Skip to content

Commit

Permalink
fix: get correct env from npm config (#24664)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
abcfy2 and mjhenkes authored Dec 1, 2022
1 parent c2c21c2 commit 05dc4a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cli/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`)

Expand Down
5 changes: 5 additions & 0 deletions cli/test/lib/util_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

5 comments on commit 05dc4a5

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 05dc4a5 Dec 1, 2022

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 arm64 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/11.3.0/linux-arm64/develop-05dc4a5ecdffbb30b49e100857c4bffe36f86d16/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 05dc4a5 Dec 1, 2022

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/11.3.0/linux-x64/develop-05dc4a5ecdffbb30b49e100857c4bffe36f86d16/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 05dc4a5 Dec 1, 2022

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/11.3.0/darwin-x64/develop-05dc4a5ecdffbb30b49e100857c4bffe36f86d16/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 05dc4a5 Dec 1, 2022

Choose a reason for hiding this comment

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

Circle 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/11.3.0/win32-x64/develop-05dc4a5ecdffbb30b49e100857c4bffe36f86d16/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 05dc4a5 Dec 1, 2022

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 arm64 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/11.3.0/darwin-arm64/develop-05dc4a5ecdffbb30b49e100857c4bffe36f86d16/cypress.tgz

Please sign in to comment.