Skip to content

Commit

Permalink
chore(deps): update choikdar to v4
Browse files Browse the repository at this point in the history
  • Loading branch information
ggodlewski committed Nov 16, 2024
1 parent d3b2c38 commit 6893764
Show file tree
Hide file tree
Showing 3 changed files with 551 additions and 287 deletions.
46 changes: 42 additions & 4 deletions lib/cli/watch-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const path = require('path');
const chokidar = require('chokidar');
const Context = require('../context');
const collectFiles = require('./collect-files');
const glob = require('glob');

/**
* Exports the `watchRun` function that runs mocha in "watch" mode.
Expand Down Expand Up @@ -167,8 +168,36 @@ const createWatcher = (
// we handle global fixtures manually
mocha.enableGlobalSetup(false).enableGlobalTeardown(false);

const watcher = chokidar.watch(watchFiles, {
ignored: watchIgnore,
const watchFilesFlat = [];

const regenerateWatchFilesFlat = () => {
let watchIgnoreFlat = [];
for (const pattern of watchIgnore) {
watchIgnoreFlat = watchIgnoreFlat.concat(glob.sync(pattern, { dot: true }));
}

let newWatchFilesFlat = [];
for (const pattern of watchFiles) {
newWatchFilesFlat = newWatchFilesFlat.concat(
glob.sync(pattern, { dot: true }).filter(pathToCheck => {
for (const watchIgnore of watchIgnoreFlat) {
if (pathToCheck === watchIgnore) {
return false;
}
if (pathToCheck.startsWith(watchIgnore + path.sep)) {
return false;
}
}
return true;
}));
}
watchFilesFlat.splice(0, watchFiles.length);
watchFilesFlat.push(...newWatchFilesFlat);
}

regenerateWatchFilesFlat();

const watcher = chokidar.watch('.', {
ignoreInitial: true
});

Expand All @@ -184,8 +213,17 @@ const createWatcher = (
rerunner.run();
});

watcher.on('all', () => {
rerunner.scheduleRun();
watcher.on('all', (event, filePath) => {
if (watchFilesFlat.includes(filePath)) {
rerunner.scheduleRun();
} else {
if (event === 'add') {
regenerateWatchFilesFlat();
if (watchFilesFlat.includes(filePath)) {
rerunner.scheduleRun();
}
}
}
});

hideCursor();
Expand Down
Loading

0 comments on commit 6893764

Please sign in to comment.