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
Forced commonjs breaks synthetic default imports #146
Comments
@dphilipson If you have a suggestion that allows your requirements to be met without breaking the other parts, I'd be happy to help take this forward. |
Ah, I see, that's a good reason for doing so. Still, it would be nice to have the option to manually override if I don't care about coverage. Perhaps if |
@dphilipson the fix has been published. Can you see if the latest version works for you? |
@kulshekhar This works perfectly and solves my problem. Thank you very much for the quick response, I really appreciate it! |
@kulshekhar can you post a guide on doing this? I've been stuck on this for a day now. "jest": {
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
]
},
"globals": {
"__TS_CONFIG__": {
"module": "es2016"
}
} The problem happens with moment. |
@iRoachie do you need module to be set to es2016 for testing? |
Yea. For some background, i'm using it with react native. If I change my imports in the components to be 'import * as moment from moment', then he tests work, but the app crashes with the worrier moment is not a function |
Can you try |
Moment has no expected member 'moment' |
it's hard to guess what's wrong. Can you create a minimal repo that reproduces this issue? Once done, open a new issue here to discuss this further |
@iRoachie did you manage to fix this? I'm bumping into the same issue. |
@ds300 Nah bro. I ended up scrapping running my tests on the typescript and instead run them on the compiled javascript instead. |
@ds300 Any idea how to get around 'DEV' is not defined for react native? |
Not exactly sure where your problem is, can you be more explicit and/or
post an error message?
…On 25 Apr 2017 4:18 pm, "Kyle Roach" ***@***.***> wrote:
@ds300 <https://github.com/ds300> Any idea how to get around '*DEV*' is
not defined for react native?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#146 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABL1qUzvjgDa9Qy7G1Au6jmdklxIBDSeks5rzgDPgaJpZM4MsR0U>
.
|
Can I see your jest config in package.json? |
Same from the README. {
"jest": {
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
]
}
} |
For react-native you need to set: |
And I think, as in the ts-jest readme, the transform field should look like this: "transform": {
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js",
"^.+\\.js$": "<rootDir>/node_modules/babel-jest"
} |
@ds300 Awesome that works! Will send a pr for the README. |
I'm facing the same issue.
tsconfig.json
Any idea on how can I fix this? |
Please open a new issue and link to the old one. |
@diegoddox you ever get this to fly? Roughly the same config/setup as you and no matter what no joy unless |
@blujedis I can't remember exactly since was a while ago but here is the new config.
|
@diegoddox I got it working with a hacky workaround but thx I'll try it today! |
|
* Use build:* steps from aws-amplify-react * Update build to use jsx for @aws-amplify/ui-react * Module '"@types/react/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag' * Add missing webpack.configs for build:cjs * Remove unused tsconfig.json * Add .npmignore from aws-amplify-react * Update main/modules/typings paths * esModuleInterop solves React.Component references kulshekhar/ts-jest#146 (comment) Co-authored-by: Sam Martinez <samlmar@amazon.com>
My React Native code writes imports as follows:
This works fine in the app, but fails in Jest with the error
Cannot read property 'Component' of undefined
. This seems to be because while my app's tsconfig has"module": "es6"
and relies on Babel to convert the import statements,ts-jest
forcescommonjs
which translates this towhich is of course wrong. Until recently, I worked around this by writing a preprocessor which would run
ts-jest
andbabel-jest
in sequence, but this has been broken by the change 192b493, which forcescommonjs
even if my tsconfig says otherwise.You might ask why I don't just write
import * as RN from "react-native"
instead? Because of facebook/react-native#12018. Besides, this conceptually makes for a better test in my mind- the app and the test code go through the same transformation pipeline (TypeScript followed by Babel).There should be a way to override the
"module": "commonjs"
setting.The text was updated successfully, but these errors were encountered: