mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-30 03:51:21 -05:00
Better handle reserved key CYPRESS_ENV being set by users to va… (#6437)
* Add warning when setting CYPRESS_ENV to non-production value * Add warning and update error when setting CYPRESS_ENV in config to non-production value * Update config test/to throw * we want warning, not throw * Rename env var to CYPRESS_INTERNAL_ENV + fix warning to actually warn when staging * update cli snapshot to include new 'info' command * yarn.lock * removed the warning from config, is overboard on our own tests 😓 * cleanup from review Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
This commit is contained in:
+3
-3
@@ -778,7 +778,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
|
||||
@@ -796,7 +796,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
|
||||
|
||||
@@ -996,7 +996,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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
----------
|
||||
|
||||
@@ -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:
|
||||
-------
|
||||
|
||||
-------
|
||||
|
||||
`
|
||||
|
||||
+21
-3
@@ -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
|
||||
|
||||
+2
-2
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
+17
-5
@@ -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
|
||||
@@ -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
|
||||
@@ -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()
|
||||
@@ -249,7 +260,8 @@ const getApplicationDataFolder = (...paths) => {
|
||||
const util = {
|
||||
normalizeModuleOptions,
|
||||
parseOpts,
|
||||
isValidCypressEnvValue,
|
||||
isValidCypressInternalEnvValue,
|
||||
isNonProductionCypressInternalEnvValue,
|
||||
printNodeOptions,
|
||||
|
||||
isCi () {
|
||||
|
||||
@@ -79,7 +79,7 @@ describe('cli', () => {
|
||||
})
|
||||
})
|
||||
|
||||
context('CYPRESS_ENV', () => {
|
||||
context('CYPRESS_INTERNAL_ENV', () => {
|
||||
/**
|
||||
* Replaces line "Platform: ..." with "Platform: xxx"
|
||||
* @param {string} s
|
||||
@@ -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)
|
||||
@@ -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'],
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if (process.env.CYPRESS_ENV !== 'production') {
|
||||
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
|
||||
require('@packages/ts/register')
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if (process.env.CYPRESS_ENV !== 'production') {
|
||||
if (process.env.CYPRESS_INTERNAL_ENV !== 'production') {
|
||||
require('@packages/ts/register')
|
||||
}
|
||||
|
||||
|
||||
@@ -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')
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ findSystemNode = require("./util/find_system_node")
|
||||
CYPRESS_ENV_PREFIX = "CYPRESS_"
|
||||
CYPRESS_ENV_PREFIX_LENGTH = "CYPRESS_".length
|
||||
CYPRESS_RESERVED_ENV_VARS = [
|
||||
"CYPRESS_ENV"
|
||||
"CYPRESS_INTERNAL_ENV"
|
||||
]
|
||||
CYPRESS_SPECIAL_ENV_VARS = [
|
||||
"CI_KEY"
|
||||
@@ -229,7 +229,7 @@ hideSpecialVals = (val, key) ->
|
||||
module.exports = {
|
||||
getConfigKeys: -> configKeys
|
||||
|
||||
isValidCypressEnvValue: (value) ->
|
||||
isValidCypressInternalEnvValue: (value) ->
|
||||
# names of config environments, see "config/app.yml"
|
||||
names = ["development", "test", "staging", "production"]
|
||||
_.includes(names, value)
|
||||
@@ -298,10 +298,10 @@ module.exports = {
|
||||
## and delete envFile
|
||||
config.env = @parseEnv(config, options.env, resolved)
|
||||
|
||||
config.cypressEnv = process.env["CYPRESS_ENV"]
|
||||
debug("using CYPRESS_ENV %s", config.cypressEnv)
|
||||
if not @isValidCypressEnvValue(config.cypressEnv)
|
||||
errors.throw("INVALID_CYPRESS_ENV", config.cypressEnv)
|
||||
config.cypressEnv = process.env["CYPRESS_INTERNAL_ENV"]
|
||||
debug("using CYPRESS_INTERNAL_ENV %s", config.cypressEnv)
|
||||
if not @isValidCypressInternalEnvValue(config.cypressEnv)
|
||||
errors.throw("INVALID_CYPRESS_INTERNAL_ENV", config.cypressEnv)
|
||||
|
||||
delete config.envFile
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@ Error.stackTraceLimit = Infinity
|
||||
pkg = require("@packages/root")
|
||||
|
||||
## instead of setting NODE_ENV we will
|
||||
## use our own separate CYPRESS_ENV so
|
||||
## use our own separate CYPRESS_INTERNAL_ENV so
|
||||
## as not to conflict with CI providers
|
||||
|
||||
## use env from package first
|
||||
## or development as default
|
||||
env = process.env["CYPRESS_ENV"] or= pkg.env ? "development"
|
||||
env = process.env["CYPRESS_INTERNAL_ENV"] or= pkg.env ? "development"
|
||||
|
||||
config = {
|
||||
## uses cancellation for automation timeouts
|
||||
|
||||
@@ -10,7 +10,7 @@ ansi_up.use_classes = true
|
||||
twoOrMoreNewLinesRe = /\n{2,}/
|
||||
|
||||
isProduction = ->
|
||||
process.env["CYPRESS_ENV"] is "production"
|
||||
process.env["CYPRESS_INTERNAL_ENV"] is "production"
|
||||
|
||||
listItems = (paths) ->
|
||||
_
|
||||
@@ -864,13 +864,15 @@ getMsgByType = (type, arg1 = {}, arg2, arg3) ->
|
||||
|
||||
Cypress will use the built-in Node version (v#{arg1}) instead.
|
||||
"""
|
||||
when "INVALID_CYPRESS_ENV"
|
||||
when "INVALID_CYPRESS_INTERNAL_ENV"
|
||||
"""
|
||||
We have detected unknown or unsupported CYPRESS_ENV value
|
||||
We have detected an unknown or unsupported "CYPRESS_INTERNAL_ENV" value
|
||||
|
||||
#{chalk.yellow(arg1)}
|
||||
|
||||
Please do not modify CYPRESS_ENV value.
|
||||
"CYPRESS_INTERNAL_ENV" is reserved and should only be used internally.
|
||||
|
||||
Do not modify the "CYPRESS_INTERNAL_ENV" value.
|
||||
"""
|
||||
when "CDP_VERSION_TOO_OLD"
|
||||
"""
|
||||
|
||||
@@ -45,7 +45,7 @@ module.exports = {
|
||||
user and user.authToken
|
||||
|
||||
create: (err) ->
|
||||
if process.env["CYPRESS_ENV"] isnt "production" or
|
||||
if process.env["CYPRESS_INTERNAL_ENV"] isnt "production" or
|
||||
process.env["CYPRESS_CRASH_REPORTS"] is "0"
|
||||
return Promise.resolve()
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ getConfig = ->
|
||||
|
||||
## we want to set node env to cypress env
|
||||
## and then restore it back to the previous
|
||||
env.NODE_ENV = env.CYPRESS_KONFIG_ENV or env.CYPRESS_ENV
|
||||
env.NODE_ENV = env.CYPRESS_KONFIG_ENV or env.CYPRESS_INTERNAL_ENV
|
||||
|
||||
## get the config values
|
||||
config = konfig().app
|
||||
|
||||
@@ -11,7 +11,7 @@ const Events = require('../gui/events')
|
||||
const Windows = require('../gui/windows')
|
||||
|
||||
const isDev = () => {
|
||||
return process.env['CYPRESS_ENV'] === 'development'
|
||||
return process.env['CYPRESS_INTERNAL_ENV'] === 'development'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -117,7 +117,7 @@ const formatPath = (name, n, colour = 'reset') => {
|
||||
|
||||
const fakeCwdPath = env.get('FAKE_CWD_PATH')
|
||||
|
||||
if (fakeCwdPath && env.get('CYPRESS_ENV') === 'test') {
|
||||
if (fakeCwdPath && env.get('CYPRESS_INTERNAL_ENV') === 'test') {
|
||||
// if we're testing within Cypress, we want to strip out
|
||||
// the current working directory before calculating the stdout tables
|
||||
// this will keep our snapshots consistent everytime we run
|
||||
|
||||
@@ -61,7 +61,7 @@ class Updater
|
||||
@request = null
|
||||
@callbacks = callbacks
|
||||
|
||||
if process.env["CYPRESS_ENV"] isnt "production"
|
||||
if process.env["CYPRESS_INTERNAL_ENV"] isnt "production"
|
||||
@patchAppPath()
|
||||
|
||||
patchAppPath: ->
|
||||
|
||||
@@ -27,7 +27,7 @@ const getSymlinkType = () => {
|
||||
}
|
||||
|
||||
const isProduction = () => {
|
||||
return process.env.CYPRESS_ENV === 'production'
|
||||
return process.env.CYPRESS_INTERNAL_ENV === 'production'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
@@ -64,11 +64,11 @@ module.exports = {
|
||||
path (...paths) {
|
||||
const { env } = process
|
||||
|
||||
la(check.unemptyString(env.CYPRESS_ENV),
|
||||
'expected CYPRESS_ENV, found', env.CYPRESS_ENV)
|
||||
la(check.unemptyString(env.CYPRESS_INTERNAL_ENV),
|
||||
'expected CYPRESS_INTERNAL_ENV, found', env.CYPRESS_INTERNAL_ENV)
|
||||
|
||||
// allow overriding the app_data folder
|
||||
const folder = env.CYPRESS_KONFIG_ENV || env.CYPRESS_ENV
|
||||
const folder = env.CYPRESS_KONFIG_ENV || env.CYPRESS_INTERNAL_ENV
|
||||
|
||||
const p = path.join(ELECTRON_APP_DATA_PATH, 'cy', folder, ...paths)
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
"repl": "node repl.js",
|
||||
"start": "node ../../scripts/cypress open --dev --global",
|
||||
"test": "node ./test/scripts/run.js",
|
||||
"test-cov": "cross-env NODE_COVERAGE=true NODE_ENV=test CYPRESS_ENV=test BLUEBIRD_DEBUG=1 xvfb-maybe istanbul cover node_modules/.bin/_mocha -- --opts ./test/support/mocha.opts",
|
||||
"test-cov-process": "cross-env NODE_COVERAGE=true NODE_ENV=test CYPRESS_ENV=test BLUEBIRD_DEBUG=1 istanbul cover --include-pid",
|
||||
"test-cov": "cross-env NODE_COVERAGE=true NODE_ENV=test CYPRESS_INTERNAL_ENV=test BLUEBIRD_DEBUG=1 xvfb-maybe istanbul cover node_modules/.bin/_mocha -- --opts ./test/support/mocha.opts",
|
||||
"test-cov-process": "cross-env NODE_COVERAGE=true NODE_ENV=test CYPRESS_INTERNAL_ENV=test BLUEBIRD_DEBUG=1 istanbul cover --include-pid",
|
||||
"test-e2e": "node ./test/scripts/run.js --glob-in-dir=test/e2e",
|
||||
"test-integration": "node ./test/scripts/run.js --glob-in-dir=test/integration",
|
||||
"test-performance": "node ./test/scripts/run.js --glob-in-dir=test/performance",
|
||||
|
||||
@@ -14,7 +14,7 @@ const performance = require('../support/helpers/performance')
|
||||
const Promise = require('bluebird')
|
||||
const sanitizeFilename = require('sanitize-filename')
|
||||
|
||||
process.env.CYPRESS_ENV = 'development'
|
||||
process.env.CYPRESS_INTERNAL_ENV = 'development'
|
||||
|
||||
const CA = require('@packages/https-proxy').CA
|
||||
const Config = require('../../lib/config')
|
||||
|
||||
@@ -120,7 +120,7 @@ commandAndArguments.args.push(
|
||||
const env = _.clone(process.env)
|
||||
|
||||
env.NODE_ENV = 'test'
|
||||
env.CYPRESS_ENV = 'test'
|
||||
env.CYPRESS_INTERNAL_ENV = 'test'
|
||||
|
||||
if (env.VERBOSE === '1') {
|
||||
_.extend(env, {
|
||||
|
||||
@@ -20,9 +20,9 @@ describe "lib/config", ->
|
||||
process.env = @env
|
||||
|
||||
context "environment name check", ->
|
||||
it "throws an error for unknown CYPRESS_ENV", ->
|
||||
sinon.stub(errors, "throw").withArgs("INVALID_CYPRESS_ENV", "foo-bar")
|
||||
process.env.CYPRESS_ENV = "foo-bar"
|
||||
it "throws an error for unknown CYPRESS_INTERNAL_ENV", ->
|
||||
sinon.stub(errors, "throw").withArgs("INVALID_CYPRESS_INTERNAL_ENV", "foo-bar")
|
||||
process.env.CYPRESS_INTERNAL_ENV = "foo-bar"
|
||||
cfg = {
|
||||
projectRoot: "/foo/bar/"
|
||||
}
|
||||
@@ -30,9 +30,9 @@ describe "lib/config", ->
|
||||
config.mergeDefaults(cfg, options)
|
||||
expect(errors.throw).have.been.calledOnce
|
||||
|
||||
it "allows known CYPRESS_ENV", ->
|
||||
it "allows production CYPRESS_INTERNAL_ENV", ->
|
||||
sinon.stub(errors, "throw")
|
||||
process.env.CYPRESS_ENV = "test"
|
||||
process.env.CYPRESS_INTERNAL_ENV = "production"
|
||||
cfg = {
|
||||
projectRoot: "/foo/bar/"
|
||||
}
|
||||
@@ -739,7 +739,7 @@ describe "lib/config", ->
|
||||
bar: "baz"
|
||||
version: "1.0.1"
|
||||
})
|
||||
expect(cfg.cypressEnv).to.eq(process.env["CYPRESS_ENV"])
|
||||
expect(cfg.cypressEnv).to.eq(process.env["CYPRESS_INTERNAL_ENV"])
|
||||
expect(cfg).not.to.have.property("envFile")
|
||||
|
||||
it "merges env into @config.env", ->
|
||||
@@ -1217,7 +1217,7 @@ describe "lib/config", ->
|
||||
|
||||
it "does not merge reserved environment variables", ->
|
||||
obj = {
|
||||
CYPRESS_ENV: "production"
|
||||
CYPRESS_INTERNAL_ENV: "production"
|
||||
CYPRESS_FOO: "bar"
|
||||
CYPRESS_CRASH_REPORTS: "0"
|
||||
CYPRESS_PROJECT_ID: "abc123"
|
||||
|
||||
@@ -7,31 +7,31 @@ mockedEnv = require('mocked-env')
|
||||
app = require("electron").app
|
||||
|
||||
setEnv = (env) =>
|
||||
process.env["CYPRESS_ENV"] = env
|
||||
process.env["CYPRESS_INTERNAL_ENV"] = env
|
||||
expectedEnv(env)
|
||||
|
||||
expectedEnv = (env) ->
|
||||
require("#{root}lib/environment")
|
||||
expect(process.env["CYPRESS_ENV"]).to.eq(env)
|
||||
expect(process.env["CYPRESS_INTERNAL_ENV"]).to.eq(env)
|
||||
|
||||
setPkg = (env) =>
|
||||
pkg.env = env
|
||||
expectedEnv(env)
|
||||
|
||||
env = process.env["CYPRESS_ENV"]
|
||||
env = process.env["CYPRESS_INTERNAL_ENV"]
|
||||
|
||||
describe "lib/environment", ->
|
||||
beforeEach ->
|
||||
sinon.stub(Promise, "config")
|
||||
delete process.env["CYPRESS_ENV"]
|
||||
delete process.env["CYPRESS_INTERNAL_ENV"]
|
||||
delete require.cache[require.resolve("#{root}lib/environment")]
|
||||
|
||||
afterEach ->
|
||||
delete require.cache[require.resolve("#{root}lib/environment")]
|
||||
delete process.env["CYPRESS_ENV"]
|
||||
delete process.env["CYPRESS_INTERNAL_ENV"]
|
||||
|
||||
after ->
|
||||
process.env["CYPRESS_ENV"] = env
|
||||
process.env["CYPRESS_INTERNAL_ENV"] = env
|
||||
|
||||
context "parses ELECTRON_EXTRA_LAUNCH_ARGS", ->
|
||||
restore = null
|
||||
@@ -51,7 +51,7 @@ describe "lib/environment", ->
|
||||
afterEach ->
|
||||
restore()
|
||||
|
||||
context "#existing process.env.CYPRESS_ENV", ->
|
||||
context "#existing process.env.CYPRESS_INTERNAL_ENV", ->
|
||||
it "is production", ->
|
||||
setEnv("production")
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ describe "lib/errors", ->
|
||||
expect(console.log).to.be.calledWithMatch("\n", "details huh")
|
||||
|
||||
it "logs err.stack in development", ->
|
||||
process.env.CYPRESS_ENV = "development"
|
||||
process.env.CYPRESS_INTERNAL_ENV = "development"
|
||||
|
||||
err = new Error("foo")
|
||||
|
||||
@@ -68,7 +68,7 @@ describe "lib/errors", ->
|
||||
context ".logException", ->
|
||||
it "calls logger.createException with unknown error", ->
|
||||
sinon.stub(logger, "createException").resolves()
|
||||
sinon.stub(process.env, "CYPRESS_ENV").value("production")
|
||||
sinon.stub(process.env, "CYPRESS_INTERNAL_ENV").value("production")
|
||||
|
||||
err = new Error("foo")
|
||||
|
||||
@@ -79,7 +79,7 @@ describe "lib/errors", ->
|
||||
|
||||
it "does not call logger.createException when known error", ->
|
||||
sinon.stub(logger, "createException").resolves()
|
||||
sinon.stub(process.env, "CYPRESS_ENV").value("production")
|
||||
sinon.stub(process.env, "CYPRESS_INTERNAL_ENV").value("production")
|
||||
|
||||
err = errors.get("NOT_LOGGED_IN")
|
||||
|
||||
@@ -90,7 +90,7 @@ describe "lib/errors", ->
|
||||
|
||||
it "does not call logger.createException when not in production env", ->
|
||||
sinon.stub(logger, "createException").resolves()
|
||||
sinon.stub(process.env, "CYPRESS_ENV").value("development")
|
||||
sinon.stub(process.env, "CYPRESS_INTERNAL_ENV").value("development")
|
||||
|
||||
err = new Error("foo")
|
||||
|
||||
@@ -101,7 +101,7 @@ describe "lib/errors", ->
|
||||
|
||||
it "swallows creating exception errors", ->
|
||||
sinon.stub(logger, "createException").rejects(new Error("foo"))
|
||||
sinon.stub(process.env, "CYPRESS_ENV").value("production")
|
||||
sinon.stub(process.env, "CYPRESS_INTERNAL_ENV").value("production")
|
||||
|
||||
err = errors.get("NOT_LOGGED_IN")
|
||||
|
||||
|
||||
@@ -122,11 +122,11 @@ describe "lib/exceptions", ->
|
||||
|
||||
context ".create", ->
|
||||
beforeEach ->
|
||||
@env = process.env["CYPRESS_ENV"]
|
||||
@env = process.env["CYPRESS_INTERNAL_ENV"]
|
||||
sinon.stub(api, "createCrashReport")
|
||||
|
||||
afterEach ->
|
||||
process.env["CYPRESS_ENV"] = @env
|
||||
process.env["CYPRESS_INTERNAL_ENV"] = @env
|
||||
|
||||
describe "with CYPRESS_CRASH_REPORTS=0", ->
|
||||
beforeEach ->
|
||||
@@ -142,7 +142,7 @@ describe "lib/exceptions", ->
|
||||
|
||||
describe "development", ->
|
||||
beforeEach ->
|
||||
process.env["CYPRESS_ENV"] = "development"
|
||||
process.env["CYPRESS_INTERNAL_ENV"] = "development"
|
||||
|
||||
it "immediately resolves", ->
|
||||
exception.create()
|
||||
@@ -151,7 +151,7 @@ describe "lib/exceptions", ->
|
||||
|
||||
describe "production", ->
|
||||
beforeEach ->
|
||||
process.env["CYPRESS_ENV"] = "production"
|
||||
process.env["CYPRESS_INTERNAL_ENV"] = "production"
|
||||
|
||||
@err = {name: "ReferenceError", message: "undefined is not a function", stack: "asfd"}
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ require("../spec_helper")
|
||||
|
||||
describe "lib/konfig", ->
|
||||
beforeEach ->
|
||||
@env = process.env["CYPRESS_ENV"]
|
||||
@env = process.env["CYPRESS_INTERNAL_ENV"]
|
||||
|
||||
@setup = (env) =>
|
||||
process.env["CYPRESS_ENV"] = env
|
||||
process.env["CYPRESS_INTERNAL_ENV"] = env
|
||||
|
||||
@konfig = require("#{root}lib/konfig")
|
||||
|
||||
@@ -13,7 +13,7 @@ describe "lib/konfig", ->
|
||||
expect(@konfig(key)).to.eq(val)
|
||||
|
||||
afterEach ->
|
||||
process.env["CYPRESS_ENV"] = @env
|
||||
process.env["CYPRESS_INTERNAL_ENV"] = @env
|
||||
|
||||
delete require.cache[require.resolve("#{root}lib/konfig")]
|
||||
|
||||
|
||||
@@ -84,21 +84,21 @@ describe('gui/interactive', () => {
|
||||
})
|
||||
|
||||
it('calls menu.set withDevTools: true when in dev env', () => {
|
||||
const env = process.env['CYPRESS_ENV']
|
||||
const env = process.env['CYPRESS_INTERNAL_ENV']
|
||||
|
||||
process.env['CYPRESS_ENV'] = 'development'
|
||||
process.env['CYPRESS_INTERNAL_ENV'] = 'development'
|
||||
interactiveMode.getWindowArgs({}).onFocus()
|
||||
expect(menu.set.lastCall.args[0].withDevTools).to.be.true
|
||||
process.env['CYPRESS_ENV'] = env
|
||||
process.env['CYPRESS_INTERNAL_ENV'] = env
|
||||
})
|
||||
|
||||
it('calls menu.set withDevTools: false when not in dev env', () => {
|
||||
const env = process.env['CYPRESS_ENV']
|
||||
const env = process.env['CYPRESS_INTERNAL_ENV']
|
||||
|
||||
process.env['CYPRESS_ENV'] = 'production'
|
||||
process.env['CYPRESS_INTERNAL_ENV'] = 'production'
|
||||
interactiveMode.getWindowArgs({}).onFocus()
|
||||
expect(menu.set.lastCall.args[0].withDevTools).to.be.false
|
||||
process.env['CYPRESS_ENV'] = env
|
||||
process.env['CYPRESS_INTERNAL_ENV'] = env
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -137,24 +137,24 @@ describe('gui/interactive', () => {
|
||||
})
|
||||
|
||||
it('calls menu.set withDevTools: true when in dev env', () => {
|
||||
const env = process.env['CYPRESS_ENV']
|
||||
const env = process.env['CYPRESS_INTERNAL_ENV']
|
||||
|
||||
process.env['CYPRESS_ENV'] = 'development'
|
||||
process.env['CYPRESS_INTERNAL_ENV'] = 'development'
|
||||
|
||||
return interactiveMode.ready({}).then(() => {
|
||||
expect(menu.set.lastCall.args[0].withDevTools).to.be.true
|
||||
process.env['CYPRESS_ENV'] = env
|
||||
process.env['CYPRESS_INTERNAL_ENV'] = env
|
||||
})
|
||||
})
|
||||
|
||||
it('calls menu.set withDevTools: false when not in dev env', () => {
|
||||
const env = process.env['CYPRESS_ENV']
|
||||
const env = process.env['CYPRESS_INTERNAL_ENV']
|
||||
|
||||
process.env['CYPRESS_ENV'] = 'production'
|
||||
process.env['CYPRESS_INTERNAL_ENV'] = 'production'
|
||||
|
||||
return interactiveMode.ready({}).then(() => {
|
||||
expect(menu.set.lastCall.args[0].withDevTools).to.be.false
|
||||
process.env['CYPRESS_ENV'] = env
|
||||
process.env['CYPRESS_INTERNAL_ENV'] = env
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -28,5 +28,5 @@ try {
|
||||
// like @packages/coffee/register.js does?
|
||||
} catch (e) {
|
||||
// continue running without TypeScript require hook
|
||||
log('Running without ts-node hook in environment "%s"', process.env.CYPRESS_ENV)
|
||||
log('Running without ts-node hook in environment "%s"', process.env.CYPRESS_INTERNAL_ENV)
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ buildCypressApp = (platform, version, options = {}) ->
|
||||
})
|
||||
.then =>
|
||||
str = """
|
||||
process.env.CYPRESS_ENV = process.env.CYPRESS_ENV || 'production'
|
||||
process.env.CYPRESS_INTERNAL_ENV = process.env.CYPRESS_INTERNAL_ENV || 'production'
|
||||
require('./packages/server')
|
||||
"""
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ runProjectTest = (buildAppExecutable, e2e) ->
|
||||
console.log("running project test")
|
||||
|
||||
new Promise (resolve, reject) ->
|
||||
env = _.omit(process.env, "CYPRESS_ENV")
|
||||
env = _.omit(process.env, "CYPRESS_INTERNAL_ENV")
|
||||
|
||||
if !canRecordVideo()
|
||||
console.log("cannot record video on this platform yet, disabling")
|
||||
@@ -92,7 +92,7 @@ runFailingProjectTest = (buildAppExecutable, e2e) ->
|
||||
|
||||
spawn = ->
|
||||
new Promise (resolve, reject) ->
|
||||
env = _.omit(process.env, "CYPRESS_ENV")
|
||||
env = _.omit(process.env, "CYPRESS_INTERNAL_ENV")
|
||||
|
||||
args = [
|
||||
"--run-project=#{e2e}",
|
||||
|
||||
Reference in New Issue
Block a user