diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 8e4c18fd726009..aae7564e42b95e 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -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); } diff --git a/lib/internal/watch_mode/files_watcher.js b/lib/internal/watch_mode/files_watcher.js index 7577ce94b25b62..ca9210e17244a5 100644 --- a/lib/internal/watch_mode/files_watcher.js +++ b/lib/internal/watch_mode/files_watcher.js @@ -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'])) {