'Jest tests failing with ENOENT no such file or directory (referring to the spec files themselves)
We have a NestJS project with several modules. Suddenly, some tests stopped working with errors all like
FAIL libs/backend/nest/pipes/src/lib/iso-date-validation.pipe.spec.ts
● Test suite failed to run
ENOENT: no such file or directory, open D:\git\my-nest-project\libs\backend\nest\pipes\src\lib\iso-date-validation.pipe.spec.ts'
It knows what test to run, but then it claims it can't find the test file. Sometimes we get a couple of these errors, sometimes dozens.
These errors are happening randomly (not always on the same tests) locally on my machine as well as on our Jenkins server and on other developer environments as well. I can reproduce this on Windows/Mac/Linux.
There were no changes to the test or project configuration files that would have triggered this change. In fact, I have checked out previous versions of the codebase that built reliably in Jenkins and now they have the same random test errors.
I have tested on clean nodejs environments with nothing installed globally except npm.
Using the jest --verbose flag gives me no further details.
The jest config in a NestJS project is multi-layered, so it's hard to display the whole thing here, but I don't understand how this could be a configuration issue because the tests used to run fine and the configuration files have not changed.
I have tried clearing the jest cache, but the results are not consistent. On some occasions I can get a clean test run after clearing the cache.
More often than not, the test failures occur in a module that has some React .tsx templates, but not always. Sometimes a pure Typescript module will fail.
Solution 1:[1]
Canceling the test watch and restarting it worked for me. with Ctrl-D then npm test
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Embedded_Mugs |
