We are encountering issues with our NestJS project that has multiple modules. Out of the blue, certain tests have started failing with errors 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'
The test runner seems to know which test to execute, but it then claims it cannot locate the test file. These errors occur sporadically, sometimes in small numbers and other times in larger quantities.
These errors are occurring randomly on my local machine, as well as on our Jenkins server and other developers' environments. I have been able to replicate this issue on Windows, Mac, and Linux systems.
No changes were made to either the test files or the project configuration files that could have caused this sudden problem. I have even reverted back to previous versions of the code that ran successfully in Jenkins before, and they now exhibit the same unpredictable test errors.
I have conducted tests in clean Node.js environments where only npm is installed globally.
Even when using the jest --verbose flag, I am unable to obtain any additional helpful information about the failures.
Given that the jest configuration in a NestJS project is complex, it is challenging to provide the entire configuration here. Nevertheless, I find it difficult to believe that this issue stems from a configuration problem, considering the tests were running without any issues previously and the configuration files remain unchanged.
Although I have attempted to clear the jest cache, the outcomes are inconsistent. Occasionally, I am able to achieve a successful test run after clearing the cache.
Most of the time, the test failures seem to occur in modules that contain React .tsx templates, but this is not always the case. Occasionally, a module purely written in Typescript will also encounter failures.