Skip to content

Commit

Permalink
Merge branch 'develop' into issue-5772
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Mar 9, 2020
2 parents 2da2ecc + 190d12e commit 0ce8eb2
Show file tree
Hide file tree
Showing 54 changed files with 653 additions and 393 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ install:
- has-env GH
# clean cache to prevent install permission issues
- yarn cache clean
- yarn || yarn || yarn
- yarn --frozen-lockfile || yarn --frozen-lockfile || yarn --frozen-lockfile
- .\node_modules\.bin\print-arch

# Post-install test scripts.
Expand Down
8 changes: 4 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ jobs:
- run: ls $(yarn global bin)/../lib/node_modules

# try several times, because flaky NPM installs ...
- run: yarn || yarn
- run: yarn --frozen-lockfile || yarn --frozen-lockfile
- run:
name: Top level packages
command: yarn list --depth=0 || true
Expand Down Expand Up @@ -777,7 +777,7 @@ jobs:
command: |
CYPRESS_PROJECT_ID=$TEST_KITCHENSINK_PROJECT_ID \
CYPRESS_RECORD_KEY=$TEST_KITCHENSINK_RECORD_KEY \
CYPRESS_ENV=staging \
CYPRESS_INTERNAL_ENV=staging \
CYPRESS_video=false \
yarn cypress:run --project /tmp/repo --record
- store-npm-logs
Expand All @@ -795,7 +795,7 @@ jobs:
command: |
CYPRESS_PROJECT_ID=$TEST_TINY_PROJECT_ID \
CYPRESS_RECORD_KEY=$TEST_TINY_RECORD_KEY \
CYPRESS_ENV=staging \
CYPRESS_INTERNAL_ENV=staging \
yarn cypress:run --project /tmp/repo --record
- store-npm-logs

Expand Down Expand Up @@ -995,7 +995,7 @@ jobs:
command: |
CYPRESS_PROJECT_ID=$TEST_TINY_PROJECT_ID \
CYPRESS_RECORD_KEY=$TEST_TINY_RECORD_KEY \
CYPRESS_ENV=staging \
CYPRESS_INTERNAL_ENV=staging \
$(yarn bin)/cypress run --record
- store-npm-logs

Expand Down
52 changes: 39 additions & 13 deletions cli/__snapshots__/cli_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,26 +323,17 @@ exports['cli unknown command shows usage and exits 1'] = `
`

exports['cli CYPRESS_ENV allows staging environment 1'] = `
code: 0
stderr:
-------
-------
`

