Mam następujące ustawienia projektu:
.
|- package.json
|- library
|- button
|- button.test.tsx
Kiedy biegnę, znajduje bibliotekę testową / button / button.test.tsx, ale wyświetla komunikat o błędzie
ENOENT: no such file or directory, open "<root-dir>/library/button.test.tsx"
podczas uruchamiania testu.
Jak widać, nie jest to przeglądanie w / library / button, ale tylko / library.
Jak rozwiązać ten problem?
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"
}
}
Odpowiedzi:
0 dla odpowiedzi № 1Poleć ustawienie roots
opcja:
{
"roots": [
"<rootDir>/library"
],
"transform": {
"^.+\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\.|/)(test|spec))\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
Osobiście używam src tylko folder.