tsdx
tsdx copied to clipboard
Support `jest.config.(cjs|mjs|ts)` as a Jest configuration file for packages written in ESM
Current Behavior
If a package is written in ESM, the only way to configure Jest is via the "jest" field in the package.json file.
Desired Behavior
It would be nice to also be able to use the standard jest.config.(cjs|mjs|ts) files.
Suggested Solution
Read from the jest.config.cjs file (and any other config files that Jest resolves, such as jest.config.mjs and jest.config.ts)
Who does this impact? Who is this for?
TSDX users who would like to write their Jest config in the standard ways.
Describe alternatives you've considered
Don't do anything
Additional context
https://github.com/formium/tsdx/issues/187
Known issue, trust me when I say if it were easy, I would have supported it a long time ago. Can see https://github.com/jaredpalmer/tsdx/pull/526#pullrequestreview-371516104 where I lament about Jest's lack of programmatic API. https://github.com/facebook/jest/issues/5048 is still open and due to this TSDX had to implement custom parsing code for Jest configs.
Could support CJS with a few LoC as it's just another filename, but would have to detect it. MJS could potentially be possible in a similar manner once Node 10 is dropped (might be some compat issues there though).
TS is highly non-trivial without a Jest API exposed. Jest's own code basically checks if it's a TS file, then checks if you have ts-node installed, then uses ts-node to load the file. That also adds another big dep on top of that complexity and changing up the loader chain and TS versioning etc. Similar thing for say tsdx.config.ts -- it adds quite a bit of complexity for such a small feature
#187
That issue is unrelated to reading jest.config files