-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: Typescript config invalid with node v22.7.0 with ESM #30099
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bd4b676
add failing system binary test [run ci]
AtofStryker 2c60737
fix: leverage the --no-experimental-detect-module when node 22.7.0 an…
AtofStryker aae89b3
Update cli/CHANGELOG.md
jennifer-shehane 36a265a
use environment variable to mock stubbing out of typescript install i…
AtofStryker 5ef8ef0
update changelog to include mention of experimental-detect-module
AtofStryker 864e6f0
make sure node version is set before comparing versions
AtofStryker ffbb93c
Revert "update changelog to include mention of experimental-detect-mo…
AtofStryker ef68373
Merge branch 'develop' of github.com:cypress-io/cypress into fix/node…
AtofStryker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 126 additions & 18 deletions
144
packages/data-context/test/unit/data/ProjectConfigIpc.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,140 @@ | ||
import childProcess from 'child_process' | ||
import { expect } from 'chai' | ||
import sinon from 'sinon' | ||
import { scaffoldMigrationProject as scaffoldProject } from '../helper' | ||
import { ProjectConfigIpc } from '../../../src/data/ProjectConfigIpc' | ||
|
||
describe('ProjectConfigIpc', () => { | ||
let projectConfigIpc | ||
|
||
beforeEach(async () => { | ||
const projectPath = await scaffoldProject('e2e') | ||
|
||
projectConfigIpc = new ProjectConfigIpc( | ||
undefined, | ||
projectPath, | ||
'cypress.config.js', | ||
false, | ||
(error) => {}, | ||
() => {}, | ||
) | ||
}) | ||
context('#eventProcessPid', () => { | ||
let projectConfigIpc | ||
|
||
afterEach(() => { | ||
projectConfigIpc.cleanupIpc() | ||
}) | ||
beforeEach(async () => { | ||
const projectPath = await scaffoldProject('e2e') | ||
|
||
projectConfigIpc = new ProjectConfigIpc( | ||
undefined, | ||
undefined, | ||
projectPath, | ||
'cypress.config.js', | ||
false, | ||
(error) => {}, | ||
() => {}, | ||
) | ||
}) | ||
|
||
afterEach(() => { | ||
projectConfigIpc.cleanupIpc() | ||
}) | ||
|
||
context('#eventProcessPid', () => { | ||
it('returns id for child process', () => { | ||
const expectedId = projectConfigIpc._childProcess.pid | ||
|
||
expect(projectConfigIpc.childProcessPid).to.eq(expectedId) | ||
}) | ||
}) | ||
|
||
context('forkChildProcess', () => { | ||
const NODE_VERSIONS = ['18.20.4', '20.17.0'] | ||
const NODE_VERSIONS_22_7_0_AND_UP = ['22.7.0', '22.11.4'] | ||
|
||
let projectConfigIpc | ||
let forkSpy | ||
|
||
beforeEach(() => { | ||
process.env.CYPRESS_INTERNAL_MOCK_TYPESCRIPT_INSTALL = 'true' | ||
forkSpy = sinon.spy(childProcess, 'fork') | ||
}) | ||
|
||
afterEach(() => { | ||
delete process.env.CYPRESS_INTERNAL_MOCK_TYPESCRIPT_INSTALL | ||
forkSpy.restore() | ||
projectConfigIpc.cleanupIpc() | ||
}) | ||
|
||
context('typescript', () => { | ||
[...NODE_VERSIONS, ...NODE_VERSIONS_22_7_0_AND_UP].forEach((nodeVersion) => { | ||
context(`node v${nodeVersion}`, () => { | ||
context('ESM', () => { | ||
it('uses the experimental module loader if ESM is being used with typescript', async () => { | ||
// @ts-expect-error | ||
const projectPath = await scaffoldProject('config-cjs-and-esm/config-with-ts-module') | ||
|
||
const MOCK_NODE_PATH = `/Users/foo/.nvm/versions/node/v${nodeVersion}/bin/node` | ||
const MOCK_NODE_VERSION = nodeVersion | ||
|
||
projectConfigIpc = new ProjectConfigIpc( | ||
MOCK_NODE_PATH, | ||
MOCK_NODE_VERSION, | ||
projectPath, | ||
'cypress.config.js', | ||
false, | ||
(error) => {}, | ||
() => {}, | ||
) | ||
|
||
expect(forkSpy).to.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({ | ||
env: { | ||
NODE_OPTIONS: sinon.match('--experimental-specifier-resolution=node --loader'), | ||
}, | ||
})) | ||
}) | ||
|
||
// @see /~https://github.com/cypress-io/cypress/issues/30084 | ||
// 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. | ||
if (NODE_VERSIONS_22_7_0_AND_UP.includes(nodeVersion)) { | ||
it(`additionally adds --no-experimental-detect-module for node versions 22.7.0 and up if ESM is being used with typescript`, async () => { | ||
// @ts-expect-error | ||
const projectPath = await scaffoldProject('config-cjs-and-esm/config-with-ts-module') | ||
|
||
const MOCK_NODE_PATH = `/Users/foo/.nvm/versions/node/v${nodeVersion}/bin/node` | ||
const MOCK_NODE_VERSION = nodeVersion | ||
|
||
projectConfigIpc = new ProjectConfigIpc( | ||
MOCK_NODE_PATH, | ||
MOCK_NODE_VERSION, | ||
projectPath, | ||
'cypress.config.js', | ||
false, | ||
(error) => {}, | ||
() => {}, | ||
) | ||
|
||
expect(forkSpy).to.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({ | ||
env: { | ||
NODE_OPTIONS: sinon.match('--no-experimental-detect-module'), | ||
}, | ||
})) | ||
}) | ||
} | ||
}) | ||
|
||
context('CommonJS', () => { | ||
it('uses the ts_node commonjs loader if CommonJS is being used with typescript', async () => { | ||
// @ts-expect-error | ||
const projectPath = await scaffoldProject('config-cjs-and-esm/config-with-module-resolution-bundler') | ||
|
||
const MOCK_NODE_PATH = `/Users/foo/.nvm/versions/node/v${nodeVersion}/bin/node` | ||
const MOCK_NODE_VERSION = nodeVersion | ||
|
||
projectConfigIpc = new ProjectConfigIpc( | ||
MOCK_NODE_PATH, | ||
MOCK_NODE_VERSION, | ||
projectPath, | ||
'cypress.config.js', | ||
false, | ||
(error) => {}, | ||
() => {}, | ||
) | ||
|
||
expect(forkSpy).to.have.been.calledWith(sinon.match.string, sinon.match.array, sinon.match({ | ||
env: { | ||
NODE_OPTIONS: sinon.match('--require'), | ||
}, | ||
})) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't figure out another way to test this. Not great, but at least gets us what we need