Skip to content

Commit

Permalink
clone settings so they can't be mutated, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding committed Mar 15, 2021
1 parent fe1046e commit 4886f23
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/server/lib/config.js
Expand Up @@ -209,8 +209,8 @@ module.exports = {
return this.set({
projectName: this.getNameFromRoot(projectRoot),
projectRoot,
config: settings,
envFile,
config: _.cloneDeep(settings),
envFile: _.cloneDeep(envFile),
options,
})
})
Expand Down
3 changes: 0 additions & 3 deletions packages/server/test/e2e/7_record_spec.js
Expand Up @@ -16,9 +16,6 @@ const {
postInstanceTestsResponse,
} = require('../support/helpers/serverStub')
const { expectRunsToHaveCorrectTimings } = require('../support/helpers/resultsUtils')
const postRunResponseWithWarnings = jsonSchemas.getExample('postRunResponse')('2.2.0')
const postRunResponse = _.assign({}, postRunResponseWithWarnings, { warnings: [] })
const postRunInstanceResponse = jsonSchemas.getExample('postRunInstanceResponse')('2.1.0')

const e2ePath = Fixtures.projectPath('e2e')
const outputPath = path.join(e2ePath, 'output.json')
Expand Down
16 changes: 14 additions & 2 deletions packages/server/test/unit/config_spec.js
Expand Up @@ -56,8 +56,7 @@ describe('lib/config', () => {

this.setup = (cypressJson = {}, cypressEnvJson = {}) => {
sinon.stub(settings, 'read').withArgs(this.projectRoot).resolves(cypressJson)

return sinon.stub(settings, 'readEnv').withArgs(this.projectRoot).resolves(cypressEnvJson)
sinon.stub(settings, 'readEnv').withArgs(this.projectRoot).resolves(cypressEnvJson)
}
})

Expand All @@ -81,6 +80,19 @@ describe('lib/config', () => {
})
})

it('clones settings and env settings, so they are not mutated', function () {
const settings = { foo: 'bar' }
const envSettings = { baz: 'qux' }

this.setup(settings, envSettings)

return config.get(this.projectRoot)
.then(() => {
expect(settings).to.deep.equal({ foo: 'bar' })
expect(envSettings).to.deep.equal({ baz: 'qux' })
})
})

context('port', () => {
beforeEach(function () {
return this.setup({}, { foo: 'bar' })
Expand Down

0 comments on commit 4886f23

Please sign in to comment.