jest
jest copied to clipboard
[Feature]: Support loading jest.config.ts as ESM
🚀 Feature Proposal
- If
"type": "module"
is set in the package.json,jest.config.ts
should be treated as ESM, not CJS -
jest.config.mts
andjest.config.cts
should be looked for and loaded as ESM and CJS, respectively
Motivation
- This is currently the behavior with
jest.config.js
, and so ESM vs CJS handling differs between JS and TS configs - I would like to be able to import ESM libraries in my TS config
Example
No response
Pitch
- Config loading is handled by core
- Module behavior between JS and TS should match
Related: #11453
PR welcome! Logic for config file resolution and reading is in https://github.com/facebook/jest/blob/1919ef13df544a968bd2d32e5d7b8a2a1c4b35d1/packages/jest-config/src/readConfigFileAndSetRootDir.ts
That said, I don't think anything has changed since https://github.com/facebook/jest/issues/11453#issuecomment-1040424443 (i.e. you need a loader). But we should at least find cts
as that is supposed to be converted to cjs
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
@SimenB as a first step, maybe let's get support for jest.config.cts
, to avoid the extra ts-node.moduleTypes
config for ts-node
Took a quick shot at a PR - does it need anything else? (other than fixing the tests)
- https://github.com/facebook/jest/pull/14064
Edit: @DerTimonius opened a new PR based on mine, which also fixes the tests:
- https://github.com/facebook/jest/pull/14070
https://github.com/jestjs/jest/releases/tag/v30.0.0-alpha.3 for .cts
support