-
Notifications
You must be signed in to change notification settings - Fork 49
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
Jest transform support / documentation #21
Comments
Hey Axel :-) I'd recommend using ts-jest. It is more mature than It makes sense to use Here's my Jest config for reference: {
"jest": {
"preset": "react-native",
"moduleDirectories": [
"node_modules",
"<rootDir>" // for absolute imports
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"transformIgnorePatterns": [
"node_modules/(?!(react-native|glamorous-native|react-native-global-props|react-native-elements|react-native-vector-icons|react-native-side-menu|react-native-tab-navigator|react-native-animatable|react-navigation)/)"
],
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
]
},
} I'd be open to figuring out how to do this, but ts-jest solves a lot of problems that I don't fancy solving again, so maybe it should be in collaboration with that project? |
I help maintain ts-jest, and I'd love to keep these projects in sync somehow. (Love what you're doing here btw @ds300) |
Hey @GeeWee That would would be awesome. Any ideas about how this could be done? It has been a long while since I looked at the ts-jest code. |
I'm not actually sure what needs to be done, ts-jest supports running things through Babel (with or without a babelrc) as a secondary transpilation step. (I think you added that originally) - does this transformer do any extra magic that'll cause the two projects to be incompatible? |
Edited: My issue was related to ts-jest, opened an issue #322 there. |
I would open a new issue in |
I just try preprocess jest tests with this module and it seems to work well with small glue code. My config: var tsTransformer = require('react-native-typescript-transformer')
var rnTransformer = require('react-native/jest/preprocessor')
var preprocessor = Object.assign({}, rnTransformer, {
process (src, file) {
return tsTransformer.transform({
filename: file,
localPath: file,
options: {
dev: true,
inlineRequires: true,
platform: '',
projectRoot: '',
retainLines: true,
},
src,
}).code
},
})
module.exports = preprocessor package.json (jest config part) "jest": {
"preset": "react-native",
"transform": {
"^.+\\.[jt]sx?$": "<rootDir>/jest/preprocessor.js"
},
"testMatch": [
"**/*.spec.{js,jsx,ts,tsx}"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js"
]
}, What do you think? |
@vovkasm This is cool! Thanks for sharing :) I still haven't heard of anyone having problems with |
No problems with ts-jest, except hard to track deps. react-native-typescript-transformer requires math fewer other modules. :) |
Hi there, Today i was suffering an issue in my tests, that I finally solved from using the previous gist and moving away of Anyway, I just wanted to state that I've had problems and solved them with this. Thanks |
If you manage to produce a working repo I'd love to see it in ts-jest. |
Happy to have your input @GeeWee ! I agree that it makes most sense to focus on ts-jest. It should work, and it has a lot of useful things that react-native-typescript-transformer lacks. |
@vovkasm your setup is not working for me. I have errors like this: FAIL ~js/app/lib/__tests__/formatPhone.spec.js
● Test suite failed to run
TypeError: Jest: a transform's `process` function must return a string, or an object with `code` key containing this string.
at ScriptTransformer.transformSource (node_modules/jest-untime/build/script_transformer.js:238:15) RN: 0.52.2 |
@aMarCruz: too new version of jest ))) it changed api for transformers, more info here: #39 (comment) |
Hi, thanks for the awesome library. Nice to see proper TypeScript support in React Native.
As Jest is the default test runner in React Native projects created by by the
react-native
cli tool, it would be nice to see support or documentation on how to use this library as the transformer for Jest as well.Of course the alternative is to use
https://github.com/lozinsky/typescript-babel-jest
, but would somehow be nice to use the same transformation for tests and production.The text was updated successfully, but these errors were encountered: