Skip to content

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

Merged
SimenB merged 13 commits into
jestjs:mainfrom
phryneas:pr/use-node-feature-typescript
Jan 30, 2025
Merged

SimenB merged 13 commits into
jestjs:mainfrom
phryneas:pr/use-node-feature-typescript

Conversation

@phryneas

@phryneas phryneas commented Jan 28, 2025 •

Copy link
Copy Markdown
Contributor

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/client@3.12.7 /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
@netlify

netlify Bot commented Jan 28, 2025 •

Copy link
Copy Markdown

✅ 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

phryneas commented Jan 28, 2025 •

Copy link
Copy Markdown
Contributor Author

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

SimenB commented Jan 28, 2025 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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', () => {

@phryneas phryneas Jan 29, 2025 •

Copy link
Copy Markdown
Contributor Author

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.

Comment thread packages/jest-config/src/readConfigFileAndSetRootDir.ts Outdated
skipPkgJsonCheck: true,
},
);
onNodeVersions('<=23.6', () => {

Copy link
Copy Markdown
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.

'__tests__/mytest.common.js': "test('common', () => expect(1).toBe(1));",
'alpha.config.ts': `
import commonRegex from './common';
import commonRegex from './common${importFileExtension}';

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

@SimenB SimenB left a comment

Copy link
Copy Markdown
Member

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
@SimenB

SimenB commented Jan 30, 2025

Copy link
Copy Markdown
Member

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

@SimenB

SimenB commented Feb 9, 2025

Copy link
Copy Markdown
Member

Hmm, snapshot test seems to be failing on 23.7 😅

@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants