Skip to content

Commit

Permalink
fix: force moduleResolution: 'node' when ts-node is registered in the… (
Browse files Browse the repository at this point in the history
#28709)

* fix: force moduleResolution: 'node' when ts-node is registered in the cypress process to make sure value is compatible with commonjs (which is already forced). [run ci]

* Update cli/CHANGELOG.md
  • Loading branch information
AtofStryker committed Jan 16, 2024
1 parent 7df6df4 commit 81fce0e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 35 deletions.
12 changes: 5 additions & 7 deletions .circleci/workflows.yml
Expand Up @@ -29,7 +29,7 @@ mainBuildFilters: &mainBuildFilters
- develop
- /^release\/\d+\.\d+\.\d+$/
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- 'chore/update_aws_sdk'
- 'fix/set_module_resolution_with_commonjs'
- 'publish-binary'
- 'em/circle2'

Expand All @@ -42,7 +42,7 @@ macWorkflowFilters: &darwin-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'chore/update_aws_sdk', << pipeline.git.branch >> ]
- equal: [ 'fix/set_module_resolution_with_commonjs', << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/service-worker-capture', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
Expand All @@ -54,8 +54,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'chore/update_aws_sdk', << pipeline.git.branch >> ]
- equal: [ 'chore/update_webpack_deps_to_latest_webpack4_compat', << pipeline.git.branch >> ]
- equal: [ 'fix/set_module_resolution_with_commonjs', << pipeline.git.branch >> ]
- equal: [ 'em/circle2', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
Expand All @@ -79,8 +78,7 @@ windowsWorkflowFilters: &windows-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'chore/update_aws_sdk', << pipeline.git.branch >> ]
- equal: [ 'chore/update_windows_signing', << pipeline.git.branch >> ]
- equal: [ 'fix/set_module_resolution_with_commonjs', << pipeline.git.branch >> ]
- equal: [ 'lerna-optimize-tasks', << pipeline.git.branch >> ]
- equal: [ 'mschile/mochaEvents_win_sep', << pipeline.git.branch >> ]
- matches:
Expand Down Expand Up @@ -152,7 +150,7 @@ commands:
name: Set environment variable to determine whether or not to persist artifacts
command: |
echo "Setting SHOULD_PERSIST_ARTIFACTS variable"
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "publish-binary" && "$CIRCLE_BRANCH" != "chore/update_aws_sdk" ]]; then
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "publish-binary" && "$CIRCLE_BRANCH" != "fix/set_module_resolution_with_commonjs" ]]; then
export SHOULD_PERSIST_ARTIFACTS=true
fi' >> "$BASH_ENV"
# You must run `setup_should_persist_artifacts` command and be using bash before running this command
Expand Down
2 changes: 1 addition & 1 deletion cli/CHANGELOG.md
Expand Up @@ -4,7 +4,7 @@
_Released 1/16/2024 (PENDING)_

**Bugfixes:**

