Files
cypress/cli/test/lib/tasks/cache_spec.js
Ben Kucera ef8b240bc0 improve cache help messages snapshot more (#2625)
* snapshot more, remove execa in tests for speed

* sub-command -> command, add snapshot

* restate execa
2019-01-25 00:34:58 -05:00

58 lines
1.4 KiB
JavaScript

require('../../spec_helper')
const mockfs = require('mock-fs')
const fs = require(`${lib}/fs`)
const state = require(`${lib}/tasks/state`)
const cache = require(`${lib}/tasks/cache`)
const stdout = require('../../support/stdout')
const snapshot = require('snap-shot-it')
describe('lib/tasks/cache', () => {
beforeEach(() => {
mockfs({
'/.cache/Cypress': {
'1.2.3': {
'Cypress': {},
},
'2.3.4': {
'Cypress.app': {},
},
},
})
sinon.stub(state, 'getCacheDir').returns('/.cache/Cypress')
this.stdout = stdout.capture()
})
afterEach(() => {
mockfs.restore()
this.stdout = this.stdout.toString().split('\n').slice(0, -2).join('\n')
snapshot(this.stdout.toString() || '[no output]')
stdout.restore()
})
describe('.path', () => {
it('lists path to cache', () => {
cache.path()
expect(this.stdout.toString()).to.eql('/.cache/Cypress\n')
})
})
describe('.clear', () => {
it('deletes cache folder and everything inside it', () => {
return cache.clear()
.then(() =>
fs.pathExistsAsync('/.cache/Cypress')
.then((exists) => expect(exists).to.eql(false))
)
})
})
describe('.list', () => {
it('lists all versions of cached binary', () => {
return cache.list()
.then(() => {
expect(this.stdout.toString()).to.eql('1.2.3, 2.3.4\n')
})
})
})
})