Skip to content
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

feat(config): if process.features.typescript is set, load jest.config.ts without external loader #15480

Merged
merged 13 commits into from
Jan 30, 2025

Conversation

phryneas
Copy link
Contributor

@phryneas phryneas commented Jan 28, 2025

Summary

see https://nodejs.org/api/process.html#processfeaturestypescript

This value is set if node is run with --experimental-transform-types or --experimental-strip-types (or you run an unflagged node version of >= 23.6) so no external package is required for transpilation in those cases

Test plan

I'm introducing this change with a patch-package patch via apollographql/apollo-client@795a432 (#12305) in apollographql/apollo-client#12305.

The tests still run fine despite ts-node not being installed and the config file being a .ts file.

proof for ts-node not being present:

% npm ls ts-node                                                                                                                                                                                                   pr/build-changes
@apollo/[email protected] /Users/tronic/tmp/apollo-client
└── (empty)

…t external loader

see https://nodejs.org/api/process.html#processfeaturestypescript
This value is set if node is run with `--experimental-transform-types` or `--experimental-strip-types` so no external package is required for transpilation in those cases
Copy link

netlify bot commented Jan 28, 2025

Deploy Preview for jestjs ready!

Name Link
🔨 Latest commit 924fa02
🔍 Latest deploy log https://app.netlify.com/sites/jestjs/deploys/679b37301843e9000839e082
😎 Deploy Preview https://deploy-preview-15480--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@phryneas
Copy link
Contributor Author

phryneas commented Jan 28, 2025

Looking at the tests running Node23+ this seems to run really well 😆

Should I just update the snapshots there or should some of those tests be skipped in node 23?

@SimenB
Copy link
Member

SimenB commented Jan 28, 2025

Exciting, thank you for the PR!

We should suppress the warning to avoid it cluttering the output in tests (

nodeOptions: '--experimental-vm-modules --no-warnings',
)

As for the syntax errors, it would be nice to update the error message for the "native" TS stripping. Might need 2 separate tests and use the onNodeVersions test helper?

const jestTypesExists = fs.existsSync(jestTypesPath);

(jestTypesExists ? test : test.skip).each([true, false])(
'check the config disabled (skip type check: %p)',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipping this test in new node versions since the node feature only transpiles and doesn't type check.

(jestTypesExists ? test : test.skip).each([true, false])(
'check the config disabled (skip type check: %p)',
skipTypeCheck => {
test('invalid JS in jest.config.ts', () => {
Copy link
Contributor Author

@phryneas phryneas Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is a bit weird here - this test is duplicated into a pre-23.6 and post-23.6 version now.

skipPkgJsonCheck: true,
},
);
onNodeVersions('<=23.6', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node resolution modes cannot be configured via tsconfig.json in modern node TS - it just uses modern node resolution by default.

This test fails anyways, because it requires transpilation to happen - the package.json contains type: "commonjs" and the jest.config.ts is written in ESM style.
That fails native node. It would work with type: "module", but we wouldn't really test what this test is about at this point - so I'm skipping it.

@@ -20,7 +24,7 @@ test('works with single typescript config that imports something', () => {
'__tests__/mytest.alpha.js': "test('alpha', () => expect(1).toBe(1));",
'__tests__/mytest.common.js': "test('common', () => expect(1).toBe(1));",
'alpha.config.ts': `
import commonRegex from './common';
import commonRegex from './common${importFileExtension}';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transpiled resolution is fine with './common', type-stripped node execution wants './common.ts'.

@phryneas
Copy link
Contributor Author

All tests green now if you want to take another look @SimenB :)

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonderful, thank you!

@SimenB SimenB merged commit d336118 into jestjs:main Jan 30, 2025
8 of 9 checks passed
@SimenB
Copy link
Member

SimenB commented Jan 30, 2025

https://github.com/jestjs/jest/releases/tag/v30.0.0-alpha.7

@SimenB
Copy link
Member

SimenB commented Feb 9, 2025

Hmm, snapshot test seems to be failing on 23.7 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants