MCPcopy Index your code
hub / github.com/nodejs/node / onChanged

Function onChanged

lib/internal/test_runner/runner.js:630–671  ·  view source on GitHub ↗
({ owners, eventType })

Source from the content-addressed store, hash-verified

628
629 // Watch for changes in current filtered files
630 const onChanged = ({ owners, eventType }) => {
631 if (!opts.hasFiles && (eventType === 'rename' || eventType === 'change')) {
632 const updatedTestFiles = createTestFileList(opts.globPatterns, opts.cwd);
633 const newFileName = ArrayPrototypeFind(updatedTestFiles, (x) => !ArrayPrototypeIncludes(testFiles, x));
634 const previousFileName = ArrayPrototypeFind(testFiles, (x) => !ArrayPrototypeIncludes(updatedTestFiles, x));
635
636 testFiles = updatedTestFiles;
637
638 // When file renamed (created / deleted) we need to update the watcher
639 if (newFileName) {
640 owners = new SafeSet().add(newFileName);
641 const resolveFileName = isAbsolute(newFileName) ? newFileName : resolve(opts.cwd, newFileName);
642 watcher.filterFile(resolveFileName, owners);
643 }
644
645 if (!newFileName && previousFileName) {
646 return; // Avoid rerunning files when file deleted
647 }
648 }
649 // Reset the root start time to recalculate the duration
650 // of the run
651 opts.root.clearExecutionTime();
652 opts.root.reporter[kEmitMessage]('test:watch:restarted');
653
654 // Restart test files
655 if (opts.isolation === 'none') {
656 PromisePrototypeThen(restartTestFile(kIsolatedProcessName), undefined, (error) => {
657 triggerUncaughtException(error, true /* fromPromise */);
658 });
659 } else {
660 watcher.unfilterFilesOwnedBy(owners);
661 PromisePrototypeThen(SafePromiseAllReturnVoid(testFiles, async (file) => {
662 if (!owners.has(file)) {
663 return;
664 }
665
666 await restartTestFile(file);
667 }, undefined, (error) => {
668 triggerUncaughtException(error, true /* fromPromise */);
669 }));
670 }
671 };
672
673 watcher.on('changed', onChanged);
674

Callers

nothing calls this directly

Calls 9

createTestFileListFunction · 0.85
isAbsoluteFunction · 0.85
restartTestFileFunction · 0.85
filterFileMethod · 0.80
clearExecutionTimeMethod · 0.80
unfilterFilesOwnedByMethod · 0.80
addMethod · 0.65
hasMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…