我收到的错误消息是:
File 'd:/Project/server/jest.config.ts' is not under 'rootDir'
'd:/Project/server/src'. 'rootDir' is expected to contain all source files.
The file is in the program because:
Matched by include pattern '**/*' in 'd:/Project/server/tsconfig.json'
我的 tsconfig.json 文件是:
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"rootDir": "./src",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
我的 jest.config.ts 文件是:
export default {
clearMocks: true,
collectCoverage: true,
coverageDirectory: "coverage",
coverageProvider: "v8",
transform: {
"^.+\\.(t|j)sx?$": ["@swc/jest"],
},
};
我正在尝试完全遵循每个文档的指示。
我在这里做错了什么?
回答1
您必须将您的 jest.config.ts
文件移动到您的 src/
目录中才能工作。我会说这个错误是不言自明的。
回答2
为了将来参考,另一种可能的解决方案是简单地改变
"rootDir": "./src",
至
"rootDir": "./",
在 tsconfig.json
文件中。
特别是如果您不想将所有配置文件移动到 src/
目录中。