-
Notifications
You must be signed in to change notification settings - Fork 507
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
Support Testing with imports of JS files in ESM #187
Comments
gd qtn. i honestly have no idea. should we recommend that test files are also in typescript? that would be another angle to this. |
Our tests are written in typescript and work fine, until we try to import another package of ours from the NPM registry, which is compiled to ES6. Then Jest complains about that test, with the error above. It still runs other tests that don't import packages in ES6. I'm assuming this is a common enough issue, maybe it's not 🤔 |
Very possible, due to the design goals of tsdx, this doesn’t surprise me. Have you tried setting the allowJs flag in tsconfig to true? |
Sorry I may have misread, tsdx is not compiling node_modules at the moment with babel (like CRA does) IIRC. We might want to fix that. |
What would you recommend as a workaround for now, should we add this to the docs? |
Thanks for the quick replies both, btw! |
I don't think we'd want to compile all our node_modules, just ones that are imported into tests, is that possible I wonder? What would be the best practice for resolving this with TSDX? |
Yeah this one is really biting me currently,as the library that I develop wraps up an es6 module so none of my tests work. If anyone has any hints for how to get this working that would be great. |
A quite common case: I use lodash-es in my project, so the test just boomed. |
So this was fixed by my #486 very recently. Though if you want to transpile something from |
I am seeing what I believe is a similar issue that I could use some guidance with. I described it in some detail on Stack Overflow. The bottom line is that I am importing the Chakra This happens whether I'm sure this is a simple matter of configuration, but I've been spinning my wheels for days now trying to figure it out. Any guidance is appreciated. |
@neilchaudhuri TypeScript doesn't use file extensions, so I'd try removing the |
@agilgur5 Thanks for the suggestion. That is how I had it initially, but one of the error messages I got along the way prompted me to be more explicit. In all cases I get the same error. I should note also importing |
This is not true:
|
I don't believe this is fixed yet and this should be reopened. Using the latest Repo: https://github.com/karlhorky/tsdx-test-esm-fail
|
Maybe one option for fixing this would be to add the module.exports = {
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\](?!aggregate-error|clean-stack|escape-string-regexp|indent-string|p-map).+\\.(js|jsx)$',
],
}; It doesn't seem possible right now using a |
Currently ESM support for |
Oh, it seems a https://github.com/karlhorky/tsdx-test-esm-fail/pull/1/files Opened a PR to document this: #1019 |
I guess |
Hi, Any solution to this problem? I'm going through the same situation. I have a third-party file in my project that internally imports two libs in js and when I run the test I get this error: Jest encountered an unexpected token
I solved it using @karlhorky suggestion documented in pr #1019, but I would like to know if this problem will be solved. |
Current Behavior
When running test files with that contain ES6 module imports with Jest, I get the following error:
Is there an existing recommendation for handling ES6/ESNext module imports, if so, could we add documentation around this? If it doesn't exist, could we add recommendation on how to handle it? I'm happy to help if I can. Could this be a TSDX feature, to switch on and off?
Desired Behavior
Either handled by default by TSDX, or there is clear recommendations on how best to handle this.
Suggested Solution
Happy to add docs with the recommendation to resolve, although I'm not sure what the recommendations are as yet.
Who does this impact? Who is this for?
Users importing other packages that use ES6.
Describe alternatives you've considered
I considered using babel-jest and configuring it myself, but this seems to make TSDX a little redundant.
The text was updated successfully, but these errors were encountered: