Skip to content

Commit

Permalink
Removing browser detection workaround for mac now that electron has b…
Browse files Browse the repository at this point in the history
…een patched/upgraded
  • Loading branch information
tbiethman committed May 10, 2022
1 parent cc1ee42 commit 5a53737
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 82 deletions.
6 changes: 0 additions & 6 deletions packages/launcher/lib/darwin/detection-workaround.ts

This file was deleted.

21 changes: 0 additions & 21 deletions packages/launcher/lib/darwin/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import { log } from '../log'
import { notInstalledErr } from '../errors'
import { utils } from '../utils'
import * as fs from 'fs-extra'
import * as os from 'os'
import * as path from 'path'
import * as plist from 'plist'
import * as semver from 'semver'
import type { FoundBrowser } from '../types'
import * as findSystemNode from '@packages/server/lib/util/find_system_node'

/** parses Info.plist file from given application and returns a property */
export function parsePlist (p: string, property: string): Promise<string> {
Expand Down Expand Up @@ -105,20 +101,3 @@ export function findApp ({ appName, executable, appId, versionProperty }: FindAp

return tryMdFind().catch(tryFullApplicationFind)
}

export function needsDarwinWorkaround (): boolean {
return os.platform() === 'darwin' && semver.gte(os.release(), '20.0.0')
}

export async function darwinDetectionWorkaround (): Promise<FoundBrowser[]> {
const nodePath = await findSystemNode.findNodeInFullPath()
let args = ['./detection-workaround.js']

if (process.env.CYPRESS_INTERNAL_ENV === 'development') {
args = ['-r', '@packages/ts/register.js', './detection-workaround.ts']
}

const { stdout } = await utils.execa(nodePath, args, { cwd: __dirname })

return JSON.parse(stdout)
}
34 changes: 1 addition & 33 deletions packages/launcher/lib/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import _, { compact, extend, find } from 'lodash'
import os from 'os'
import { browsers } from './browsers'
import * as darwinHelper from './darwin'
import { needsDarwinWorkaround, darwinDetectionWorkaround } from './darwin/util'
import { notDetectedAtPathErr } from './errors'
import * as linuxHelper from './linux'
import { log } from './log'
Expand Down Expand Up @@ -141,44 +140,13 @@ function checkOneBrowser (browser: Browser): Promise<boolean | HasVersion> {
}

/** returns list of detected browsers */
export const detect = (goalBrowsers?: Browser[], useDarwinWorkaround = true): Bluebird<FoundBrowser[]> => {
export const detect = (goalBrowsers?: Browser[]): Bluebird<FoundBrowser[]> => {
// we can detect same browser under different aliases
// tell them apart by the name and the version property
if (!goalBrowsers) {
goalBrowsers = browsers
}

// BigSur (darwin 20.x) and Electron 12+ cause huge performance issues when
// spawning child processes, which is the way we find browsers via execa.
// The performance cost is multiplied by the number of binary variants of
// each browser plus any fallback lookups we do.
// The workaround gets around this by breaking out of the bundled Electron
// Node.js and using the user's Node.js if possible. It only pays the cost
// of spawning a single child process instead of multiple. If this fails,
// we fall back to to the slower, default method
// https://github.com/cypress-io/cypress/issues/17773
if (useDarwinWorkaround && needsDarwinWorkaround()) {
log('using darwin detection workaround')
if (log.enabled) {
// eslint-disable-next-line no-console
console.time('time taken detecting browsers (darwin workaround)')
}

return Bluebird.resolve(darwinDetectionWorkaround())
.catch((err) => {
log('darwin workaround failed, falling back to normal detection')
log(err.stack)

return detect(goalBrowsers, false)
})
.finally(() => {
if (log.enabled) {
// eslint-disable-next-line no-console
console.timeEnd('time taken detecting browsers (darwin workaround)')
}
})
}

const removeDuplicates = (val) => {
return _.uniqBy(val, (browser: FoundBrowser) => {
return `${browser.name}-${browser.version}`
Expand Down
22 changes: 0 additions & 22 deletions packages/launcher/test/unit/detect_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { utils } from '../../lib/utils'
import sinon, { SinonStub } from 'sinon'
import os from 'os'
import { log } from '../log'
import * as darwinUtil from '../../lib/darwin/util'

const isWindows = () => {
return os.platform() === 'win32'
Expand Down Expand Up @@ -169,25 +168,4 @@ describe('browser detection', () => {
.and.contain('Firefox newer than or equal to 86')
})
})

// https://github.com/cypress-io/cypress/issues/17773
context('darwin performance workaround', () => {
let browsers

beforeEach(() => {
sinon.stub(os, 'platform').returns('darwin')
sinon.stub(os, 'release').returns('20.0.0')

browsers = []

sinon.stub(darwinUtil, 'darwinDetectionWorkaround').resolves(browsers)
})

it('uses workaround when on darwin 20.0.0+', async () => {
const result = await detect()

expect(darwinUtil.darwinDetectionWorkaround).to.be.called
expect(result).to.equal(browsers)
})
})
})

0 comments on commit 5a53737

Please sign in to comment.