- Force `moduleResolution` to `node` when `typescript` projects are detected to correctly run Cypress. This change should not have a large impact as `commonjs` is already forced when `ts-node` is registered. This fix does not impact the ESM Typescript configuration loader. Fixes [#27731](https://github.com/cypress-io/cypress/issues/27731).
- No longer wait for additional frames when recording a video for a spec that was skipped by the Cloud due to Auto Cancellation. Fixes [#27898](https://github.com/cypress-io/cypress/issues/27898).
- Now `node_modules` will not be ignored if a project path or a provided path to spec files contains it. Fixes [#23616](https://github.com/cypress-io/cypress/issues/23616).
- Updated display of assertions and commands with a URL argument to escape markdown formatting so that values are displayed as is and assertion values display as bold. Fixes [#24960](https://github.com/cypress-io/cypress/issues/24960) and [#28100](https://github.com/cypress-io/cypress/issues/28100).
Expand Down
4 changes: 1 addition & 3 deletions packages/server/lib/plugins/child/ts_node.js
Expand Up @@ -23,6 +23,7 @@ const getTsNodeOptions = (tsPath, registeredFile) => {
*/
const compilerOptions = {
module: 'commonjs',
moduleResolution: 'node',
...(semver.satisfies(version, '>=4.5.0')
// Only adding this option for TS >= 4.5.0
? { preserveValueImports: false }
Expand All @@ -34,9 +35,6 @@ const getTsNodeOptions = (tsPath, registeredFile) => {

if (process.env.TS_NODE_COMPILER) {
try {
// @ts-expect-error - compilerOptions is an object we can assign properties on.
// It's the 'tsconfig.compilerOptions'.
compilerOptions.moduleResolution = 'node'
compiler = require.resolve(process.env.TS_NODE_COMPILER, { paths: [path.dirname(registeredFile)] })
} catch {
// ts-node compiler not installed in project directory
Expand Down
26 changes: 2 additions & 24 deletions packages/server/test/unit/plugins/child/ts_node_spec.js
Expand Up @@ -24,6 +24,7 @@ describe('lib/plugins/child/ts_node', () => {
dir: '/path/to/plugins',
compilerOptions: {
module: 'commonjs',
moduleResolution: 'node',
},
ignore: [
'(?:^|/)node_modules/',
Expand All @@ -38,35 +39,14 @@ describe('lib/plugins/child/ts_node', () => {
sinon.stub(typescriptObject, 'version').value('4.5.0')
tsNodeUtil.register('proj-root', '/path/to/plugins/file.js')

expect(tsnode.register).to.be.calledWith({
transpileOnly: true,
compiler: 'typescript/lib/typescript.js',
dir: '/path/to/plugins',
compilerOptions: {
module: 'commonjs',
preserveValueImports: false,
},
ignore: [
'(?:^|/)node_modules/',
'/packages/telemetry/dist/span-exporters/ipc-span-exporter',
'/packages/telemetry/dist/span-exporters/console-trace-link-exporter',
'/packages/telemetry/dist/processors/on-start-span-processor',
],
})
})

it('registers ts-node with commonjs and node moduleResolution when process.env.TS_NODE_COMPILER is set', () => {
process.env.TS_NODE_COMPILER = true
sinon.stub(typescriptObject, 'version').value('1.1.1')
tsNodeUtil.register('proj-root', '/path/to/plugins/file.js')

expect(tsnode.register).to.be.calledWith({
transpileOnly: true,
compiler: 'typescript/lib/typescript.js',
dir: '/path/to/plugins',
compilerOptions: {
module: 'commonjs',
moduleResolution: 'node',
preserveValueImports: false,
},
ignore: [
'(?:^|/)node_modules/',
Expand All @@ -75,8 +55,6 @@ describe('lib/plugins/child/ts_node', () => {
'/packages/telemetry/dist/processors/on-start-span-processor',
],
})

delete process.env.TS_NODE_COMPILER
})

it('does not register ts-node if typescript is not installed', () => {
Expand Down

5 comments on commit 81fce0e

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 81fce0e Jan 16, 2024

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:

npm install https://cdn.cypress.io/beta/npm/13.6.3/linux-arm64/develop-81fce0e2536d04a6ce426c015aafd85f46fcf46c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 81fce0e Jan 16, 2024

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:

npm install https://cdn.cypress.io/beta/npm/13.6.3/linux-x64/develop-81fce0e2536d04a6ce426c015aafd85f46fcf46c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 81fce0e Jan 16, 2024

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:

npm install https://cdn.cypress.io/beta/npm/13.6.3/darwin-x64/develop-81fce0e2536d04a6ce426c015aafd85f46fcf46c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 81fce0e Jan 16, 2024

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:

npm install https://cdn.cypress.io/beta/npm/13.6.3/darwin-arm64/develop-81fce0e2536d04a6ce426c015aafd85f46fcf46c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 81fce0e Jan 16, 2024

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:

npm install https://cdn.cypress.io/beta/npm/13.6.3/win32-x64/develop-81fce0e2536d04a6ce426c015aafd85f46fcf46c/cypress.tgz

Please sign in to comment.