stryker-js: Cannot find module 'setupDevtools' from 'setup.js'
Summary
I use a react-native project with typescript and jest. When I tried to install stryker and run it, I have the following message :
Cannot find module 'setupDevtools' from 'setup.js'
at Resolver.resolveModule (../../node_modules/jest-resolve/build/index.js:169:17)
at Object.<anonymous> (../../node_modules/react-native/jest/setup.js:30:1)
● Test suite failed to run
But when I use jest, I don’t have any error. Is something wrong with my config or is it a real issue ?
Stryker config
Stryker
module.exports = (config) => {
config.set({
// Test runners
testRunner: 'jest',
jest: {
config: require('./jest.config.js'),
},
// Transpilers
transpilers: ['typescript', 'babel'],
tsconfigFile: 'tsconfig.json',
babelrcFile: '.babelrc',
// Reporters
reporter: ['clear-text', 'progress'],
coverageAnalysis: 'off',
// Files
files: [
'src/**/*',
'jest/**/*',
'__mocks__/**/*',
],
// Mutations
mutator: 'typescript',
// mutate: ['src/**/*.ts?(x)', '!src/**/*.container.ts', '!src/**/*.d.ts', '!**/index.ts'],
});
};
Jest
module.exports = {
preset: 'react-native',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
transform: {
'\\.(js|jsx)$': '<rootDir>/node_modules/babel-jest',
'\\.(ts|tsx)$': '<rootDir>/node_modules/ts-jest/preprocessor.js',
'\\.(gql|graphql)$': '<rootDir>/node_modules/jest-transform-graphql',
},
transformIgnorePatterns: [
'node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@bam.tech/react-native-(root-siblings|modalbox)|static-container|react-navigation)',
],
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js|jsx)$',
testPathIgnorePatterns: ['\\.snap$', '<rootDir>/node_modules/', '<rootDir>/stryker-tmp/'],
cacheDirectory: '.jest/cache',
moduleNameMapper: {
'^[./a-zA-Z0-9$_-]+\\.(jpg|png|gif|eot|svg|ttf|woff|woff2|mp4|webm)$':
'<rootDir>/jest/FileStub.js',
},
collectCoverageFrom: [
'src/**/*.{js|ts|tsx|jsx}',
'!src/**/*.container.ts',
'!src/**/*.d.ts',
'!**/index.ts',
],
setupTestFrameworkScriptFile: '<rootDir>/jest/setupTests.js',
};
Babel
{
"presets": ["react-native", "react-native-stage-0/decorator-support"]
}
Stryker environment
"stryker": "^0.22.4",
"stryker-api": "^0.16.1",
"stryker-babel-transpiler": "^0.4.2",
"stryker-jest-runner": "^0.6.0",
"stryker-typescript": "^0.10.2",
But also
"babel-core": "^6.26.0",
"babel-jest": "22.4.1",
"babel-preset-react-native": "4.0.0",
"babel-preset-react-native-stage-0": "^1.0.1",
"jest": "22.4.2",
"ts-jest": "^22.4.1",
"typescript": "^2.7.2"
Your Environment
software | version(s) |
---|---|
node | 9.5.0 |
npm | 5.6.0 |
Operating System | macOS High Sierra |
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 33 (15 by maintainers)
@mickaelw It’s an issue with type in your dependencies. You ask for types/react 16.7.3 but enzyme is still using types/react 16.4.13 in you yarn.lock.
I made a PR, it’s not the best fix but it’s enough. https://github.com/mickaelw/test-stryker/pull/1
@nicojs In this PR, yarn test works for me, but not yarn stryker
I’ve been able to reproduce the error without Stryker, just plain jest + react-native. I’ve opened up an issue at react-native. Hopefully there is a solution. https://github.com/facebook/react-native/issues/22823
I will try to figure out what’s wrong before this year is done. Thanks for your patience
@simondel Thanks for the time you takes
I don’t really know and can’t explain why we need babel. We are starting using typescript on our project and still having some js files. For example,
index.js
,setupTest.js
, …, and runningyarn test:unit
without babel will returnHow did you remove babel from the project ?
And I’m not sure because I could only try tomorrow, but I think my real react-native project won’t correctly run and build on IOS and Android without babel. For information, we’re using this package. I’ll check tomorrow.
But I’m surprised the provided repository does not produce error about setupDevtools on your computer. I tried on Mac / Node 9.5 and Linux / Node 8.4 and I got it every time.
I need to comment the
node_modules/react-native/jest/setup.js
from line 29 to the EOF to get the error you hadIn this case, if I remove
setupTestFrameworkScriptFile
from the jest config and use the testIt works !!!
But then, I removed
Still works ! Why ? It makes me confused.
Ok, if I go back and look at the preset error. I found out the issue came from the following lines of
setupTest.js
But then, if i run
yarn add babel-preset-es2015
, I have the errorI found this issue and try quickly
yarn add jsdom@11.1.0
and now I have the errorI’ll will keep investiguate tomorrow or this week-end.
But I don’t think that is a solution for me cause during this time,
yarn test:unit
does not work with the errorAnd if I don’t comment the
node_modules/react-native/jest/setup.js
from line 29 to the EOF, tests pass but Stryker ask me for setupDevtools…@simondel I made this for you.
Jest works
Stryker does not