Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: spawn child process with process.env in macOS arm64 #25753

Merged
merged 10 commits into from
Feb 13, 2023
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ _Released 02/14/2023 (PENDING)_
- Fixed an issue with the Cloud project selection modal not showing the correct prompts. Fixes [#25520](https://github.com/cypress-io/cypress/issues/25520).
- Fixed an issue in middleware where error-handling code could itself generate an error and fail to report the original issue. Fixes [#22825](https://github.com/cypress-io/cypress/issues/22825).
- Fixed an issue that could cause the Debug page to display a different number of specs for in-progress runs than shown in Cypress Cloud. Fixes [#25647](https://github.com/cypress-io/cypress/issues/25647).
- Fixed an issue introduced in Cypress 12.3.0 where custom browsers that relied on process environment variables were not found on macOS arm64 architectures. Fixed in [#25753](https://github.com/cypress-io/cypress/pull/25753).

**Misc:**

Expand Down
2 changes: 1 addition & 1 deletion packages/launcher/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const utils = {
let stdout = ''
let stderr = ''

const proc = utils.spawnWithArch(cmd, args, { stdio: ['ignore', 'pipe', 'pipe'] })
const proc = utils.spawnWithArch(cmd, args, { stdio: ['ignore', 'pipe', 'pipe'], env: process.env })

const finish = () => {
proc.kill()
Expand Down
16 changes: 13 additions & 3 deletions packages/launcher/test/unit/darwin_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('darwin browser detection', () => {

context('forces correct architecture', () => {
function stubForArch (arch: 'arm64' | 'x64') {
sinon.stub(process, 'env').value({ env2: 'false', env3: 'true' })
sinon.stub(os, 'arch').returns(arch)
sinon.stub(os, 'platform').returns('darwin')
getOutput.restore()
Expand All @@ -111,6 +112,8 @@ describe('darwin browser detection', () => {
expect(args[1]).to.deep.eq([knownBrowsers[0].binary, '--version'])
expect(args[2].env).to.deep.include({
ARCHPREFERENCE: 'arm64,x86_64',
env2: 'false',
env3: 'true',
})
})

Expand All @@ -125,15 +128,18 @@ describe('darwin browser detection', () => {

expect(args[0]).to.eq(knownBrowsers[0].binary)
expect(args[1]).to.deep.eq(['--version'])
expect(args[2].env).to.not.exist
expect(args[2].env).to.deep.include({
env2: 'false',
env3: 'true',
})
})
})

context('in browser launching', () => {
it('uses arch and ARCHPREFERENCE on arm64', async () => {
const cpSpawn = stubForArch('arm64')

await launch({ path: 'chrome' } as unknown as FoundBrowser, 'url', 123, ['arg1'], { env1: 'true' })
await launch({ path: 'chrome' } as unknown as FoundBrowser, 'url', 123, ['arg1'], { env1: 'true', env2: 'true' })

const { args } = cpSpawn.getCall(0)

Expand All @@ -142,20 +148,24 @@ describe('darwin browser detection', () => {
expect(args[2].env).to.deep.include({
ARCHPREFERENCE: 'arm64,x86_64',
env1: 'true',
env2: 'false',
env3: 'true',
})
})

it('does not use `arch` on x64', async () => {
const cpSpawn = stubForArch('x64')

await launch({ path: 'chrome' } as unknown as FoundBrowser, 'url', 123, ['arg1'], { env1: 'true' })
await launch({ path: 'chrome' } as unknown as FoundBrowser, 'url', 123, ['arg1'], { env1: 'true', env2: 'true' })

const { args } = cpSpawn.getCall(0)

expect(args[0]).to.eq('chrome')
expect(args[1]).to.deep.eq(['url', 'arg1'])
expect(args[2].env).to.deep.include({
env1: 'true',
env2: 'false',
env3: 'true',
})

expect(args[2].env).to.not.have.property('ARCHPREFERENCE')
Expand Down