Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ecf714e

Browse filesBrowse files
MoLowtargos
authored andcommitted
test_runner: reset count on watch mode
PR-URL: #46577 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 345c8c3 commit ecf714e
Copy full SHA for ecf714e

File tree

Expand file treeCollapse file tree

3 files changed

+22
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+22
-5
lines changed
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,
@@ -325,7 +327,17 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
325327
throw err;
326328
}
327329
});
328-
return subtest.start();
330+
const promise = subtest.start();
331+
if (filesWatcher) {
332+
return PromisePrototypeThen(promise, () => {
333+
const index = ArrayPrototypeIndexOf(root.subtests, subtest);
334+
if (index !== -1) {
335+
ArrayPrototypeSplice(root.subtests, index, 1);
336+
root.waitingOn--;
337+
}
338+
});
339+
}
340+
return promise;
329341
}
330342

331343
function watchFiles(testFiles, root, inspectPort) {
Collapse file
+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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.