Skip to content

Commit

Permalink
fix: add v8 snapshot usage to cypress in cypress testing (#24860)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthemanuel committed Dec 8, 2022
1 parent 79f743e commit c540284
Show file tree
Hide file tree
Showing 27 changed files with 167 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .circleci/cache-version.txt
@@ -1,3 +1,3 @@
# Bump this version to force CI to re-create the cache from scratch.

12-01-22
12-05-22
14 changes: 5 additions & 9 deletions .circleci/workflows.yml
Expand Up @@ -28,8 +28,7 @@ mainBuildFilters: &mainBuildFilters
only:
- develop
- /^release\/\d+\.\d+\.\d+$/
- 'ryanm/fix/v8-improvements'
- 'mschile/windows_session'
- 'ryanm/fix/cy-in-cy-and-v8-snapshots'

# usually we don't build Mac app - it takes a long time
# but sometimes we want to really confirm we are doing the right thing
Expand All @@ -38,17 +37,15 @@ macWorkflowFilters: &darwin-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/v8-improvements', << pipeline.git.branch >> ]
- equal: [ 'mschile/windows_session', << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/cy-in-cy-and-v8-snapshots', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/v8-improvements', << pipeline.git.branch >> ]
- equal: [ 'mschile/windows_session', << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/cy-in-cy-and-v8-snapshots', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand All @@ -66,8 +63,7 @@ windowsWorkflowFilters: &windows-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/v8-improvements', << pipeline.git.branch >> ]
- equal: [ 'mschile/windows_session', << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/cy-in-cy-and-v8-snapshots', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand Down Expand Up @@ -133,7 +129,7 @@ commands:
- run:
name: Check current branch to persist artifacts
command: |
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "ryanm/fix/v8-improvements" ]]; then
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "ryanm/fix/cy-in-cy-and-v8-snapshots" ]]; then
echo "Not uploading artifacts or posting install comment for this branch."
circleci-agent step halt
fi
Expand Down
1 change: 1 addition & 0 deletions npm/vite-dev-server/cypress.config.ts
Expand Up @@ -11,6 +11,7 @@ export default defineConfig({

// Delete this as we only want to honor it on parent Cypress when doing E2E Cypress in Cypress testing
delete process.env.HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS
delete process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT
process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF = 'true'
process.env.CYPRESS_INTERNAL_VITE_OPEN_MODE_TESTING = 'true'
const { e2ePluginSetup } = require('@packages/frontend-shared/cypress/e2e/e2ePluginSetup') as typeof import('@packages/frontend-shared/cypress/e2e/e2ePluginSetup')
Expand Down
2 changes: 1 addition & 1 deletion npm/vite-dev-server/package.json
Expand Up @@ -8,7 +8,7 @@
"build-prod": "tsc || echo 'built, with type errors'",
"check-ts": "tsc --noEmit",
"cypress:run": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --project . --browser chrome",
"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",
"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",
"cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project .",
"watch": "tsc -w",
"test": "yarn test-unit",
Expand Down
1 change: 1 addition & 0 deletions npm/webpack-dev-server/cypress.config.ts
Expand Up @@ -11,6 +11,7 @@ export default defineConfig({

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

Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/package.json
Expand Up @@ -11,7 +11,7 @@
"dev": "tsc --watch",
"clean": "rimraf dist",
"cypress:run": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --project . --browser chrome",
"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",
"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",
"cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project .",
"test": "yarn test-unit",
"test-unit": "mocha -r ts-node/register/transpile-only --config ./test/.mocharc.js",
Expand Down
5 changes: 1 addition & 4 deletions package.json
Expand Up @@ -69,10 +69,6 @@
"watch": "yarn gulp watch",
"prepare": "husky install"
},
"dependencies": {
"bytenode": "1.3.7",
"nvm": "0.0.4"
},
"devDependencies": {
"@aws-sdk/credential-providers": "3.53.0",
"@cypress/questions-remain": "1.0.1",
Expand Down Expand Up @@ -132,6 +128,7 @@
"babel-eslint": "10.1.0",
"bluebird": "3.5.3",
"bluebird-retry": "0.11.0",
"bytenode": "1.3.7",
"c8": "^7.10.0",
"chai": "4.2.0",
"chai-as-promised": "7.1.1",
Expand Down
1 change: 1 addition & 0 deletions packages/app/cypress.config.ts
Expand Up @@ -35,6 +35,7 @@ export default defineConfig({

// Delete this as we only want to honor it on parent Cypress when doing E2E Cypress in Cypress testing
delete process.env.HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS
delete process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT
process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF = 'true'
process.env.CYPRESS_INTERNAL_VITE_OPEN_MODE_TESTING = 'true'
// process.env.DEBUG = '*'
Expand Down
2 changes: 1 addition & 1 deletion packages/app/cypress/e2e/runs.cy.ts
Expand Up @@ -77,7 +77,7 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
moveToRunsPage()
cy.contains(defaultMessages.runs.connect.buttonUser).click()
cy.withCtx((ctx, o) => {
o.sinon.spy(ctx._apis.authApi, 'logIn')
o.sinon.stub(ctx._apis.authApi, 'logIn')
})

cy.findByRole('dialog', { name: 'Log in to Cypress' }).within(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/cypress/e2e/settings.cy.ts
Expand Up @@ -399,7 +399,7 @@ describe('App: Settings without cloud', () => {
cy.findByText('Cypress Cloud settings').click()
cy.findByText('Project ID').should('not.exist')
cy.withCtx((ctx, o) => {
o.sinon.spy(ctx._apis.authApi, 'logIn')
o.sinon.stub(ctx._apis.authApi, 'logIn')
})

cy.contains('button', 'Log in to Cypress Cloud').click()
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Expand Up @@ -8,7 +8,7 @@
"clean": "rimraf dist && rimraf ./node_modules/.vite && echo 'cleaned'",
"clean-deps": "rimraf node_modules",
"test": "echo 'ok'",
"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",
"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",
"cypress:launch": "yarn cypress:run-cypress-in-cypress gulp open --project .",
"cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project .",
"cypress:run:ct": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --component --project .",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/package.json
Expand Up @@ -21,7 +21,7 @@
"@babel/parser": "^7",
"@babel/plugin-syntax-typescript": "^7",
"@babel/plugin-transform-typescript": "^7",
"@babel/traverse": "^7",
"@babel/traverse": "7.15.4",
"@babel/types": "^7",
"check-more-types": "2.24.0",
"common-tags": "1.8.0",
Expand Down
22 changes: 21 additions & 1 deletion packages/data-context/src/data/ProjectConfigIpc.ts
@@ -1,7 +1,7 @@
/* eslint-disable no-dupe-class-members */
import { CypressError, getError } from '@packages/errors'
import type { FullConfig, TestingType } from '@packages/types'
import { ChildProcess, fork, ForkOptions } from 'child_process'
import { ChildProcess, fork, ForkOptions, spawn } from 'child_process'
import EventEmitter from 'events'
import fs from 'fs-extra'
import path from 'path'
Expand All @@ -10,6 +10,7 @@ import debugLib from 'debug'
import { autoBindDebug, hasTypeScriptInstalled, toPosix } from '../util'
import _ from 'lodash'
import { pathToFileURL } from 'url'
import os from 'os'

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

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

/**
* If running as root on Linux, no-sandbox must be passed or Chrome will not start
*/
const isSandboxNeeded = () => {
// eslint-disable-next-line no-restricted-properties
return (os.platform() === 'linux') && (process.geteuid && process.geteuid() === 0)
}

export interface SetupNodeEventsReply {
setupConfig: Cypress.ConfigOptions | null
requires: string[]
Expand Down Expand Up @@ -310,6 +319,17 @@ export class ProjectConfigIpc extends EventEmitter {
debug(`no typescript found, just use regular Node.js`)
}

if (process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT) {
if (isSandboxNeeded()) {
configProcessArgs.push('--no-sandbox')
}

return spawn(process.execPath, ['--entryPoint', CHILD_PROCESS_FILE_PATH, ...configProcessArgs], {
...childOptions,
stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
})
}

return fork(CHILD_PROCESS_FILE_PATH, configProcessArgs, childOptions)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/data-context/src/sources/ErrorDataSource.ts
Expand Up @@ -38,7 +38,7 @@ export class ErrorDataSource {
} else {
// Skip any stack trace lines which come from node:internal code
const stackLines = stackUtils.getStackLines(source.cypressError.stack ?? '')
const filteredStackLines = stackLines.filter((stackLine) => !stackLine.includes('node:internal') && !stackLine.includes('source-map-support'))
const filteredStackLines = stackLines.filter((stackLine) => !stackLine.includes('node:electron') && !stackLine.includes('node:internal') && !stackLine.includes('source-map-support'))
const parsedLine = stackUtils.parseStackLine(filteredStackLines[0] ?? '')

if (parsedLine) {
Expand Down
9 changes: 9 additions & 0 deletions packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts
@@ -1,3 +1,7 @@
import { hookRequire } from '@packages/server/hook-require'

hookRequire({ forceTypeScript: false })

import path from 'path'
import execa from 'execa'

Expand Down Expand Up @@ -43,6 +47,11 @@ chai.use(chaiSubset)
chai.use(sinonChai)

export async function e2ePluginSetup (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) {
// @ts-ignore snapshotAuxiliaryData is injected by the snapshot script
if (typeof global.snapshotAuxiliaryData === 'undefined') {
throw new Error('snapshotAuxiliaryData is undefined. v8 snapshots are not being used in Cypress in Cypress')
}

process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF = 'true'
delete process.env.CYPRESS_INTERNAL_GRAPHQL_PORT
delete process.env.CYPRESS_INTERNAL_VITE_DEV
Expand Down
1 change: 1 addition & 0 deletions packages/launchpad/cypress.config.ts
Expand Up @@ -28,6 +28,7 @@ export default defineConfig({
baseUrl: 'http://localhost:5555',
supportFile: 'cypress/e2e/support/e2eSupport.ts',
async setupNodeEvents (on, config) {
delete process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT
process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF = 'true'
const { e2ePluginSetup } = require('@packages/frontend-shared/cypress/e2e/e2ePluginSetup')

Expand Down
9 changes: 5 additions & 4 deletions packages/launchpad/package.json
Expand Up @@ -9,10 +9,11 @@
"clean-deps": "rimraf node_modules",
"test": "yarn cypress:run:ct && yarn types",
"windi": "yarn windicss-analysis",
"cypress:open": "cross-env TZ=America/New_York gulp open --project .",
"cypress:open:ct": "cross-env TZ=America/New_York gulp open --component --project .",
"cypress:run:ct": "cross-env TZ=America/New_York node ../../scripts/cypress run --component --project .",
"cypress:run:e2e": "cross-env TZ=America/New_York node ../../scripts/cypress run --e2e --project .",
"cypress:run-cypress-in-cypress": "cross-env CYPRESS_INTERNAL_E2E_TESTING_SELF_PARENT_PROJECT=1 TZ=America/New_York",
"cypress:open": "yarn cypress:run-cypress-in-cypress gulp open --project .",
"cypress:open:ct": "yarn cypress:run-cypress-in-cypress gulp open --component --project .",
"cypress:run:ct": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --component --project .",
"cypress:run:e2e": "yarn cypress:run-cypress-in-cypress node ../../scripts/cypress run --e2e --project .",
"dev": "yarn gulp dev --project .",
"start": "echo 'run yarn dev from the root' && exit 1",
"watch": "echo 'run yarn dev from the root' && exit 1",
Expand Down
7 changes: 0 additions & 7 deletions packages/packherd-require/src/loader.ts
Expand Up @@ -12,8 +12,6 @@ import { strict as assert } from 'assert'

const logDebug = debug('cypress-verbose:packherd:debug')
const logTrace = debug('cypress-verbose:packherd:trace')
const logSilly = debug('cypress-verbose:packherd:silly')
const logWarn = debug('cypress:packherd:warn')

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

return { mod, origin }
} catch (err: any) {
logWarn(err.message)
logSilly(err)

return { mod: undefined, origin }
} finally {
this.loading.finish(fullPath)
}
Expand Down
15 changes: 13 additions & 2 deletions packages/server/index.js
@@ -1,7 +1,12 @@
const { initializeStartTime } = require('./lib/util/performance_benchmark')
const runChildProcess = async (entryPoint) => {
require('./lib/plugins/child/register_ts_node')
require(entryPoint)
}

const startCypress = async () => {
try {
const { initializeStartTime } = require('./lib/util/performance_benchmark')

initializeStartTime()

const { hookRequire } = require('./hook-require')
Expand All @@ -16,4 +21,10 @@ const startCypress = async () => {
}
}

module.exports = startCypress()
const { entryPoint } = require('minimist')(process.argv.slice(1))

if (entryPoint) {
module.exports = runChildProcess(entryPoint)
} else {
module.exports = startCypress()
}

5 comments on commit c540284

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c540284 Dec 8, 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/12.0.2/linux-arm64/develop-c540284f5080d46a8597e53dd2213cb6fb133078/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c540284 Dec 8, 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/12.0.2/linux-x64/develop-c540284f5080d46a8597e53dd2213cb6fb133078/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c540284 Dec 8, 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/12.0.2/darwin-arm64/develop-c540284f5080d46a8597e53dd2213cb6fb133078/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c540284 Dec 8, 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/12.0.2/darwin-x64/develop-c540284f5080d46a8597e53dd2213cb6fb133078/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c540284 Dec 8, 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/12.0.2/win32-x64/develop-c540284f5080d46a8597e53dd2213cb6fb133078/cypress.tgz

Please sign in to comment.