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 committed Nov 22, 2021
1 parent f251681 commit de4fca3
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
Expand Up @@ -210,7 +210,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 plugins file. The following tasks are registered: return:arg, arg:is:undefined, wait, create:long:file\n\nFix this in your plugins file here:\n${Cypress.config('pluginsFile')}`)
expect(err.message).to.eq(`\`cy.task('bar')\` failed with the following error:\n\nThe task 'bar' was not handled in the plugins file. The following tasks are registered: return:arg, cypress:env, arg:is:undefined, wait, create:long:file\n\nFix this in your plugins file here:\n${Cypress.config('pluginsFile')}`)

done()
})
Expand Down
5 changes: 5 additions & 0 deletions packages/driver/cypress/integration/issues/18805_spec.js
@@ -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
Expand Up @@ -38,6 +38,9 @@ module.exports = (on) => {
'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
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
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')
})
})
})

3 comments on commit de4fca3

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on de4fca3 Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.1.0/circle-develop-de4fca351b507070723d1e470af518ad1c3b0c8c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on de4fca3 Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.1.0/appveyor-develop-de4fca351b507070723d1e470af518ad1c3b0c8c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on de4fca3 Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.1.0/circle-develop-de4fca351b507070723d1e470af518ad1c3b0c8c/cypress.tgz

Please sign in to comment.