GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test_runner: reset count on watch mode · nodejs/node@17fbfb2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/test_runner
    • runner.js
  • test
    • fixtures/test-runner
      • dependent.js
    • parallel
      • test-runner-watch-mode.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/test_runner/runner.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/runner.js
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ const {
44
ArrayPrototypeFilter,
55
ArrayPrototypeForEach,
66
ArrayPrototypeIncludes,
7+
ArrayPrototypeIndexOf,
78
ArrayPrototypePush,
89
ArrayPrototypeSlice,
910
ArrayPrototypeSome,
1011
ArrayPrototypeSort,
12+
ArrayPrototypeSplice,
1113
FunctionPrototypeCall,
1214
Number,
1315
ObjectAssign,
@@ -324,7 +326,17 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
324326
throw err;
325327
}
326328
});
327-
return subtest.start();
329+
const promise = subtest.start();
330+
if (filesWatcher) {
331+
return PromisePrototypeThen(promise, () => {
332+
const index = ArrayPrototypeIndexOf(root.subtests, subtest);
333+
if (index !== -1) {
334+
ArrayPrototypeSplice(root.subtests, index, 1);
335+
root.waitingOn--;
336+
}
337+
});
338+
}
339+
return promise;
328340
}
329341

330342
function watchFiles(testFiles, root, inspectPort) {
Collapse file

‎test/fixtures/test-runner/dependent.js‎

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const test = require('node:test');
12
require('./dependency.js');
23
import('./dependency.mjs');
34
import('data:text/javascript,');
5+
test('test has ran');
Collapse file

‎test/parallel/test-runner-watch-mode.mjs‎

Copy file name to clipboardExpand all lines: test/parallel/test-runner-watch-mode.mjs
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,25 @@ async function testWatch({ files, fileToUpdate }) {
1111
const ran2 = util.createDeferredPromise();
1212
const child = spawn(process.execPath, ['--watch', '--test', '--no-warnings', ...files], { encoding: 'utf8' });
1313
let stdout = '';
14+
1415
child.stdout.on('data', (data) => {
1516
stdout += data.toString();
16-
if (/ok 2/.test(stdout)) ran1.resolve();
17-
if (/ok 3/.test(stdout)) ran2.resolve();
17+
const matches = stdout.match(/test has ran/g);
18+
if (matches?.length >= 1) ran1.resolve();
19+
if (matches?.length >= 2) ran2.resolve();
1820
});
1921

2022
await ran1.promise;
21-
writeFileSync(fileToUpdate, readFileSync(fileToUpdate, 'utf8'));
23+
const interval = setInterval(() => writeFileSync(fileToUpdate, readFileSync(fileToUpdate, 'utf8')), 50);
2224
await ran2.promise;
25+
clearInterval(interval);
2326
child.kill();
2427
}
2528

2629
describe('test runner watch mode', () => {
2730
it('should run tests repeatedly', async () => {
2831
const file1 = fixtures.path('test-runner/index.test.js');
29-
const file2 = fixtures.path('test-runner/subdir/subdir_test.js');
32+
const file2 = fixtures.path('test-runner/dependent.js');
3033
await testWatch({ files: [file1, file2], fileToUpdate: file2 });
3134
});
3235

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.