-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Typescript config invalid with node v22.7.0 with ESM (#30099)
* add failing system binary test [run ci] * fix: leverage the --no-experimental-detect-module when node 22.7.0 and above is detected [run ci] * Update cli/CHANGELOG.md * use environment variable to mock stubbing out of typescript install in order to unit test as mocking the module seems near impossible to do correctly given the context [run ci] * update changelog to include mention of experimental-detect-module * make sure node version is set before comparing versions * Revert "update changelog to include mention of experimental-detect-module" This reverts commit 5ef8ef0. --------- Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
- Loading branch information
1 parent
0480480
commit 5a6b8c4
Showing
7 changed files
with
149 additions
and
19 deletions.
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
5a6b8c4
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.
Circle has built the
linux arm64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
5a6b8c4
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.
Circle has built the
linux x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
5a6b8c4
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.
Circle has built the
win32 x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
5a6b8c4
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.
Circle has built the
darwin x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
5a6b8c4
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.
Circle has built the
darwin arm64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally: