From d2812bcc71e5a40682cfbd7f4b4228815bb53d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Fri, 9 Nov 2018 12:09:59 +0000 Subject: [PATCH] Stop re-running tests when mtime has not changed --- CHANGELOG.md | 1 + packages/jest-haste-map/src/index.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e0db1897e2c..ad6205cfa706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - `[jest-circus]` [**BREAKING**] Fail tests if a test takes a done callback and have return values ([#9129](https://github.com/facebook/jest/pull/9129)) - `[jest-circus]` [**BREAKING**] Throw a proper error if a test / hook is defined asynchronously ([#8096](https://github.com/facebook/jest/pull/8096)) - `[jest-config, jest-resolve]` [**BREAKING**] Remove support for `browser` field ([#9943](https://github.com/facebook/jest/pull/9943)) +- `[jest-haste-map]` Stop reporting files as changed when they are only accessed ([#7347](https://github.com/facebook/jest/pull/7347)) - `[jest-resolve]` Show relative path from root dir for `module not found` errors ([#9963](https://github.com/facebook/jest/pull/9963)) ### Chore & Maintenance diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index 129858c1f40d..37ff65131ec5 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -846,6 +846,19 @@ class HasteMap extends EventEmitter { return; } + const relativeFilePath = fastPath.relative(rootDir, filePath); + const fileMetadata = hasteMap.files.get(relativeFilePath); + + // The file has been accessed, not modified + if ( + fileMetadata && + type === 'change' && + stat && + fileMetadata[H.MTIME] === stat.mtime.getTime() + ) { + return; + } + changeQueue = changeQueue .then(() => { // If we get duplicate events for the same file, ignore them. @@ -879,9 +892,6 @@ class HasteMap extends EventEmitter { return null; }; - const relativeFilePath = fastPath.relative(rootDir, filePath); - const fileMetadata = hasteMap.files.get(relativeFilePath); - // If it's not an addition, delete the file and all its metadata if (fileMetadata != null) { const moduleName = fileMetadata[H.ID];