From df7b3da11b8aaf05d367dcae8c79624fed23eabf 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.js | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1df683e1edfd..9d20eb843307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ - `[expect]` Fix toMatchObject matcher when used with `Object.create(null)` ([#7334](https://github.com/facebook/jest/pull/7334)) - `[jest-haste-map]` [**BREAKING**] Recover files correctly after haste name collisions are fixed ([#7329](https://github.com/facebook/jest/pull/7329)) - `[jest-haste-map]` Remove legacy condition for duplicate module detection ([#7333](https://github.com/facebook/jest/pull/7333)) +- `[jest-haste-map]` Stop reporting files as changed when they are only accessed ([#7347](https://github.com/facebook/jest/pull/7347)) ### Chore & Maintenance diff --git a/packages/jest-haste-map/src/index.js b/packages/jest-haste-map/src/index.js index d31d8f2188ff..5abffb7b5941 100644 --- a/packages/jest-haste-map/src/index.js +++ b/packages/jest-haste-map/src/index.js @@ -800,6 +800,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. @@ -830,9 +843,6 @@ class HasteMap extends EventEmitter { const add = () => eventsQueue.push({filePath, stat, type}); - 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];