jestjs/jest

[Feature]: Allow using tsx instead of ts-node for loading TS config files

Open

#13,143 建立於 2022年8月16日

在 GitHub 查看
 (28 留言) (81 反應) (0 負責人)TypeScript (45,361 star) (6,653 fork)batch import
:rocket: Feature RequestHelp WantedPinned

描述

🚀 Feature Proposal

I would like to be able to use the tsx compiler for handling the jest.config.ts file, as opposed to relying on ts-node.

Motivation

tsx is a quickly rising alternative to ts-node as it runs much faster as it runs on the back of esbuild, and doesn't do typechecking. While parsing the jest configuration file should already be generally quick, it could be made quicker to using tsx. Additionally, for teams that have moved to tsx, it would allow having just one runtime compiler in their dependency for everything, vs having tsx for most things, and ts-node just for reading jest.config.ts files.

Example

It would be used implicitly within jest-config library where when it detects a file that ends with .ts, it checks if ts-node is available and uses that, else it'll check for tsx and use that. If neither are available output an error message that neither could be found.

All the user would need to do would be to have tsx installed via their package manager and available via node_modules.

Pitch

Looking at https://github.com/facebook/jest/blob/main/packages/jest-config/src/readConfigFileAndSetRootDir.ts, there didn't seem to be an obvious way to modify the behavior of how it loads config files, where even if it was possible to get tsx registered before triggering jest-config, it would still attempt to use ts-node for .ts extension.

貢獻者指南