stryker-js: Custom tsconfig path throw "Cannot find module" error (compilerOptions.paths)
Question
Hello, I’m trying to add stryker to my current typescript project, but I’m unable to run the tests, it seems that the custom compilerOptions.paths present in my tsconfig.json is ignored.
this is the error
14:16:01 (21772) INFO DryRunExecutor Starting initial test run. This may take a while.
14:16:03 (21772) ERROR DryRunExecutor One or more tests resulted in an error:
Error: MODULE_NOT_FOUND (undefined) Error: Cannot find module '@server/services'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/home/test/project/.stryker-tmp/sandbox1527714/test/testlib/onboarding.ts:2:1)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Module.m._compile (/home/test/project/node_modules/ts-node/src/index.ts:858:23)
at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Object.require.extensions.(anonymous function) [as .ts] (/home/test/project/node_modules/ts-node/src/index.ts:861:12)
at Module.load (internal/modules/cjs/loader.js:653:32)
14:16:03 (21772) ERROR Stryker Error: Something went wrong in the initial test run
at DryRunExecutor.validateResultCompleted (/home/test/project/node_modules/@stryker-mutator/core/src/process/3-dry-run-executor.js:59:15)
at DryRunExecutor.timeDryRun (/home/test/project/node_modules/@stryker-mutator/core/src/process/3-dry-run-executor.js:69:14)
at process._tickCallback (internal/process/next_tick.js:68:7)
Stryker environment
├─┬ @stryker-mutator/core@4.4.1
│ ├─┬ @stryker-mutator/api@4.4.1
│ ├─┬ @stryker-mutator/instrumenter@4.4.1
│ │ ├── @stryker-mutator/api@4.4.1 deduped
│ │ ├── @stryker-mutator/util@4.4.1 deduped
│ ├─┬ @stryker-mutator/util@4.4.1
├─┬ @stryker-mutator/mocha-runner@4.4.1
│ ├── @stryker-mutator/api@4.4.1 deduped
│ ├── @stryker-mutator/util@4.4.1 deduped
├─┬ @stryker-mutator/typescript-checker@4.4.1
│ ├── @stryker-mutator/api@4.4.1 deduped
│ ├── @stryker-mutator/util@4.4.1 deduped
"mocha": "^7.1.2"
"ts-mocha": "^7.0.0"
"typescript": "^3.8.3"
Additional context
I’m using ts-mocha to run the tests with this command:
"test:unit": "ts-mocha --project test/tsconfig.json -r tsconfig-paths/register 'test/**/*.spec.ts' --exit --timeout 15000",
test/tsconfig.json contains the following
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@server": ["../src"],
"@server/*": ["../src/*"]
}
},
"include": [ "." ]
}
this is my stryker config
{
packageManager: "yarn",
reporters: ["html", "clear-text", "progress"],
testRunner: "mocha",
commandRunner: {
command: "yarn test:unit",
},
coverageAnalysis: "off",
mutate: ["src/**/*.ts"],
mochaOptions: {
spec: ["test/**/*.spec.ts"],
require: ["ts-node/register", "tsconfig-paths/register"]
},
tsconfigFile: "test/tsconfig.json"
};
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (4 by maintainers)
@Zialus would you be able to create a small reproduction project? Would love to take a look! Please upload it in a new issue
I just realized that the issue is actually module lazy loading
https://angular.io/guide/lazy-loading-ngmodules
The line
is the problematic one.
If I tell stryker not to mutate
app-routing.module.ts
then everything works fine!