Skip to content

Commit c540284

Browse files
fix: add v8 snapshot usage to cypress in cypress testing (#24860)
1 parent 79f743e commit c540284

27 files changed

+167
-140
lines changed

.circleci/cache-version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Bump this version to force CI to re-create the cache from scratch.
22

3-
12-01-22
3+
12-05-22

.circleci/workflows.yml

+5-9
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ mainBuildFilters: &mainBuildFilters
2828
only:
2929
- develop
3030
- /^release\/\d+\.\d+\.\d+$/
31-
- 'ryanm/fix/v8-improvements'
32-
- 'mschile/windows_session'
31+
- 'ryanm/fix/cy-in-cy-and-v8-snapshots'
3332

3433
# usually we don't build Mac app - it takes a long time
3534
# but sometimes we want to really confirm we are doing the right thing
@@ -38,17 +37,15 @@ macWorkflowFilters: &darwin-workflow-filters
3837
when:
3938
or:
4039
- equal: [ develop, << pipeline.git.branch >> ]
41-
- equal: [ 'ryanm/fix/v8-improvements', << pipeline.git.branch >> ]
42-
- equal: [ 'mschile/windows_session', << pipeline.git.branch >> ]
40+
- equal: [ 'ryanm/fix/cy-in-cy-and-v8-snapshots', << pipeline.git.branch >> ]
4341
- matches:
4442
pattern: /^release\/\d+\.\d+\.\d+$/
4543
value: << pipeline.git.branch >>
4644
linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
4745
when:
4846
or:
4947
- equal: [ develop, << pipeline.git.branch >> ]
50-
- equal: [ 'ryanm/fix/v8-improvements', << pipeline.git.branch >> ]
51-
- equal: [ 'mschile/windows_session', << pipeline.git.branch >> ]
48+
- equal: [ 'ryanm/fix/cy-in-cy-and-v8-snapshots', << pipeline.git.branch >> ]
5249
- matches:
5350
pattern: /^release\/\d+\.\d+\.\d+$/
5451
value: << pipeline.git.branch >>
@@ -66,8 +63,7 @@ windowsWorkflowFilters: &windows-workflow-filters
6663
when:
6764
or:
6865
- equal: [ develop, << pipeline.git.branch >> ]
69-
- equal: [ 'ryanm/fix/v8-improvements', << pipeline.git.branch >> ]
70-
- equal: [ 'mschile/windows_session', << pipeline.git.branch >> ]
66+
- equal: [ 'ryanm/fix/cy-in-cy-and-v8-snapshots', << pipeline.git.branch >> ]
7167
- matches:
7268
pattern: /^release\/\d+\.\d+\.\d+$/
7369
value: << pipeline.git.branch >>
@@ -133,7 +129,7 @@ commands:
133129
- run:
134130
name: Check current branch to persist artifacts
135131
command: |
136-
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "ryanm/fix/v8-improvements" ]]; then
132+
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "ryanm/fix/cy-in-cy-and-v8-snapshots" ]]; then
137133
echo "Not uploading artifacts or posting install comment for this branch."
138134
circleci-agent step halt
139135
fi

