Skip to content

Commit

Permalink
feat: Set CYPRESS=true as env var in child processes where Cypress ru…
Browse files Browse the repository at this point in the history
…ns user code in Node (#18981)
  • Loading branch information
davidmunechika authored and lmiller1990 committed Nov 29, 2021
1 parent b637334 commit e2e7618
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/driver/cypress/integration/commands/task_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe('src/cy/commands/task', () => {
expect(lastLog.get('error')).to.eq(err)
expect(lastLog.get('state')).to.eq('failed')

expect(err.message).to.eq(`\`cy.task('bar')\` failed with the following error:\n\nThe task 'bar' was not handled in the setupNodeEvents method. The following tasks are registered: return:arg, arg:is:undefined, wait, create:long:file\n\nFix this in your setupNodeEvents method here:\n${path.join(Cypress.config('projectRoot'), Cypress.config('configFile'))}`)
expect(err.message).to.eq(`\`cy.task('bar')\` failed with the following error:\n\nThe task 'bar' was not handled in the setupNodeEvents method. The following tasks are registered: return:arg, cypress:env, arg:is:undefined, wait, create:long:file\n\nFix this in your setupNodeEvents method here:\n${path.join(Cypress.config('projectRoot'), Cypress.config('configFile'))}`)

done()
})
Expand Down
5 changes: 5 additions & 0 deletions packages/driver/cypress/integration/issues/18805_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('CYPRESS env var', () => {
it('checks that the CYPRESS env var exists in the plugin file', () => {
cy.task('cypress:env').should('eq', 'true')
})
})
3 changes: 3 additions & 0 deletions packages/driver/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ module.exports = (on, config) => {
'return:arg' (arg) {
return arg
},
'cypress:env' () {
return process.env['CYPRESS']
},
'arg:is:undefined' (arg) {
if (arg === undefined) {
return 'arg was undefined'
Expand Down
2 changes: 2 additions & 0 deletions packages/server/lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const pkg = require('@packages/root')
// or development as default
const env = process.env['CYPRESS_INTERNAL_ENV'] || (process.env['CYPRESS_INTERNAL_ENV'] = pkg.env != null ? pkg.env : 'development')

process.env['CYPRESS'] = 'true'

const config = {
// uses cancellation for automation timeouts
cancellation: true,
Expand Down
6 changes: 6 additions & 0 deletions packages/server/test/unit/environment_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,10 @@ describe('lib/environment', () => {
return expectedEnv('development')
})
})

context('it sets process.env.CYPRESS', () => {
it('sets CYPRESS=true when Cypress runs', () => {
expect(process.env['CYPRESS']).to.eq('true')
})
})
})

0 comments on commit e2e7618

Please sign in to comment.