exports['cli CYPRESS_ENV catches environment "foo" 1'] = `
exports['cli CYPRESS_INTERNAL_ENV catches environment "foo" 1'] = `
code: 11
stderr:
-------
The environment variable with the reserved name "CYPRESS_ENV" is set.
The environment variable with the reserved name "CYPRESS_INTERNAL_ENV" is set.
Unset the "CYPRESS_ENV" environment variable and run Cypress again.
Unset the "CYPRESS_INTERNAL_ENV" environment variable and run Cypress again.
----------
CYPRESS_ENV=foo
CYPRESS_INTERNAL_ENV=foo
----------
Expand Down Expand Up @@ -402,3 +393,38 @@ This will work, but it's not recommended.
If you are trying to pass multiple arguments, separate them with commas instead:
cypress run --tag arg1,arg2,arg3
`

exports['cli CYPRESS_INTERNAL_ENV allows and warns when staging environment 1'] = `
code: 0
stdout:
-------
⚠ Warning: It looks like you're passing CYPRESS_INTERNAL_ENV=staging
The environment variable "CYPRESS_INTERNAL_ENV" is reserved and should only be used internally.
Unset the "CYPRESS_INTERNAL_ENV" environment variable and run Cypress again.
Usage: cypress <command> [options]
Options:
-v, --version prints Cypress version
-h, --help output usage information
Commands:
help Shows CLI help and exits
version prints Cypress version
run [options] Runs Cypress tests from the CLI without the GUI
open [options] Opens Cypress in the interactive GUI.
install [options] Installs the Cypress executable matching this package's
version
verify [options] Verifies that Cypress is installed correctly and
executable
cache [options] Manages the Cypress binary cache
info [options] Prints Cypress and system information
-------
stderr:
-------
-------
`
24 changes: 21 additions & 3 deletions cli/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,32 @@ module.exports = {
args = process.argv
}

if (!util.isValidCypressEnvValue(process.env.CYPRESS_ENV)) {
debug('invalid CYPRESS_ENV value', process.env.CYPRESS_ENV)
const { CYPRESS_INTERNAL_ENV } = process.env

if (!util.isValidCypressInternalEnvValue(CYPRESS_INTERNAL_ENV)) {
debug('invalid CYPRESS_INTERNAL_ENV value', CYPRESS_INTERNAL_ENV)

return errors.exitWithError(errors.errors.invalidCypressEnv)(
`CYPRESS_ENV=${process.env.CYPRESS_ENV}`,
`CYPRESS_INTERNAL_ENV=${CYPRESS_INTERNAL_ENV}`,
)
}

if (util.isNonProductionCypressInternalEnvValue(CYPRESS_INTERNAL_ENV)) {
debug('non-production CYPRESS_INTERNAL_ENV value', CYPRESS_INTERNAL_ENV)

let msg = `
${logSymbols.warning} Warning: It looks like you're passing CYPRESS_INTERNAL_ENV=${CYPRESS_INTERNAL_ENV}
The environment variable "CYPRESS_INTERNAL_ENV" is reserved and should only be used internally.
Unset the "CYPRESS_INTERNAL_ENV" environment variable and run Cypress again.
`

logger.log()
logger.warn(stripIndent(msg))
logger.log()
}

const program = new commander.Command()

// bug in commander not printing name
Expand Down
4 changes: 2 additions & 2 deletions cli/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ const unexpected = {

const invalidCypressEnv = {
description:
chalk.red('The environment variable with the reserved name "CYPRESS_ENV" is set.'),
solution: chalk.red('Unset the "CYPRESS_ENV" environment variable and run Cypress again.'),
chalk.red('The environment variable with the reserved name "CYPRESS_INTERNAL_ENV" is set.'),
solution: chalk.red('Unset the "CYPRESS_INTERNAL_ENV" environment variable and run Cypress again.'),
exitCode: 11,
}

Expand Down
22 changes: 17 additions & 5 deletions cli/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ function stdoutLineMatches (expectedLine, stdout) {
}

/**
* Confirms if given value is a valid CYPRESS_ENV value. Undefined values
* Confirms if given value is a valid CYPRESS_INTERNAL_ENV value. Undefined values
* are valid, because the system can set the default one.
*
* @param {string} value
* @example util.isValidCypressEnvValue(process.env.CYPRESS_ENV)
* @example util.isValidCypressInternalEnvValue(process.env.CYPRESS_INTERNAL_ENV)
*/
function isValidCypressEnvValue (value) {
function isValidCypressInternalEnvValue (value) {
if (_.isUndefined(value)) {
// will get default value
return true
Expand All @@ -139,6 +139,17 @@ function isValidCypressEnvValue (value) {
return _.includes(names, value)
}

/**
* Confirms if given value is a non-production CYPRESS_INTERNAL_ENV value.
* Undefined values are valid, because the system can set the default one.
*
* @param {string} value
* @example util.isNonProductionCypressInternalEnvValue(process.env.CYPRESS_INTERNAL_ENV)
*/
function isNonProductionCypressInternalEnvValue (value) {
return !_.isUndefined(value) && value !== 'production'
}

/**
* Prints NODE_OPTIONS using debug() module, but only
* if DEBUG=cypress... is set
Expand Down Expand Up @@ -234,7 +245,7 @@ const getApplicationDataFolder = (...paths) => {
const { env } = process

// allow overriding the app_data folder
const folder = env.CYPRESS_KONFIG_ENV || env.CYPRESS_ENV || 'development'
const folder = env.CYPRESS_KONFIG_ENV || env.CYPRESS_INTERNAL_ENV || 'development'

const PRODUCT_NAME = pkg.productName || pkg.name
const OS_DATA_PATH = ospath.data()
Expand All @@ -249,7 +260,8 @@ const getApplicationDataFolder = (...paths) => {
const util = {
normalizeModuleOptions,
parseOpts,
isValidCypressEnvValue,
isValidCypressInternalEnvValue,
isNonProductionCypressInternalEnvValue,
printNodeOptions,

isCi () {
Expand Down
11 changes: 5 additions & 6 deletions cli/test/lib/cli_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('cli', () => {
})
})

context('CYPRESS_ENV', () => {
context('CYPRESS_INTERNAL_ENV', () => {
/**
* Replaces line "Platform: ..." with "Platform: xxx"
* @param {string} s
Expand All @@ -104,13 +104,12 @@ describe('cli', () => {
.join(os.eol)
}

it('allows staging environment', () => {
it('allows and warns when staging environment', () => {
const options = {
env: {
CYPRESS_ENV: 'staging',
CYPRESS_INTERNAL_ENV: 'staging',
},
// we are only interested in the exit code
filter: ['code', 'stderr'],
filter: ['code', 'stderr', 'stdout'],
}

return execa('bin/cypress', ['help'], options).then(snapshot)
Expand All @@ -119,7 +118,7 @@ describe('cli', () => {
it('catches environment "foo"', () => {
const options = {
env: {
CYPRESS_ENV: 'foo',
CYPRESS_INTERNAL_ENV: 'foo',
},
// we are only interested in the exit code
filter: ['code', 'stderr'],
Expand Down
12 changes: 6 additions & 6 deletions cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,13 +663,13 @@ declare namespace Cypress {
/**
* Click a DOM element at specific corner / side.
*
* @param {String} position - The position where the click should be issued.
* @param {PositionType} position - The position where the click should be issued.
* The `center` position is the default position.
* @see https://on.cypress.io/click
* @example
* cy.get('button').click('topRight')
*/
click(position: string, options?: Partial<ClickOptions>): Chainable<Subject>
click(position: PositionType, options?: Partial<ClickOptions>): Chainable<Subject>
/**
* Click a DOM element at specific coordinates
*
Expand Down Expand Up @@ -800,13 +800,13 @@ declare namespace Cypress {
/**
* Double-click a DOM element at specific corner / side.
*
* @param {String} position - The position where the click should be issued.
* @param {PositionType} position - The position where the click should be issued.
* The `center` position is the default position.
* @see https://on.cypress.io/dblclick
* @example
* cy.get('button').dblclick('topRight')
*/
dblclick(position: string, options?: Partial<ClickOptions>): Chainable<Subject>
dblclick(position: PositionType, options?: Partial<ClickOptions>): Chainable<Subject>
/**
* Double-click a DOM element at specific coordinates
*
Expand All @@ -830,13 +830,13 @@ declare namespace Cypress {
/**
* Right-click a DOM element at specific corner / side.
*
* @param {String} position - The position where the click should be issued.
* @param {PositionType} position - The position where the click should be issued.
* The `center` position is the default position.
* @see https://on.cypress.io/click
* @example
* cy.get('button').rightclick('topRight')
*/
rightclick(position: string, options?: Partial<ClickOptions>): Chainable<Subject>
rightclick(position: PositionType, options?: Partial<ClickOptions>): Chainable<Subject>
/**
* Right-click a DOM element at specific coordinates
*
Expand Down
2 changes: 1 addition & 1 deletion packages/coffee/register.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (process.env.CYPRESS_ENV !== 'production') {
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
require('coffeescript/register')

// using hack found here to prevent problems with
Expand Down
4 changes: 4 additions & 0 deletions packages/desktop-gui/src/styles/components/_alerts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@

.alert-content {
text-align: left;

p {
line-height: 1.5;
}
}

code, pre {
Expand Down
2 changes: 1 addition & 1 deletion packages/launcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// compile TypeScript files on the fly using
// Node require hook project
if (process.env.CYPRESS_ENV !== 'production') {
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
require('@packages/ts/register')
}

Expand Down
2 changes: 1 addition & 1 deletion packages/network/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (process.env.CYPRESS_ENV !== 'production') {
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
require('@packages/ts/register')
}

Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (process.env.CYPRESS_ENV !== 'production') {
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
require('@packages/ts/register')
}

Expand Down
18 changes: 18 additions & 0 deletions packages/server/__snapshots__/3_plugins_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,21 @@ The following error was thrown by a plugin. We stopped running your tests becaus
`

