mirror of
https://github.com/cypress-io/cypress.git
synced 2026-03-03 05:19:45 -06:00
fix: get correct env from npm config (#24664)
* fix: get correct env from npm config `npm config set VAR VAL` will inject `npm_config_var=val` environment variable. This commit will solve this issue Closes: #24556 * Disable commercial recommendations for system tests. * Disable commercial recommendations * Update system-tests/lib/system-tests.ts * Revert changes * Update cli/test/lib/util_spec.js * Update cli/test/lib/util_spec.js Co-authored-by: Matt Henkes <mjhenkes@gmail.com>
This commit is contained in:
@@ -533,6 +533,7 @@ const util = {
|
||||
la(is.unemptyString(varName), 'expected environment variable name, not', varName)
|
||||
|
||||
const configVarName = `npm_config_${varName}`
|
||||
const configVarNameLower = configVarName.toLowerCase()
|
||||
const packageConfigVarName = `npm_package_config_${varName}`
|
||||
|
||||
let result
|
||||
@@ -545,6 +546,10 @@ const util = {
|
||||
debug(`Using ${varName} from npm config`)
|
||||
|
||||
result = process.env[configVarName]
|
||||
} else if (process.env.hasOwnProperty(configVarNameLower)) {
|
||||
debug(`Using ${varName.toLowerCase()} from npm config`)
|
||||
|
||||
result = process.env[configVarNameLower]
|
||||
} else if (process.env.hasOwnProperty(packageConfigVarName)) {
|
||||
debug(`Using ${varName} from package.json config`)
|
||||
|
||||
|
||||
@@ -543,6 +543,11 @@ describe('util', () => {
|
||||
expect(util.getEnv('CYPRESS_FOO')).to.eql('')
|
||||
})
|
||||
|
||||
it('npm config set should work', () => {
|
||||
process.env.npm_config_cypress_foo_foo = 'bazz'
|
||||
expect(util.getEnv('CYPRESS_FOO_FOO')).to.eql('bazz')
|
||||
})
|
||||
|
||||
it('throws on non-string name', () => {
|
||||
expect(() => {
|
||||
util.getEnv()
|
||||
|
||||
Reference in New Issue
Block a user