我有以下项目设置:
.
|- package.json
|- library
|- button
|- button.test.tsx
当我运行jest时,它会找到测试库/ button / button.test.tsx,但会显示错误消息
ENOENT: no such file or directory, open '<root-dir>/library/button.test.tsx'
运行测试时。
正如您所看到的那样,它不是在查找/ library / button,而只是/ library。
我该如何解决这个问题?
的package.json:
"jest": {
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"\\.(ts|tsx)$": "./node_modules/ts-jest/preprocessor.js"
},
"testRegex": "./library/.*.test\\.(ts|tsx|js)$",
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"./__mocks__/fileMock.js",
"\\.(css|less)$": "identity-obj-proxy"
}
}
答案 0 :(得分:0)
建议设置roots
选项:
{
"roots": [
"<rootDir>/library"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
我个人仅使用src文件夹。