1
1
import childProcess from 'child_process'
2
2
import { expect } from 'chai'
3
+ import semver from 'semver'
3
4
import sinon from 'sinon'
4
5
import { scaffoldMigrationProject as scaffoldProject } from '../helper'
5
6
import { ProjectConfigIpc } from '../../../src/data/ProjectConfigIpc'
@@ -34,8 +35,11 @@ describe('ProjectConfigIpc', () => {
34
35
} )
35
36
36
37
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'
39
43
40
44
let projectConfigIpc
41
45
let forkSpy
@@ -52,10 +56,10 @@ describe('ProjectConfigIpc', () => {
52
56
} )
53
57
54
58
context ( 'typescript' , ( ) => {
55
- [ ...NODE_VERSIONS , ... NODE_VERSIONS_22_7_0_AND_UP ] . forEach ( ( nodeVersion ) => {
59
+ [ ...NODE_VERSIONS ] . forEach ( ( nodeVersion ) => {
56
60
context ( `node v${ nodeVersion } ` , ( ) => {
57
61
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 ( ) => {
59
63
// @ts -expect-error
60
64
const projectPath = await scaffoldProject ( 'config-cjs-and-esm/config-with-ts-module' )
61
65
@@ -77,35 +81,23 @@ describe('ProjectConfigIpc', () => {
77
81
NODE_OPTIONS : sinon . match ( '--experimental-specifier-resolution=node --loader' ) ,
78
82
} ,
79
83
} ) )
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
- )
101
84
85
+ if ( semver . gte ( nodeVersion , experimentalDetectModuleIntroduced ) ) {
102
86
expect ( forkSpy ) . to . have . been . calledWith ( sinon . match . string , sinon . match . array , sinon . match ( {
103
87
env : {
104
88
NODE_OPTIONS : sinon . match ( '--no-experimental-detect-module' ) ,
105
89
} ,
106
90
} ) )
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
+ } )
109
101
} )
110
102
111
103
context ( 'CommonJS' , ( ) => {
0 commit comments