Occasionally I've been seeing the following error when running my Jest test suite.
> @module/module@1.2.9 test C:\_Development\project
> jest
FAIL __tests__/resources/project.router.test.ts
● Test suite failed to run
Could not find source file: 'C:\_Development\project\__tests__\resources\project.actions.test.ts'.
at getValidSourceFile (node_modules/typescript/lib/typescript.js:135637:29)
at Object.getSemanticDiagnostics (node_modules/typescript/lib/typescript.js:135859:36)
at doTypeChecking (node_modules/ts-jest/dist/compiler/language-service.js:11:35)
at node_modules/ts-jest/dist/compiler/language-service.js:96:25
at Array.forEach (<anonymous>)
at compileFn (node_modules/ts-jest/dist/compiler/language-service.js:94:26)
at Object.compile (node_modules/ts-jest/dist/compiler/instance.js:90:25)
at TsJestTransformer.process (node_modules/ts-jest/dist/ts-jest-transformer.js:94:41)
at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:481:35)
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:586:40)
The source files always exist in the right location - it seems like actually Jest isnt always calling the real file, but grabbing it from the cache?
The solution is to pass the following arguemnts
jest --clearCache
Obviously, alot of the time, we arn't running Jest directly, its in our package.json. In that case you can pass in an extra -- to tell the npm runner to pass the argument down into the underlying call.
npm run test -- --clearCache
Hope this helps!
Top comments (5)
Thank you for posting this, @smarthomedan. This helped me too!
Maybe it's just me, but on
jest@27.5.1
with@angular-builders/jest@12.1.2
, I get the following warning:You might want to update the post for versions of
jest
which have deprecated support for camelCase arguments.For older versions of
jest
, use the--clearCache
argument.For newer versions of
jest
, use the--clear-cache
argument.u saved me, thks!
Thank you Dan!
Thank you! That just did the trick
Coming at you in early 2022, glad you posted this. 💯