Skip to content

Commit 322cc0d

Browse files
committed
add test
1 parent 0c190a2 commit 322cc0d

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

.circleci/workflows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ macWorkflowFilters: &darwin-workflow-filters
4242
- equal: [ develop, << pipeline.git.branch >> ]
4343
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
4444
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
45-
- equal: [ 'chore/update_reporter_mobx', << pipeline.git.branch >> ]
45+
- equal: [ 'ryanm/experiment/esm', << pipeline.git.branch >> ]
4646
- matches:
4747
pattern: /^release\/\d+\.\d+\.\d+$/
4848
value: << pipeline.git.branch >>

packages/data-context/test/unit/data/ProjectConfigIpc.spec.ts

+19-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import childProcess from 'child_process'
22
import { expect } from 'chai'
3+
import semver from 'semver'
34
import sinon from 'sinon'
45
import { scaffoldMigrationProject as scaffoldProject } from '../helper'
56
import { ProjectConfigIpc } from '../../../src/data/ProjectConfigIpc'
@@ -34,8 +35,11 @@ describe('ProjectConfigIpc', () => {
3435
})
3536

3637
context('forkChildProcess', () => {
37-
const NODE_VERSIONS = ['18.20.4', '20.17.0']
38-
const NODE_VERSIONS_22_7_0_AND_UP = ['22.7.0', '22.11.4']
38+
// some of these node versions may not exist, but we want to verify
39+
// the experimental flags are correctly disabled for future versions
40+
const NODE_VERSIONS = ['18.20.4', '20.17.0', '22.7.0', '22.11.4', '22.12.0', '22.15.0']
41+
const experimentalDetectModuleIntroduced = '22.7.0'
42+
const experimentalRequireModuleIntroduced = '22.12.0'
3943

4044
let projectConfigIpc
4145
let forkSpy
@@ -52,10 +56,10 @@ describe('ProjectConfigIpc', () => {
5256
})
5357

5458
context('typescript', () => {
55-
[...NODE_VERSIONS, ...NODE_VERSIONS_22_7_0_AND_UP].forEach((nodeVersion) => {
59+
[...NODE_VERSIONS].forEach((nodeVersion) => {
5660
context(`node v${nodeVersion}`, () => {
5761
context('ESM', () => {
58-
it('uses the experimental module loader if ESM is being used with typescript', async () => {
62+
it('passes the correct experimental flags if ESM is being used with typescript', async () => {
5963
// @ts-expect-error
6064
const projectPath = await scaffoldProject('config-cjs-and-esm/config-with-ts-module')
6165

@@ -77,35 +81,23 @@ describe('ProjectConfigIpc', () => {
7781
NODE_OPTIONS: sinon.match('--experimental-specifier-resolution=node --loader'),
7882
},
7983
}))
80-
})
81-
82-
// @see https://github.com/cypress-io/cypress/issues/30084
83-
// at time of writing, 22.11.4 is a node version that does not exist. We are using this version to test the logic for future proofing.
84-
if (NODE_VERSIONS_22_7_0_AND_UP.includes(nodeVersion)) {
85-
it(`additionally adds --no-experimental-detect-module for node versions 22.7.0 and up if ESM is being used with typescript`, async () => {
86-
// @ts-expect-error
87-
const projectPath = await scaffoldProject('config-cjs-and-esm/config-with-ts-module')
88-
89-
const MOCK_NODE_PATH = `/Users/foo/.nvm/versions/node/v${nodeVersion}/bin/node`
90-
const MOCK_NODE_VERSION = nodeVersion
91-
92-
projectConfigIpc = new ProjectConfigIpc(
93-
MOCK_NODE_PATH,
94-
MOCK_NODE_VERSION,
95-
projectPath,
96-
'cypress.config.js',
97-
false,
98-
(error) => {},
99-
() => {},
100-
)
10184

85+
if (semver.gte(nodeVersion, experimentalDetectModuleIntroduced)) {
10286
expect(forkSpy).to.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({
10387
env: {
10488
NODE_OPTIONS: sinon.match('--no-experimental-detect-module'),
10589
},
10690
}))
107-
})
108-
}
91+
}
92+
93+
if (semver.gte(nodeVersion, experimentalRequireModuleIntroduced)) {
94+
expect(forkSpy).to.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({
95+
env: {
96+
NODE_OPTIONS: sinon.match('--no-experimental-require-module'),
97+
},
98+
}))
99+
}
100+
})
109101
})
110102

111103
context('CommonJS', () => {

0 commit comments

Comments
 (0)