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: ct testing support for node 17+ #21430

Merged
merged 9 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ const util = {
// To be removed when the Cypress binary pulls in the @cypress/webpack-batteries-included-preprocessor
// version that has been updated to webpack >= 5.61, which no longer relies on
// Node's builtin crypto.hash function.
if (process.versions && semver.satisfies(process.versions.node, '>=17.0.0') && process.versions.openssl.startsWith('3.')) {
if (process.versions && semver.satisfies(process.versions.node, '>=17.0.0') && semver.satisfies(process.versions.openssl, '>=3', { includePrerelease: true })) {
opts.ORIGINAL_NODE_OPTIONS = `${opts.ORIGINAL_NODE_OPTIONS || ''} --openssl-legacy-provider`
}

Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/src/createWebpackDevServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function webpackDevServer4 (
const { devServerConfig: { cypressConfig: { devServerPublicPathRoute } } } = config
const WebpackDevServer = config.sourceWebpackModulesResult.webpackDevServer.module
const webpackDevServerConfig = {
host: 'localhost',
host: '127.0.0.1',
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, we should never use 'localhost' in the App due to issues like this. We've even had users with an incorrect localhost entry in /etc/hosts, which causes mind boggling issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was absolutely baffled as to what was going on until I stumbled upon the issues I listed above.

port: 'auto',
// @ts-ignore
...finalWebpackConfig?.devServer,
Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/test/devServer-e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import './support'
const requestSpecFile = (file: string, port: number) => {
return new Promise((res) => {
const opts = {
host: 'localhost',
host: '127.0.0.1',
port,
path: encodeURI(file),
}
Expand Down
9 changes: 4 additions & 5 deletions packages/extension/gulpfile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import gulp from 'gulp'
import rimraf from 'rimraf'
import webpack from 'webpack'
import * as cypressIcons from '@packages/icons'
import webpackConfig from './webpack.config.js'
import cp from 'child_process'
import util from 'util'
const exec = util.promisify(cp.exec)

const clean = (done) => {
rimraf('dist', done)
Expand All @@ -14,9 +15,7 @@ const manifest = () => {
}

const background = (cb) => {
const compiler = webpack(webpackConfig as webpack.Configuration)

compiler.run(cb)
exec('node ../../scripts/run-webpack.js').then(() => cb()).catch(cb)
}

const html = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"test-debug": "yarn test-unit --inspect-brk=5566",
"test-unit": "cross-env NODE_ENV=test mocha -r @packages/ts/register --reporter mocha-multi-reporters --reporter-options configFile=../../mocha-reporter-config.json",
"test-watch": "yarn test-unit --watch",
"watch": "webpack --watch --progress"
"watch": "node ../../scripts/run-webpack --watch --progress"
},
"dependencies": {
"bluebird": "3.5.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/reporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"browser": "src/main.tsx",
"scripts": {
"build-for-tests": "webpack",
"build-for-tests": "node ../../scripts/run-webpack",
"clean-deps": "rimraf node_modules",
"cypress:open": "node ../../scripts/cypress open --project .",
"cypress:run": "node ../../scripts/cypress run --project .",
Expand Down
4 changes: 2 additions & 2 deletions packages/runner-ct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"private": true,
"browser": "src/index.js",
"scripts": {
"build": "webpack",
"build": "node ../../scripts/run-webpack",
"build-prod": "cross-env NODE_ENV=production yarn build && tsc",
"clean-deps": "rimraf node_modules",
"cypress:open": "ts-node ../../scripts/cypress.js open --component --project .",
"cypress:run": "ts-node ../../scripts/cypress.js run --component --project .",
"postinstall": "echo '@packages/runner needs: yarn build'",
"lint": "eslint --ext .js,.jsx,.ts,.tsx,.json src",
"test": "ts-node ../../scripts/cypress.js run --component --project .",
"watch": "webpack --watch --progress --config webpack.config.ts"
"watch": "node ../../scripts/run-webpack --watch --progress --config webpack.config.ts"
},
"dependencies": {},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"browser": "src/index.js",
"scripts": {
"build": "webpack",
"build": "node ../../scripts/run-webpack",
"build-prod": "cross-env NODE_ENV=production yarn build",
"clean-deps": "rimraf node_modules",
"cypress:open": "node ../../scripts/cypress open",
Expand All @@ -14,7 +14,7 @@
"test-debug": "yarn test-unit --inspect-brk=5566",
"test-unit": "mocha --config test/.mocharc.json src/**/*.spec.* --exit",
"test-watch": "yarn test-unit --watch",
"watch": "webpack --watch --progress"
"watch": "node ../../scripts/run-webpack --watch --progress"
},
"devDependencies": {
"@cypress/react-tooltip": "0.5.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"main": "src/index.tsx",
"scripts": {
"build-for-tests": "webpack",
"build-for-tests": "node ../../scripts/run-webpack",
"check-deps": "node ../../scripts/check-deps.js --verbose",
"check-deps-pre": "npm run check-deps -- --prescript",
"clean-deps": "rimraf node_modules",
Expand Down Expand Up @@ -39,6 +39,6 @@
"react-dom": "16.8.6",
"rimraf": "3.0.2",
"webpack": "^4.44.2",
"webpack-cli": "3.3.11"
"webpack-cli": "3.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/web-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"sass-loader": "10.1.0",
"sinon-chai": "3.3.0",
"webpack": "^4.44.2",
"webpack-cli": "3.3.11",
"webpack-cli": "3.3.2",
"webpack-livereload-plugin": "2.3.0"
}
}
23 changes: 22 additions & 1 deletion scripts/gulp/tasks/gulpWebpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import pDefer from 'p-defer'
import { monorepoPaths } from '../monorepoPaths'
import { universalSpawn } from '../utils/childProcessUtils'
import { addChildProcess } from './gulpRegistry'
import semver from 'semver'

type Env = typeof process.env

export function webpackRunner () {
return runWebpack({
Expand All @@ -16,10 +19,27 @@ type RunWebpackCfg = {
cwd: string
prefix: string
args?: string[]
env?: object
env?: Env
devServer?: boolean
}

// https://github.com/cypress-io/cypress/issues/18914
// Node 17+ ships with OpenSSL 3 by default, so we may need the option
// --openssl-legacy-provider so that webpack@4 can use the legacy MD4 hash
// function. This option doesn't exist on Node <17 or when it is built
// against OpenSSL 1, so we have to detect Node's major version and check
// which version of OpenSSL it was built against before spawning the process.
//
// Can be removed once the webpack version is upgraded to >= 5.61,
// which no longer relies on Node's builtin crypto.hash function.
function useLegacyOpenSSLProvider (env: Env) {
if (process.versions && semver.satisfies(process.versions.node, '>=17.0.0') && semver.satisfies(process.versions.openssl, '>=3', { includePrerelease: true })) {
return { NODE_OPTIONS: `${env.NODE_OPTIONS ?? ''} --openssl-legacy-provider` }
}

return {}
}

export async function runWebpack (cfg: RunWebpackCfg) {
const { cwd, args = [], env = process.env, devServer = false, prefix } = cfg
const dfd = pDefer()
Expand All @@ -32,6 +52,7 @@ export async function runWebpack (cfg: RunWebpackCfg) {
cwd,
env: {
...(env || process.env),
...useLegacyOpenSSLProvider(env),
FORCE_COLOR: '1',
},
},
Expand Down
23 changes: 23 additions & 0 deletions scripts/run-webpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const cp = require('child_process')
const path = require('path')
const semver = require('semver')

const webpackCli = path.join(__dirname, '..', 'node_modules', 'webpack-cli', 'bin', 'cli.js')

// https://github.com/cypress-io/cypress/issues/18914
// Node 17+ ships with OpenSSL 3 by default, so we may need the option
// --openssl-legacy-provider so that webpack@4 can use the legacy MD4 hash
// function. This option doesn't exist on Node <17 or when it is built
// against OpenSSL 1, so we have to detect Node's major version and check
// which version of OpenSSL it was built against before spawning the process.
//
// Can be removed once the webpack version is upgraded to >= 5.61,
// which no longer relies on Node's builtin crypto.hash function.

let NODE_OPTIONS = process.env.NODE_OPTIONS || ''

if (process.versions && semver.satisfies(process.versions.node, '>=17.0.0') && semver.satisfies(process.versions.openssl, '>=3', { includePrerelease: true })) {
NODE_OPTIONS = `${NODE_OPTIONS} --openssl-legacy-provider`
}

cp.execSync(`node ${webpackCli} ${process.argv.slice(2).join(' ')}`, { stdio: 'inherit', env: { ...process.env, NODE_OPTIONS } })
1 change: 1 addition & 0 deletions system-tests/lib/system-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ const systemTests = {
const args = options.withBinary ? [
`run`,
`--project=${projectPath}`,
options.testingType === 'component' ? '--component' : '--e2e',
] : [
require.resolve('@packages/server'),
// hides a user warning to go through NPM module
Expand Down
9 changes: 9 additions & 0 deletions system-tests/test-binary/node_versions_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ function smokeTestDockerImage (dockerImage: string) {
specDir: 'tests',
project: 'todos',
})

systemTests.it(`can run in ${dockerImage}`, {
Copy link
Contributor

Choose a reason for hiding this comment

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

clean up the hierarchy of tests here? right now it's:

e2e binary node versions > can run in ${dockerImage}
e2e binary node versions > can run in ${dockerImage}

but something like this would be better:

binary node versions > ct > can run in ${dockerImage}
binary node versions > e2e > can run in ${dockerImage}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, addressed in 0654882

withBinary: true,
browser: 'electron',
dockerImage,
testingType: 'component',
project: 'simple-ct',
spec: 'src/simple_passing_component.cy.js',
})
}

describe('e2e binary node versions', () => {
Expand Down
90 changes: 21 additions & 69 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16445,15 +16445,6 @@ engine.io@~5.0.0:
engine.io-parser "~4.0.0"
ws "~7.4.2"

enhanced-resolve@4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.1.0.tgz#41c7e0bfdfe74ac1ffe1e57ad6a5c6c9f3742a7f"
integrity sha512-F/7vkyTtyc/llOIn8oWclcB25KdRaiPBpZYDgJHgh/UHtpgT2p2eldQgtQnLtUvfMKPKxbRaQM/hHkvLHt1Vng==
dependencies:
graceful-fs "^4.1.2"
memory-fs "^0.4.0"
tapable "^1.0.0"

enhanced-resolve@5.7.0:
version "5.7.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.7.0.tgz#525c5d856680fbd5052de453ac83e32049958b5c"
Expand Down Expand Up @@ -18522,16 +18513,6 @@ find-yarn-workspace-root@^2.0.0:
dependencies:
micromatch "^4.0.2"

findup-sync@3.0.0, findup-sync@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-3.0.0.tgz#17b108f9ee512dfb7a5c7f3c8b27ea9e1a9c08d1"
integrity sha512-YbffarhcicEhOrm4CtrwdKBdCuz576RLdhJDsIfvNtxUuhdRet1qZcsMjqbePtAseKdAnDyM/IyXbu7PRPRLYg==
dependencies:
detect-file "^1.0.0"
is-glob "^4.0.0"
micromatch "^3.0.4"
resolve-dir "^1.0.1"

findup-sync@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-2.0.0.tgz#9326b1488c22d1a6088650a86901b2d9a90a2cbc"
Expand All @@ -18542,6 +18523,16 @@ findup-sync@^2.0.0:
micromatch "^3.0.4"
resolve-dir "^1.0.1"

findup-sync@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-3.0.0.tgz#17b108f9ee512dfb7a5c7f3c8b27ea9e1a9c08d1"
integrity sha512-YbffarhcicEhOrm4CtrwdKBdCuz576RLdhJDsIfvNtxUuhdRet1qZcsMjqbePtAseKdAnDyM/IyXbu7PRPRLYg==
dependencies:
detect-file "^1.0.0"
is-glob "^4.0.0"
micromatch "^3.0.4"
resolve-dir "^1.0.1"

fined@^1.0.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/fined/-/fined-1.2.0.tgz#d00beccf1aa2b475d16d423b0238b713a2c4a37b"
Expand Down Expand Up @@ -21111,7 +21102,7 @@ import-lazy@^2.1.0:
resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43"
integrity sha1-BWmOPUXIjo1+nZLLBYTnfwlvPkM=

import-local@2.0.0, import-local@^2.0.0:
import-local@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/import-local/-/import-local-2.0.0.tgz#55070be38a5993cf18ef6db7e961f5bee5c5a09d"
integrity sha512-b6s04m3O+s3CGSbqDIyP4R6aAwAeYlVq9+WUWep6iHa8ETRf9yei1U48C5MmfJmV9AiLYYBKPMq/W+/WRpQmCQ==
Expand Down Expand Up @@ -21376,11 +21367,6 @@ internal-slot@^1.0.3:
has "^1.0.3"
side-channel "^1.0.4"

interpret@1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.2.0.tgz#d5061a6224be58e8083985f5014d844359576296"
integrity sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==

interpret@^1.0.0, interpret@^1.1.0, interpret@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
Expand Down Expand Up @@ -25353,7 +25339,7 @@ memfs@^3.4.1:
dependencies:
fs-monkey "1.0.3"

memory-fs@^0.4.0, memory-fs@^0.4.1:
memory-fs@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552"
integrity sha1-OpoguEYlI+RHz7x+i7gO1me/xVI=
Expand Down Expand Up @@ -35087,13 +35073,6 @@ supports-color@6.0.0:
dependencies:
has-flag "^3.0.0"

supports-color@6.1.0, supports-color@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3"
integrity sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==
dependencies:
has-flag "^3.0.0"

supports-color@8.1.1, supports-color@^8.0.0, supports-color@^8.1.0, supports-color@^8.1.1:
version "8.1.1"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c"
Expand All @@ -35113,6 +35092,13 @@ supports-color@^5.3.0, supports-color@^5.4.0, supports-color@^5.5.0:
dependencies:
has-flag "^3.0.0"

supports-color@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3"
integrity sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==
dependencies:
has-flag "^3.0.0"

supports-color@^7.0.0, supports-color@^7.1.0, supports-color@^7.2.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da"
Expand Down Expand Up @@ -37066,7 +37052,7 @@ v8-compile-cache-lib@^3.0.0:
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz#0582bcb1c74f3a2ee46487ceecf372e46bce53e8"
integrity sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA==

v8-compile-cache@2.0.3, v8-compile-cache@^2.0.2, v8-compile-cache@^2.0.3:
v8-compile-cache@^2.0.2, v8-compile-cache@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.0.3.tgz#00f7494d2ae2b688cfe2899df6ed2c54bef91dbe"
integrity sha512-CNmdbwQMBjwr9Gsmohvm0pbL954tJrNzf6gWL3K+QMQf00PF7ERGrEiLgjuU3mKreLC2MeGhUsNV9ybTbLgd3w==
Expand Down Expand Up @@ -37746,23 +37732,6 @@ webidl-conversions@^4.0.2:
watchpack "^1.7.4"
webpack-sources "^1.4.1"

webpack-cli@3.3.11:
version "3.3.11"
resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.3.11.tgz#3bf21889bf597b5d82c38f215135a411edfdc631"
integrity sha512-dXlfuml7xvAFwYUPsrtQAA9e4DOe58gnzSxhgrO/ZM/gyXTBowrsYeubyN4mqGhYdpXMFNyQ6emjJS9M7OBd4g==
dependencies:
chalk "2.4.2"
cross-spawn "6.0.5"
enhanced-resolve "4.1.0"
findup-sync "3.0.0"
global-modules "2.0.0"
import-local "2.0.0"
interpret "1.2.0"
loader-utils "1.2.3"
supports-color "6.1.0"
v8-compile-cache "2.0.3"
yargs "13.2.4"

webpack-cli@3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.3.2.tgz#aed2437b0db0a7faa2ad28484e166a5360014a91"
Expand Down Expand Up @@ -38977,7 +38946,7 @@ yargs-parser@13.1.1:
camelcase "^5.0.0"
decamelize "^1.2.0"

yargs-parser@13.1.2, yargs-parser@^13.1.0, yargs-parser@^13.1.1, yargs-parser@^13.1.2:
yargs-parser@13.1.2, yargs-parser@^13.1.1, yargs-parser@^13.1.2:
version "13.1.2"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.2.tgz#130f09702ebaeef2650d54ce6e3e5706f7a4fb38"
integrity sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg==
Expand Down Expand Up @@ -39092,23 +39061,6 @@ yargs@12.0.2:
y18n "^3.2.1 || ^4.0.0"
yargs-parser "^10.1.0"

yargs@13.2.4:
version "13.2.4"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.2.4.tgz#0b562b794016eb9651b98bd37acf364aa5d6dc83"
integrity sha512-HG/DWAJa1PAnHT9JAhNa8AbAv3FPaiLzioSjCcmuXXhP8MlpHO5vwls4g4j6n30Z74GVQj8Xa62dWVx1QCGklg==
dependencies:
cliui "^5.0.0"
find-up "^3.0.0"
get-caller-file "^2.0.1"
os-locale "^3.1.0"
require-directory "^2.1.1"
require-main-filename "^2.0.0"
set-blocking "^2.0.0"
string-width "^3.0.0"
which-module "^2.0.0"
y18n "^4.0.0"
yargs-parser "^13.1.0"

yargs@13.3.0:
version "13.3.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.3.0.tgz#4c657a55e07e5f2cf947f8a366567c04a0dedc83"
Expand Down