Skip to content

Commit def2885

Browse files
committed
Improve handling of temporary file changes in watch mode
1 parent 1a62f15 commit def2885

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

lib/snapshot-manager.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,10 @@ class Manager {
355355
const {dir, relFile, snapFile, snapPath, reportPath} = this;
356356

357357
if (this.updating && this.newBlocksByTitle.size === 0) {
358-
return [
359-
...cleanFile(snapPath),
360-
...cleanFile(reportPath),
361-
];
358+
return {
359+
changedFiles: [cleanFile(snapPath), cleanFile(reportPath)].flat(),
360+
temporaryFiles: [],
361+
};
362362
}
363363

364364
if (!this.hasChanges) {
@@ -376,11 +376,14 @@ class Manager {
376376

377377
fs.mkdirSync(dir, {recursive: true});
378378

379-
const paths = [snapPath, reportPath];
380-
const tmpfileCreated = tmpfile => paths.push(tmpfile);
379+
const temporaryFiles = [];
380+
const tmpfileCreated = file => temporaryFiles.push(file);
381381
writeFileAtomic.sync(snapPath, buffer, {tmpfileCreated});
382382
writeFileAtomic.sync(reportPath, reportBuffer, {tmpfileCreated});
383-
return paths;
383+
return {
384+
changedFiles: [snapPath, reportPath],
385+
temporaryFiles,
386+
};
384387
}
385388
}
386389

lib/watcher.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export default class Watcher {
164164
this.testDependencies = [];
165165
this.trackTestDependencies(api);
166166

167+
this.temporaryFiles = new Set();
167168
this.touchedFiles = new Set();
168169
this.trackTouchedFiles(api);
169170

@@ -245,9 +246,13 @@ export default class Watcher {
245246
return;
246247
}
247248

248-
for (const file of evt.files) {
249+
for (const file of evt.files.changedFiles) {
249250
this.touchedFiles.add(file);
250251
}
252+
253+
for (const file of evt.files.temporaryFiles) {
254+
this.temporaryFiles.add(file);
255+
}
251256
});
252257
});
253258
}
@@ -393,6 +398,14 @@ export default class Watcher {
393398
return false;
394399
}
395400

401+
// Unlike touched files, temporary files are never cleared. We may see
402+
// adds and unlinks detected separately, so we track the temporary files
403+
// as long as AVA is running.
404+
if (this.temporaryFiles.has(path)) {
405+
debug('Ignoring known temporary file %s', path);
406+
return false;
407+
}
408+
396409
return true;
397410
});
398411

0 commit comments

Comments
 (0)