Skip to content

Commit

Permalink
fix: ct testing support for node 17+ (#21430)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachJW34 committed May 13, 2022
1 parent d45c9f8 commit 0f786ab
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 95 deletions.
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',
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
29 changes: 21 additions & 8 deletions system-tests/test-binary/node_versions_spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import systemTests from '../lib/system-tests'

function smokeTestDockerImage (dockerImage: string) {
systemTests.it(`can run in ${dockerImage}`, {
withBinary: true,
browser: 'electron',
dockerImage,
spec: 'test1.js',
specDir: 'tests',
project: 'todos',
context('e2e', () => {
systemTests.it(`can run in ${dockerImage}`, {
withBinary: true,
browser: 'electron',
dockerImage,
spec: 'test1.js',
specDir: 'tests',
project: 'todos',
})
})

context('component', () => {
systemTests.it(`can run in ${dockerImage}`, {
withBinary: true,
browser: 'electron',
dockerImage,
testingType: 'component',
project: 'simple-ct',
spec: 'src/simple_passing_component.cy.js',
})
})
}

describe('e2e binary node versions', () => {
describe('binary node versions', () => {
[
'cypress/base:12',
'cypress/base:14',
Expand Down

3 comments on commit 0f786ab

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0f786ab May 13, 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/10.0.0/linux-x64/10.0-release-0f786ab893d178c2f87eed6a1334a248c6bec7a6/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0f786ab May 13, 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/10.0.0/darwin-x64/10.0-release-0f786ab893d178c2f87eed6a1334a248c6bec7a6/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0f786ab May 13, 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/10.0.0/win32-x64/10.0-release-0f786ab893d178c2f87eed6a1334a248c6bec7a6/cypress.tgz

Please sign in to comment.