When I run e2e test in my application with the command:
jest --no-cache --config ./test/jest-e2e.json --detectOpenHandles
I receive some errors like:
Cannot find module 'src/modules/shared/shared.module' from '../src/modules/charge/invoice/invoice.module.ts'
But it works if I change the path import to ../../src/ instead of only src/ in these other files.
jest-e2e.json
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"verbose": true
}
package.json
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"esModuleInterop": true,
"scripts": {
...
},
"dependencies": {
...
},
"devDependencies": {
...
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"allowJs": true
},
"include": ["src/**/*"],
}
I tried to change the configuration files but without success (added "type": "module" in package.json; "include": ["src/**/*"] in tsconfig.json). And saw similar questions but none work it. I needed that src/ imports work too.