Open yxtao opened 2 years ago
What is your normal npm test
command? And what is your jest config (if you have any)
If it's a normal "react-scripts" project, than this config should work:
{
"jest": {
"projectType": "create-react-app",
"config": {
"here-you-can-override-any-jest-option":{}
}
}
}
The error about import
and export
is coming from the wrong babel transpiling would be my guess. This means that you should not use --experimental-vm-modules
or override any options, setting the project type to "create-react-app" should be enough.
I have the same problem in the stryker generated file test.js
:
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import path from 'path';
^^^^^^
SyntaxError: Cannot use import statement outside a module
and this configuration:
{
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"_comment": "This config was generated using 'stryker init'. Please take a look at: https://stryker-mutator.io/docs/stryker-js/configuration/ for more information.",
"packageManager": "npm",
"reporters": [
"html",
"clear-text",
"progress",
"dashboard"
],
"testRunner": "jest",
"testRunner_comment": "Take a look at https://stryker-mutator.io/docs/stryker-js/jest-runner for information about the jest plugin.",
"coverageAnalysis": "perTest",
"ignorePatterns": ["dist", "coverage", "tests", "runtime", "http", "config", "v8coverage"]
}
The application is a server written in TypeScript. Normal testing works using the following command:
npx jest --config jest.config.json --runInBand
with the following configuration:
{
"rootDir": "..",
"testEnvironment": "node",
"verbose": true,
"testMatch": ["**/tests/*.test.ts"],
"moduleFileExtensions": ["ts", "js"],
"extensionsToTreatAsEsm": [".ts"],
"transformIgnorePatterns": ["!../common/", "!server/", "!./"],
"transform": {
"^.+\\.ts$": ["ts-jest", {
"tsconfig": "tests/tsconfig.json",
"diagnostics": {"ignore": [1343]}
}]
},
"setupFilesAfterEnv": ["jest-extended/all"],
"collectCoverage": false,
"collectCoverageFrom": [
"server/*.ts",
"common/*.ts"
],
"coveragePathIgnorePatterns": [".d.ts", "iie.ts", "node_modules", "save", "WordStatistics.ts"],
"coverageDirectory": "coverage",
"coverageReporters": ["text", "json-summary", "html"]
}
(Windows 11, jest 29.3.1, "@stryker-mutator/core": "^6.3.1", node 18.13.0) It is my first attempt at stryker. Any idea? Thanks! mario
Red face.
Was a test file outside the project source directory. Added to ignorePatterns
solved the problem.
Sorry for the noise!
mario
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Question
Can Stryker.conf.json file override the default transformIgnorePattern in Jest ?
In Stryker.conf.json ,
When I run npx stryker run, it shows that import and export are not supported. SyntaxError: Cannot use import statement outside a module. This points to several packages in node modules. So I added {
"transformIgnorePatterns": ["/node_modules/(?!(nodePackage1|nodePackage2)/)"]
} to the stryker.conf.json file under the “jest”/“config” section, but it didn’t solve the issue.Stryker environment
Additional context
It is a react project