Skip to content

Commit 8ae14d8

Browse files
authored
Stop issue from #444 causing randomly failing runs
1 parent 6150841 commit 8ae14d8

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/jest-transform/src/ScriptTransformer.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,21 @@ const writeCacheFile = (cachePath: Config.Path, fileData: string) => {
664664
* processes attempt to rename to the same target file at the same time.
665665
* If the target file exists we can be reasonably sure another process has
666666
* legitimately won a cache write race and ignore the error.
667+
* If the target does not exist we do not know if it is because it is still
668+
* being written by another process or is being overwritten by another process.
667669
*/
668670
const cacheWriteErrorSafeToIgnore = (
669671
e: Error & {code: string},
670672
cachePath: Config.Path,
671-
) =>
672-
process.platform === 'win32' &&
673-
e.code === 'EPERM' &&
674-
fs.existsSync(cachePath);
673+
) => {
674+
if (process.platform !== 'win32' || e.code !== 'EPERM') {
675+
return false;
676+
}
677+
if (!fs.existsSync(cachePath)) {
678+
console.warn('Possible problem writing cache if this occurs many times', e);
679+
}
680+
return true;
681+
};
675682

676683
const readCacheFile = (cachePath: Config.Path): string | null => {
677684
if (!fs.existsSync(cachePath)) {

0 commit comments

Comments
 (0)