Skip to content

Commit

Permalink
fix: spawn child process with process.env in macOS arm64 (#25753)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Schile <mschile@cypress.io>
Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
Co-authored-by: Zach Bloomquist <github@chary.us>
  • Loading branch information
4 people authored Feb 13, 2023
1 parent a11e266 commit 88c2279
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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

5 comments on commit 88c2279

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 88c2279 Feb 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.6.0/linux-x64/develop-88c2279b555aad8f3e2d41eea528535094a9909e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 88c2279 Feb 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.6.0/linux-arm64/develop-88c2279b555aad8f3e2d41eea528535094a9909e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 88c2279 Feb 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.6.0/darwin-x64/develop-88c2279b555aad8f3e2d41eea528535094a9909e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 88c2279 Feb 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.6.0/darwin-arm64/develop-88c2279b555aad8f3e2d41eea528535094a9909e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 88c2279 Feb 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.6.0/win32-x64/develop-88c2279b555aad8f3e2d41eea528535094a9909e/cypress.tgz

Please sign in to comment.