-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
[Feature] Add jest transformer wrapper #142
Comments
Thanks for the suggestion! I had a look, and it looks like it may be possible via https://kulshekhar.github.io/ts-jest/docs/getting-started/options/astTransformers I'll have to think on this one for a bit. Since |
Interesting, I did not know about https://kulshekhar.github.io/ts-jest/docs/getting-started/options/astTransformers/#public-transformers. I'll give this a shot and report back. If this works, I still think a mention in the docs would be worthwhile. People using this tool will want it working in Jest, and it's just not obvious how to do that at first. Brief one-liner integration tips here go a long way. If they get out of date, community usually notices and hopefully opens a PR. |
Hmmmm It seems that it works by default, just like this: import type { InitialOptionsTsJest } from 'ts-jest/dist/types'
const config: InitialOptionsTsJest = {
preset: 'ts-jest',
globals: {
'ts-jest': {
diagnostics: Boolean(process.env.CI),
},
},
}
export default config |
Appreciate the update! It occurred to me that it should, but the docs made it seem like they were using babel instead of typescript for compilation. Glad it works! |
Update It seems I was wrong, this is what is needed. Maybe I encountered a cache issue on my end, thinking the reduced code worked when actually it was running the previous. import type { InitialOptionsTsJest } from 'ts-jest/dist/types'
const config: InitialOptionsTsJest = {
preset: 'ts-jest',
globals: {
'ts-jest': {
astTransformers: {
before: ['ts-jest/dist/transformers/path-mapping'],
},
},
},
}
export default config |
Ah ok. Looks like it is using the TS compiler API. Also... The code looks oddly familiar. 😅 Regarding your request, I think there is some value to natively supporting jest. This is particularly going to be important because Along with that, we're adding full esm support. Lots of crazy gotchas involved in importing from packages with With that in mind, we've been adding custom loaders and register scripts for node, node with esm, ts-node, etc. I'm going to go ahead and add a jest wrapper to the Ultimately, config will likely end up looking like this:
|
Any update on this one? 🤔 Or is there any tutorial how I can make Whatever I do ts-jest still can't resolve my modules. Also |
Interesting! Didn't know that.
A few days ago, I had to set a solution up, and I opted to use their AST transformer. It did work. The one problem is it make it so I can't use Realistically, the best way to make sure it works is to use ts-patch. When you do, you can simply add the plugin config to a All the wrappers and loaders could be avoided if people did, but in effort to broaden support for people who prefer not to add another tool, I'm adding the extras as I'm able. Unfortunately, I've been swamped lately. I do hope to finish this when things slow down in the next major release. In the mean time, I hope that helps! |
Yes, but unfortunately they just link and don't provide any explanation or example, which is really a pity..
Would you mind sharing your solution? I don't mind if I currently can't debug, as long as ts-jest is able to resolve the paths properly.
Do you have a concrete example how Edit: I think I found a working solution for me leveraging tsconfig-paths |
@pz-uc I should probably clarify the readme. There is one "official" way of using this library and there are now several alternatives, if you really don't want to use the official route. Here are the steps:
It's as simple as that. If your typescript is patched, it will work.
I actually used to recommend using Would you mind sharing how you got it to work with jest? |
Currently the best way I know how but happy to simplify:
https://github.com/jasonkuhrt/template-typescript-lib/blob/main/jest.config.ts
The text was updated successfully, but these errors were encountered: