-
Notifications
You must be signed in to change notification settings - Fork 19
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
add jest+typescript test #155
Conversation
@cyberwombat would this type of test setup work for your tests? |
I should be able to use tsm - right now I use ts-jest transform. Ive never used tsm as a loader but happy to experiment. |
I did not know about ts-jest transform... I'm interested to change this PR to use the ts-jest transform |
Ya my jest.config.ts looks like this:
|
Actually, based on my admittedly limited understanding of jest... probably jest transform will not work. I think the ts transformation must occur through a --loader like tsm or ts-node. I can try to use the jest.config.ts provided but I don't believe I will succeed. |
I am not attached - I do want to be able to use TS files for my |
jest tries to use ts-node, so updating this PR to use ts-node rather than tsm seems like a good idea. when using the jest.config.ts, errors like these occur... Error: Jest: Failed to parse the TypeScript config file /home/bumble/software/esmock/tests/tests-jest-ts/jest.config.ts
Error: Must use import to load ES Module: /home/bumble/software/esmock/tests/tests-jest-ts/jest.config.ts
require() of ES modules is not supported.
require() of /home/bumble/software/esmock/tests/tests-jest-ts/jest.config.ts from /home/bumble/software/esmock/tests/tests-jest-ts/node_modules/jest-config/build/readConfigFileAndSetRootDir.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
Instead change the requiring code to use import(), or remove "type": "module" from /home/bumble/software/esmock/tests/tests-jest-ts/package.json. |
Hmm. I can't tell if its struggling with a TS config or just the ESM. I think the latter. What I did is have "type": "module" in my
|
Once think I wanted to avoid is doing all imports with 'js' extensions as that makes a total mess for jest/ts-jest. Also I had to play around to have VSCode Inteliisense play nice so these settings are the result of that. |
I haven't succeeded in replacing tsm with ts-jest :/ |
What about ts-node? From reading comments here and there it seems to have a better overall support w Jest and has native esm loader https://www.npmjs.com/package/ts-node |
when tsm is replaced with ts-node/esm, this happens when the tests run, FAIL ./esmock.node-jest.test.ts
● Test suite failed to run
thrown: Object {
"diagnosticCodes": Array [
2593,
2304,
],
} |
a ts-node/esm test folder with passing esmock tests is here https://github.com/iambumblehead/esmock/tree/master/tests/tests-nodets this error appears to occur specifically in combination with jest |
4241410
to
14b6253
Compare
@cyberwombat the ts-node/esm test at this PR is passing. If you have time and would provide the favor of trying to add something like your jest.config.ts file to the PR that would be awesome. If we can support that file, we should include that with the test. To use the esmock tests, from esmock's root folder |
let's merge this now, in order to update the wiki with links to this test-jest-ts folder. A separate PR could be used for any subsequent changes |
I am having no luck w |
ok thanks for helping me to this point |
Frankly the solution is probably to dump Jest. It's pretty outdated these days and they've expressed a lack of motivation in supporting ESM mocks. I'm exploring vitest to see if that has better options. It supports TS and ESM natively which is nice. Thank you for your effort |
I would be interested to know what you think of vitest, as there are many positive reviews |
@cyberwombat either "tsm" or "ts-node" could be used the same way here, but this PR uses --loader=tsm now.
re #154