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 2 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
2 changes: 1 addition & 1 deletion packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"main": "index.js",
"scripts": {
"build": "gulp build",
"build": "cross-env NODE_OPTIONS=\"$(node ../../scripts/use-legacy-openssl.js)\" gulp build",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work in Windows? IDK how the command substitution is handled cross-platform

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 point I'll give it a test!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't work on Windows, changed to running webpack in a child process so the env variables could be manipulated more easily

"build-prod": "yarn build",
"clean": "gulp clean",
"clean-deps": "rimraf node_modules",
Expand Down
2 changes: 1 addition & 1 deletion packages/runner-ct/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": "cross-env NODE_OPTIONS=\"$(node ../../scripts/use-legacy-openssl.js)\" 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 .",
Expand Down
2 changes: 1 addition & 1 deletion 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": "cross-env NODE_OPTIONS=\"$(node ../../scripts/use-legacy-openssl.js)\" webpack",
"build-prod": "cross-env NODE_ENV=production yarn build",
"clean-deps": "rimraf node_modules",
"cypress:open": "node ../../scripts/cypress open",
Expand Down
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
20 changes: 20 additions & 0 deletions scripts/use-legacy-openssl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.

const semver = require('semver')

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

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

// eslint-disable-next-line no-console
console.log(opts)
ZachJW34 marked this conversation as resolved.
Show resolved Hide resolved