Skip to content

Commit

Permalink
test_runner: remove additional filesWatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarchini committed Aug 9, 2024
1 parent 0c8e112 commit 3ccbbb4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
26 changes: 7 additions & 19 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,34 +413,22 @@ function runTestFile(path, filesWatcher, opts) {
function watchFiles(testFiles, opts) {
const runningProcesses = new SafeMap();
const runningSubtests = new SafeMap();
const watcher = new FilesWatcher({ __proto__: null, debounce: 200, mode: 'filter', signal: opts.signal });
const watcherMode = opts.hasFiles ? 'filter' : 'all';
const watcher = new FilesWatcher({ __proto__: null, debounce: 200, mode: watcherMode, signal: opts.signal });
if (!opts.hasFiles) {
watcher.watchPath(process.cwd()); // TODO: https://github.com/nodejs/node/issues/53867 before closing this MR
}
const filesWatcher = { __proto__: null, watcher, runningProcesses, runningSubtests };
opts.root.harness.watching = true;
// Watch for created/deleted files in the current directory
const allFilesWatcher = new FilesWatcher({ __proto__: null, debounce: 200, mode: 'all', signal: opts.signal });
allFilesWatcher.watchPath(process.cwd());
allFilesWatcher.on('changed', ({ owners, eventType }) => {
if (eventType === 'rename') {
const updatedTestFiles = createTestFileList(opts.globPatterns);

const newFiles = ArrayPrototypeFilter(updatedTestFiles, (x) => !ArrayPrototypeIncludes(testFiles, x));

testFiles = updatedTestFiles;
newFiles.forEach((newFile) => {
watcher.emit('changed', { __proto__: null, owners: new SafeSet().add(newFile), eventType: 'rename' });
});
}
});
// Watch for changes in current filtered files
watcher.on('changed', ({ owners, eventType }) => {
if (!opts.hasFiles && eventType === 'rename') {
const updatedTestFiles = createTestFileList(opts.globPatterns);

const newFileName = ArrayPrototypeFind(updatedTestFiles, (x) => !ArrayPrototypeIncludes(testFiles, x));
const previousFileName = ArrayPrototypeFind(testFiles, (x) => !ArrayPrototypeIncludes(updatedTestFiles, x));

// When file renamed
if (newFileName && previousFileName) {
// When file renamed (created / deleted) we need to update the watcher
if (newFileName) {
owners = new SafeSet().add(newFileName);
watcher.filterFile(resolve(newFileName), owners);
}
Expand Down
15 changes: 12 additions & 3 deletions lib/internal/watch_mode/files_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,18 @@ class FilesWatcher extends EventEmitter {
if (this.#passthroughIPC) {
this.#setupIPC(child);
}
if (this.#mode !== 'filter') {
return;
}
/*
* TODO: Remove this comment
*
* I'm leaving this comment here to make sure we discuss this:
* Why were we filtering files only in filter mode?
*
* No tests are failing after removing this condition.
*
* if (this.#mode !== 'filter') {
* return;
* }
*/
child.on('message', (message) => {
try {
if (ArrayIsArray(message['watch:require'])) {
Expand Down

0 comments on commit 3ccbbb4

Please sign in to comment.