Skip to content

Commit

Permalink
fix intermittent test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Aug 11, 2017
1 parent 2a231b6 commit 9e481d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/watch/fileWatchers.js
Expand Up @@ -29,11 +29,13 @@ export function deleteTask(id, target, chokidarOptionsHash) {
const group = watchers.get(chokidarOptionsHash);

const watcher = group.get(id);
watcher.tasks.delete(target);
if (watcher) {
watcher.tasks.delete(target);

if (watcher.tasks.size === 0) {
watcher.close();
group.delete(id);
if (watcher.tasks.size === 0) {
watcher.close();
group.delete(id);
}
}
}

Expand Down
24 changes: 16 additions & 8 deletions src/watch/index.js
Expand Up @@ -147,14 +147,8 @@ class Task {
const watched = new Set();

bundle.modules.forEach(module => {
if (!this.filter(module.id)) return;

if (~this.dests.indexOf(module.id)) {
throw new Error('Cannot import the generated bundle');
}

watched.add(module.id);
addTask(module.id, this, this.chokidarOptions, this.chokidarOptionsHash);
this.watchFile(module.id);
});

this.watched.forEach(id => {
Expand Down Expand Up @@ -182,16 +176,30 @@ class Task {
});
})
.catch(error => {
if (this.closed) return;

if (this.cache) {
this.cache.modules.forEach(module => {
// this is necessary to ensure that any 'renamed' files
// continue to be watched following an error
addTask(module.id, this, this.chokidarOptions, this.chokidarOptionsHash);
this.watchFile(module.id);
});
}
throw error;
});
}

watchFile(id) {
if (!this.filter(id)) return;

if (~this.dests.indexOf(id)) {
throw new Error('Cannot import the generated bundle');
}

// this is necessary to ensure that any 'renamed' files
// continue to be watched following an error
addTask(id, this, this.chokidarOptions, this.chokidarOptionsHash);
}
}

export default function watch(configs) {
Expand Down

0 comments on commit 9e481d8

Please sign in to comment.