-
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
Transformer.js must export a "process" function - jester v2.0.1 jest 27 #65
Comments
You have to use jest with es modules. Which brings its own challanges, especially with external dependencies |
Thanks for the reply @micschwarz . This is not written anywhere on the current readme - unless i'm going blind. I think this should be made clearer as its a pretty major change not to be mentioned at all in the current documentation. However, even after changing jest to use es modules as per the jest documentation I still get the same problem regarding the synchronous transformer. The jest documentation says to disable code transforms by passing transform: {} or otherwise configure your transformer to emit ESM. The current documentation instructs us to use
I am using typescript, and thus ts-jest, so I changed my preset to I can tell node is running in experimental mode as I get the warnings " ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time" in my console when executing. Here is my full jest setup following the jest suggestions to enable ESM - as I mentioned I also tested with the transform: {} shown above with the same results
|
Quick response: have a look over here #59 (comment) You need to tell ts-node to not transform your jest.config.ts config, which is really weird btw. |
TLDR: "ts-node": {
"moduleTypes": {
"jest.config.ts": "cjs"
},
"transpileOnly": true
} |
Is there any chance to get this running without experimental vm modules? Using experimental flags for professional projects is not that great. And jests automock does not work with esm.
Edit: |
Thanks guys but i'm not using a jest.config.ts file. My jest config is in my package.json..... Of course I could create one and move the config but I shouldn't be forced to. I',m also not using ts-node, just ts-jest. I feel like this project should not have switched to using ESM at this point. I was previously having the issue with import.meta not being supported - due to jest26 - which is why I upgraded but that issue only existed in one file so I was happy to mock it for testing. This new version seems like we are having to jump through all sorts of hoops and still failing. Plus as @micschwarz pointed out using experimental flags for production projects is not great. Working with Sveltekit has been awesome so far with the exception of testing support. I know Sveltekit is still pre 1.0 software so its going to have gaps and issues but getting this setup is by far the biggest problem so far. |
Yes, the switch to esm was more problematic then we thought. We are going to change the versioning again and offer ESM support in a version next. We will support async and commonjs with version 2.x. See #61 Nevertheless, esm support is not happening without the experimental flag. This is also enforced by jest itself. You can have the same config in your package.json. Also, ts-Node is implicit, if you use typescript and jest. |
@sebastianrothe thanks for the info. I'm fairly new to typescript so didn't realize ts-node was implicit. I think offering a next version for testing ESM is a good move. Do you have a timeframe as to when the next release will come that will revert back to the old CJS way but with support for jest 27? Just wondering if I should revert back to jest 26 the old 1.x version for the time being if its going to take a while? Thanks again for the support |
I'll try to find some time next week. |
@kevpye-fabdata have you tried
That works for me with Jest 27. |
I tested this and it gives me several warnings on install - which is not surprising as the dependency versions do not match between this and ts-jest
But it does seem to work when I run my tests so I will leave it for now and update this once the next version is out. As the 2.x version that @sebastianrothe is going to try and work on this week will revert back to CJS I still had to go back to mocking my app settings file that uses the import meta syntax as it seems that is only supported for ESM imports with jest without doing some other trickery with babel. For me it was much simpler to simply mock my settings file using a setuptests file and adding it setupFilesAfterEnv setting in package.json. |
I resolved this issue by downgrading svelte-jester to 1.8.2 and added jsdom. |
It seems that the newest version of the svelte-jester is not compatible with jest library for the lack of process function, by degrading svelte-jester and adding jsdom, everything will works fine. @GHesericsu Thank you for the suggestion. |
Downgrading to |
2.1.0 is out now with the CJS build. Is this fixed as a result? |
perhaps there are some incompatible apis between the versions. |
Hey what's happening? I upgraded to 2.1.0 from the 2.0.something which threw that weird process error. Yet now I get even more serious looking error:
Going into the
Yet inside the folder there is only |
I haven't had a chance to test 2.1.0 yet in my project. I will try to look at it early next week and will report if I see the same problem as @TeemuKoivisto |
Doh! Thanks for pointing that out. That should have been updated. PR here: #69. If you change the |
@benmccann Hey, good to hear. Updating the paths to dist fixes it but it still throws the process error.
I wonder what's up with that. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hmm. It looks like you can't use Maybe transpiling isn't the way to go then and we'd be better off including two separate code bases for CJS and for ESM where CJS uses |
Not sure if it's a problem with CJS per se. I am importing the mjs file and removed my commonjs plugin as well as changed the module in my tsconfig to es2020 to no avail. It just seems that Jest it not playing well with the async processing. Granted this whole thing is quite messy so I'm not sure exactly what causes what. Having sync version in the cjs file would seem reasonable as otherwise I'm forced to downgrade 👍. |
@TeemuKoivisto would you be able to share a reproduction? |
2.1.1 is out now which fixes the file paths in |
Ahh. Well. I must say I can't put too much effort into this but here's a library https://github.com/teemukoivisto/svelte-tree-view I've been working on and just made public. It's kinda ready just missing tests, hence I'm here posting. So to reproduce what I've been doing you'd have to clone it, then After that, go to Anyway, don't know much else. I'll use the 1.8 version for now and make some tests. |
Hi there, I'm relatively new to svelte, and I've been running head-first into this problem for the past couple of days. If you want to reproduce this error, one way is to make a new scaffolded svelte app with TS support according to the svelte pages, then to follow this tutorial: (https://web.archive.org/web/20210127075453/https://timdeschryver.dev/blog/how-to-test-svelte-components). I've archived it just in case the author edits. The tutorial doesn't suggest specific versions of any library, but rather the latest. |
@benmccann > 2.1.1 is out now which fixes the file paths in I still got the same error :( |
Here's instructions to make it work in ESM mode: rossyman/svelte-add-jest#19 (comment) |
Hello you all, In the Jest documentation (to write custom transformers) it is stated that (quote) "...As can be seen, only process is mandatory to implement..." read here in jestdoc Also looking at the typescript decl (same page), it is the only mandatory member function in PS: in interface interface SyncTransformer<OptionType = unknown> {
canInstrument?: boolean; //OPTIONAL
createTransformer?: (options?: OptionType) => SyncTransformer<OptionType>; //OPTIONAL
getCacheKey?: ... //OPTIONAL
getCacheKeyAsync?: ... //OPTIONAL
process: ( //MANDATORY
sourceText: string,
sourcePath: Config.Path,
options: TransformOptions<OptionType>,
) => TransformedSource;
processAsync?... //(OPTIONAL)
} |
|
Looks like the 2.1.2 change may have a regression: #74. |
Hey guys,
I just updated to the new jester version - 2.0.1 and jest 27 and all tests are now failing with the following error:
Here is a sample test - just rendering a static page
I'm running node LTS 14.17.0.
Any ideas?
Thanks
The text was updated successfully, but these errors were encountered: