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: add v8 snapshot usage to cypress in cypress testing #24860

Merged
merged 36 commits into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f03253c
fix: add v8 snapshot usage to cypress in cypress testing
ryanthemanuel Nov 16, 2022
65580d9
fix linux build
ryanthemanuel Nov 17, 2022
6684f14
ensure that snapshot is only used on e2e
ryanthemanuel Nov 17, 2022
e2d06d1
fix ci
ryanthemanuel Nov 17, 2022
67d7366
add debugging
ryanthemanuel Nov 17, 2022
a45ca79
Empty commit
ryanthemanuel Nov 28, 2022
a5388d9
enable more debugging
ryanthemanuel Nov 28, 2022
92c21ad
enable more debugging
ryanthemanuel Nov 28, 2022
d082194
enable more debugging
ryanthemanuel Nov 28, 2022
f24e168
fix bug
ryanthemanuel Nov 28, 2022
33cbd0c
fix bug
ryanthemanuel Nov 28, 2022
7894213
fix tests
ryanthemanuel Nov 28, 2022
4a12e7d
Merge branch 'develop' into ryanm/fix/cy-in-cy-and-v8-snapshots
ryanthemanuel Nov 28, 2022
ff9387c
Update config.yml
ryanthemanuel Nov 28, 2022
d4ef5b4
Update workflows.yml
ryanthemanuel Nov 28, 2022
dd6d5d9
refactoring
ryanthemanuel Nov 28, 2022
51eff1c
cleanup
ryanthemanuel Nov 28, 2022
c962c42
run ci
ryanthemanuel Nov 28, 2022
0652445
Merge branch 'develop' into ryanm/fix/cy-in-cy-and-v8-snapshots
ryanthemanuel Dec 4, 2022
b4c119e
Merge branch 'develop' into ryanm/fix/cy-in-cy-and-v8-snapshots
ryanthemanuel Dec 5, 2022
737391b
clean up the bytenode dependency
ryanthemanuel Dec 5, 2022
aa5f7af
Merge branch 'develop' into ryanm/fix/cy-in-cy-and-v8-snapshots
ryanthemanuel Dec 5, 2022
7d80f64
fix build
ryanthemanuel Dec 5, 2022
f4c207f
Merge branch 'develop' into ryanm/fix/cy-in-cy-and-v8-snapshots
ryanthemanuel Dec 5, 2022
0873220
update yarn.lock
ryanthemanuel Dec 5, 2022
5179d50
Update cache-version.txt
ryanthemanuel Dec 6, 2022
ce86292
Update packages/data-context/src/data/ProjectConfigIpc.ts
ryanthemanuel Dec 6, 2022
2bf7b8a
Update packages/server/index.js
ryanthemanuel Dec 6, 2022
d8f5dcf
move around the hook for snapshots
ryanthemanuel Dec 6, 2022
40ec8ef
Merge branch 'develop' into ryanm/fix/cy-in-cy-and-v8-snapshots
ryanthemanuel Dec 6, 2022
1ff5927
ensure to fail if snapshots become unavailable for cypress in cypress
ryanthemanuel Dec 6, 2022
ea40564
undo refactor
ryanthemanuel Dec 6, 2022
0d9e3cb
Merge branch 'develop' into ryanm/fix/cy-in-cy-and-v8-snapshots
ryanthemanuel Dec 6, 2022
8bab2db
Merge branch 'develop' into ryanm/fix/cy-in-cy-and-v8-snapshots
ryanthemanuel Dec 7, 2022
d483d47
use getSnapshotResult for check in e2eplugins
ryanthemanuel Dec 7, 2022
9ba8ca8
Merge branch 'develop' into ryanm/fix/cy-in-cy-and-v8-snapshots
ryanthemanuel Dec 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
10 changes: 5 additions & 5 deletions .circleci/workflows.yml
Expand Up @@ -28,7 +28,7 @@ mainBuildFilters: &mainBuildFilters
only:
- develop
- /^release\/\d+\.\d+\.\d+$/
- 'ryanm/fix/v8-improvements'
- '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 @@ -37,15 +37,15 @@ macWorkflowFilters: &darwin-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/v8-improvements', << 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: [ 'ryanm/fix/cy-in-cy-and-v8-snapshots', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand All @@ -63,7 +63,7 @@ windowsWorkflowFilters: &windows-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/v8-improvements', << 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 @@ -129,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",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this to match the rest of the repo.

"@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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit of a shame we need to ship test code to prod :'(

This is "the change" that lets v8 snapshots run in cy-in-cy?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anyway to verify it now uses snapshots in the tests? How do we know it works (and catch it if stops?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's unfortunate, but I'm not sure of a clean way to do it otherwise with how everything is structured.

And, I like your idea. I added a check to ensure that we fail in cypress in cypress if the snapshot is unavailable.

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
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
20 changes: 18 additions & 2 deletions packages/server/index.js
@@ -1,7 +1,17 @@
const { initializeStartTime } = require('./lib/util/performance_benchmark')
const runChildProcess = async (entryPoint) => {
require('./lib/plugins/child/register_ts_node')

const { hookRequire } = require('@packages/server/hook-require')

hookRequire({ forceTypeScript: false })

require(entryPoint)
}

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

initializeStartTime()

const { hookRequire } = require('./hook-require')
Expand All @@ -16,4 +26,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()
}