mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-04 22:10:40 -05:00
639df99036
* Rename non-user facing instances of whitelist * Rename server option 'whitelist' to 'ignore' * Update use of whitelist with server to throw instead of warn * Rename Cypress.Cookies.defaults 'whitelist' option to 'preserve' * fix circle yml parameter parsing consistent * compose cloning an external repo and switching to the NEXT_DEV_VERSION branch consistently * add cypress org to repo parameter * cd into the right dir before switching branches * one line git checkout * simplify passing repo * cd into the right dir * clone into the right dir * oh my cd 101 * replace kitchen sink strings for 5.0.0 Co-authored-by: Brian Mann <brian.mann86@gmail.com>
89 lines
2.6 KiB
JavaScript
89 lines
2.6 KiB
JavaScript
require('../spec_helper')
|
|
|
|
const path = require('path')
|
|
const Promise = require('bluebird')
|
|
const fs = require(`${root}lib/util/fs`)
|
|
const FileUtil = require(`${root}lib/util/file`)
|
|
const appData = require(`${root}lib/util/app_data`)
|
|
|
|
const savedState = require(`${root}lib/saved_state`)
|
|
|
|
describe('lib/saved_state', () => {
|
|
context('#create', () => {
|
|
beforeEach(() => {
|
|
return savedState.create().then((state) => {
|
|
return fs.unlinkAsync(state.path)
|
|
}).catch(() => {}) // ignore error if file didn't exist in the first place
|
|
})
|
|
|
|
it('resolves with an instance of FileUtil', () => {
|
|
return savedState.create()
|
|
.then((state) => {
|
|
expect(state).to.be.instanceof(FileUtil)
|
|
})
|
|
})
|
|
|
|
it('resolves with a noop instance if isTextTerminal', () => {
|
|
return savedState.create('/foo/bar', true)
|
|
.then((state) => {
|
|
expect(state).to.equal(FileUtil.noopFile)
|
|
})
|
|
})
|
|
|
|
it('caches state file instance per path', () => {
|
|
return Promise.all([
|
|
savedState.create('/foo/bar'),
|
|
savedState.create('/foo/bar'),
|
|
]).spread((a, b) => {
|
|
expect(a).to.equal(b)
|
|
})
|
|
})
|
|
|
|
it('returns different state file for different path', () => {
|
|
const a = savedState.create('/foo/bar')
|
|
const b = savedState.create('/foo/baz')
|
|
|
|
expect(a).to.not.equal(b)
|
|
})
|
|
|
|
it('sets path to project name + hash if projectRoot', () => {
|
|
return savedState.create('/foo/the-project-name')
|
|
.then((state) => {
|
|
expect(state.path).to.include('the-project-name')
|
|
})
|
|
})
|
|
|
|
it('sets path __global__ if no projectRoot', () => {
|
|
return savedState.create()
|
|
.then((state) => {
|
|
const expected = path.join(appData.path(), 'projects', '__global__', 'state.json')
|
|
|
|
expect(state.path).to.equal(expected)
|
|
})
|
|
})
|
|
|
|
it('only saves allowed keys', () => {
|
|
return savedState.create()
|
|
.then((state) => {
|
|
return state.set({ foo: 'bar', appWidth: 20 })
|
|
.then(() => {
|
|
return state.get()
|
|
})
|
|
}).then((stateObject) => {
|
|
expect(stateObject).to.eql({ appWidth: 20 })
|
|
})
|
|
})
|
|
|
|
it('logs error when attempting to set invalid key(s)', () => {
|
|
sinon.spy(console, 'error')
|
|
|
|
return savedState.create()
|
|
.then((state) => {
|
|
return state.set({ foo: 'bar', baz: 'qux' })
|
|
}).then(() => {
|
|
expect(console.error).to.be.calledWith('WARNING: attempted to save state for non-allowed key(s): foo, baz. All keys must be allowed in server/lib/saved_state.js')
|
|
})
|
|
})
|
|
})
|
|
})
|