exports['e2e plugins projectRoot and configFile passes projectRoot and default configFile to plugins function 1'] = `
The following validation error was thrown by your plugins file (\`/foo/bar/.projects/plugin-validation-error/cypress/plugins/index.js\`).
Error: You must pass a valid event name when registering a plugin.
You passed: \`invalid:event\`
The following are valid events:
- file:preprocessor
- before:browser:launch
- task
- after:screenshot
[stack trace lines]
`
4 changes: 2 additions & 2 deletions packages/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (process.env.CY_NET_PROFILE && isRunningElectron) {
process.env.UV_THREADPOOL_SIZE = 128

require('graceful-fs').gracefulify(require('fs'))
// if running in production mode (CYPRESS_ENV)
// if running in production mode (CYPRESS_INTERNAL_ENV)
// all transpile should have been done already
// and these calls should do nothing
require('@packages/ts/register')
Expand All @@ -30,7 +30,7 @@ require && require.extensions && delete require.extensions['.coffee.md']

// warn when deprecated callback apis are used in electron
// https://github.com/electron/electron/blob/master/docs/api/process.md#processenablepromiseapis
process.enablePromiseAPIs = process.env.CYPRESS_ENV !== 'production'
process.enablePromiseAPIs = process.env.CYPRESS_INTERNAL_ENV !== 'production'

require('./lib/util/suppress_unauthorized_warning').suppress()

Expand Down
Loading

0 comments on commit 0ce8eb2

Please sign in to comment.