npm/vite-dev-server/cypress.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default defineConfig({
1111

1212
// Delete this as we only want to honor it on parent Cypress when doing E2E Cypress in Cypress testing
1313
delete process.env.HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS
14+
delete process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT
1415
process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF = 'true'
1516
process.env.CYPRESS_INTERNAL_VITE_OPEN_MODE_TESTING = 'true'
1617
const { e2ePluginSetup } = require('@packages/frontend-shared/cypress/e2e/e2ePluginSetup') as typeof import('@packages/frontend-shared/cypress/e2e/e2ePluginSetup')

npm/vite-dev-server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build-prod": "tsc || echo 'built, with type errors'",
99
"check-ts": "tsc --noEmit",
1010
"cypress:run": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --project . --browser chrome",
11-
"cypress:run-cypress-in-cypress": "cross-env HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS=http://localhost:4455 CYPRESS_REMOTE_DEBUGGING_PORT=6666 TZ=America/New_York",
11+
"cypress:run-cypress-in-cypress": "cross-env CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT=1 HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS=http://localhost:4455 CYPRESS_REMOTE_DEBUGGING_PORT=6666 TZ=America/New_York",
1212
"cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project .",
1313
"watch": "tsc -w",
1414
"test": "yarn test-unit",

npm/webpack-dev-server/cypress.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default defineConfig({
1111

1212
// Delete this as we only want to honor it on parent Cypress when doing E2E Cypress in Cypress testing
1313
delete process.env.HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS
14+
delete process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT
1415
process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF = 'true'
1516
const { e2ePluginSetup } = require('@packages/frontend-shared/cypress/e2e/e2ePluginSetup') as typeof import('@packages/frontend-shared/cypress/e2e/e2ePluginSetup')
1617

npm/webpack-dev-server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dev": "tsc --watch",
1212
"clean": "rimraf dist",
1313
"cypress:run": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --project . --browser chrome",
14-
"cypress:run-cypress-in-cypress": "cross-env HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS=http://localhost:4455 CYPRESS_REMOTE_DEBUGGING_PORT=6666 TZ=America/New_York",
14+
"cypress:run-cypress-in-cypress": "cross-env CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT=1 HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS=http://localhost:4455 CYPRESS_REMOTE_DEBUGGING_PORT=6666 TZ=America/New_York",
1515
"cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project .",
1616
"test": "yarn test-unit",
1717
"test-unit": "mocha -r ts-node/register/transpile-only --config ./test/.mocharc.js",

package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@
6969
"watch": "yarn gulp watch",
7070
"prepare": "husky install"
7171
},
72-
"dependencies": {
73-
"bytenode": "1.3.7",
74-
"nvm": "0.0.4"
75-
},
7672
"devDependencies": {
7773
"@aws-sdk/credential-providers": "3.53.0",
7874
"@cypress/questions-remain": "1.0.1",
@@ -132,6 +128,7 @@
132128
"babel-eslint": "10.1.0",
133129
"bluebird": "3.5.3",
134130
"bluebird-retry": "0.11.0",
131+
"bytenode": "1.3.7",
135132
"c8": "^7.10.0",
136133
"chai": "4.2.0",
137134
"chai-as-promised": "7.1.1",

packages/app/cypress.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default defineConfig({
3535

3636
// Delete this as we only want to honor it on parent Cypress when doing E2E Cypress in Cypress testing
3737
delete process.env.HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS
38+
delete process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT
3839
process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF = 'true'
3940
process.env.CYPRESS_INTERNAL_VITE_OPEN_MODE_TESTING = 'true'
4041
// process.env.DEBUG = '*'

packages/app/cypress/e2e/runs.cy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
7777
moveToRunsPage()
7878
cy.contains(defaultMessages.runs.connect.buttonUser).click()
7979
cy.withCtx((ctx, o) => {
80-
o.sinon.spy(ctx._apis.authApi, 'logIn')
80+
o.sinon.stub(ctx._apis.authApi, 'logIn')
8181
})
8282

8383
cy.findByRole('dialog', { name: 'Log in to Cypress' }).within(() => {

packages/app/cypress/e2e/settings.cy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ describe('App: Settings without cloud', () => {
399399
cy.findByText('Cypress Cloud settings').click()
400400
cy.findByText('Project ID').should('not.exist')
401401
cy.withCtx((ctx, o) => {
402-
o.sinon.spy(ctx._apis.authApi, 'logIn')
402+
o.sinon.stub(ctx._apis.authApi, 'logIn')
403403
})
404404

405405
cy.contains('button', 'Log in to Cypress Cloud').click()

packages/app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"clean": "rimraf dist && rimraf ./node_modules/.vite && echo 'cleaned'",
99
"clean-deps": "rimraf node_modules",
1010
"test": "echo 'ok'",
11-
"cypress:run-cypress-in-cypress": "cross-env HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS=http://localhost:4455 CYPRESS_REMOTE_DEBUGGING_PORT=6666 TZ=America/New_York",
11+
"cypress:run-cypress-in-cypress": "cross-env CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT=1 HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS=http://localhost:4455 CYPRESS_REMOTE_DEBUGGING_PORT=6666 TZ=America/New_York",
1212
"cypress:launch": "yarn cypress:run-cypress-in-cypress gulp open --project .",
1313
"cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project .",
1414
"cypress:run:ct": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --component --project .",

packages/config/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@babel/parser": "^7",
2222
"@babel/plugin-syntax-typescript": "^7",
2323
"@babel/plugin-transform-typescript": "^7",
24-
"@babel/traverse": "^7",
24+
"@babel/traverse": "7.15.4",
2525
"@babel/types": "^7",
2626
"check-more-types": "2.24.0",
2727
"common-tags": "1.8.0",

packages/data-context/src/data/ProjectConfigIpc.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-dupe-class-members */
22
import { CypressError, getError } from '@packages/errors'
33
import type { FullConfig, TestingType } from '@packages/types'
4-
import { ChildProcess, fork, ForkOptions } from 'child_process'
4+
import { ChildProcess, fork, ForkOptions, spawn } from 'child_process'
55
import EventEmitter from 'events'
66
import fs from 'fs-extra'
77
import path from 'path'
@@ -10,6 +10,7 @@ import debugLib from 'debug'
1010
import { autoBindDebug, hasTypeScriptInstalled, toPosix } from '../util'
1111
import _ from 'lodash'
1212
import { pathToFileURL } from 'url'
13+
import os from 'os'
1314

1415
const pkg = require('@packages/root')
1516
const debug = debugLib(`cypress:lifecycle:ProjectConfigIpc`)
@@ -21,6 +22,14 @@ const tsNode = toPosix(require.resolve('@packages/server/lib/plugins/child/regis
2122

2223
export type IpcHandler = (ipc: ProjectConfigIpc) => void
2324

25+
/**
26+
* If running as root on Linux, no-sandbox must be passed or Chrome will not start
27+
*/
28+
const isSandboxNeeded = () => {
29+
// eslint-disable-next-line no-restricted-properties
30+
return (os.platform() === 'linux') && (process.geteuid && process.geteuid() === 0)
31+
}
32+
2433
export interface SetupNodeEventsReply {
2534
setupConfig: Cypress.ConfigOptions | null
2635
requires: string[]
@@ -310,6 +319,17 @@ export class ProjectConfigIpc extends EventEmitter {
310319
debug(`no typescript found, just use regular Node.js`)
311320
}
312321

322+
if (process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT) {
323+
if (isSandboxNeeded()) {
324+
configProcessArgs.push('--no-sandbox')
325+
}
326+
327+
return spawn(process.execPath, ['--entryPoint', CHILD_PROCESS_FILE_PATH, ...configProcessArgs], {
328+
...childOptions,
329+
stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
330+
})
331+
}
332+
313333
return fork(CHILD_PROCESS_FILE_PATH, configProcessArgs, childOptions)
314334
}
315335

packages/data-context/src/sources/ErrorDataSource.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class ErrorDataSource {
3838
} else {
3939
// Skip any stack trace lines which come from node:internal code
4040
const stackLines = stackUtils.getStackLines(source.cypressError.stack ?? '')
41-
const filteredStackLines = stackLines.filter((stackLine) => !stackLine.includes('node:internal') && !stackLine.includes('source-map-support'))
41+
const filteredStackLines = stackLines.filter((stackLine) => !stackLine.includes('node:electron') && !stackLine.includes('node:internal') && !stackLine.includes('source-map-support'))
4242
const parsedLine = stackUtils.parseStackLine(filteredStackLines[0] ?? '')
4343

4444
if (parsedLine) {

packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { hookRequire } from '@packages/server/hook-require'
2+
3+
hookRequire({ forceTypeScript: false })
4+
15
import path from 'path'
26
import execa from 'execa'
37

@@ -43,6 +47,11 @@ chai.use(chaiSubset)
4347
chai.use(sinonChai)
4448

4549
export async function e2ePluginSetup (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) {
50+
// @ts-ignore snapshotAuxiliaryData is injected by the snapshot script
51+
if (typeof global.snapshotAuxiliaryData === 'undefined') {
52+
throw new Error('snapshotAuxiliaryData is undefined. v8 snapshots are not being used in Cypress in Cypress')
53+
}
54+
4655
process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF = 'true'
4756
delete process.env.CYPRESS_INTERNAL_GRAPHQL_PORT
4857
delete process.env.CYPRESS_INTERNAL_VITE_DEV

packages/launchpad/cypress.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default defineConfig({
2828
baseUrl: 'http://localhost:5555',
2929
supportFile: 'cypress/e2e/support/e2eSupport.ts',
3030
async setupNodeEvents (on, config) {
31+
delete process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT
3132
process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF = 'true'
3233
const { e2ePluginSetup } = require('@packages/frontend-shared/cypress/e2e/e2ePluginSetup')
3334

packages/launchpad/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
"clean-deps": "rimraf node_modules",
1010
"test": "yarn cypress:run:ct && yarn types",
1111
"windi": "yarn windicss-analysis",
12-
"cypress:open": "cross-env TZ=America/New_York gulp open --project .",
13-
"cypress:open:ct": "cross-env TZ=America/New_York gulp open --component --project .",
14-
"cypress:run:ct": "cross-env TZ=America/New_York node ../../scripts/cypress run --component --project .",
15-
"cypress:run:e2e": "cross-env TZ=America/New_York node ../../scripts/cypress run --e2e --project .",
12+
"cypress:run-cypress-in-cypress": "cross-env CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT=1 TZ=America/New_York",
13+
"cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project .",
14+
"cypress:open:ct": "yarn cypress:run-cypress-in-cypress gulp open --component --project .",
15+
"cypress:run:ct": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --component --project .",
16+
"cypress:run:e2e": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --e2e --project .",
1617
"dev": "yarn gulp dev --project .",
1718
"start": "echo 'run yarn dev from the root' && exit 1",
1819
"watch": "echo 'run yarn dev from the root' && exit 1",

packages/packherd-require/src/loader.ts

-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import { strict as assert } from 'assert'
1212

1313
const logDebug = debug('cypress-verbose:packherd:debug')
1414
const logTrace = debug('cypress-verbose:packherd:trace')
15-
const logSilly = debug('cypress-verbose:packherd:silly')
16-
const logWarn = debug('cypress:packherd:warn')
1715

1816
/**
1917
* Provides information that is used to resolve a module's key from its URI.
@@ -869,11 +867,6 @@ export class PackherdModuleLoader {
869867
this.definitionHits.add(mod.id)
870868

871869
return { mod, origin }
872-
} catch (err: any) {
873-
logWarn(err.message)
874-
logSilly(err)
875-
876-
return { mod: undefined, origin }
877870
} finally {
878871
this.loading.finish(fullPath)
879872
}

packages/server/index.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
const { initializeStartTime } = require('./lib/util/performance_benchmark')
1+
const runChildProcess = async (entryPoint) => {
2+
require('./lib/plugins/child/register_ts_node')
3+
require(entryPoint)
4+
}
25

36
const startCypress = async () => {
47
try {
8+
const { initializeStartTime } = require('./lib/util/performance_benchmark')
9+
510
initializeStartTime()
611

712
const { hookRequire } = require('./hook-require')
@@ -16,4 +21,10 @@ const startCypress = async () => {
1621
}
1722
}
1823

19-
module.exports = startCypress()
24+
const { entryPoint } = require('minimist')(process.argv.slice(1))
25+
26+
if (entryPoint) {
27+
module.exports = runChildProcess(entryPoint)
28+
} else {
29+
module.exports = startCypress()
30+
}

0 commit comments

Comments
 (0)