GeezerVison is showing github.com — test_runner: reset count on watch mode · nodejs/node@17fbfb2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/runner.js +13-1Lines changed: 13 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,10 +4,12 @@ const { | 4 | 4 | ArrayPrototypeFilter, | 5 | 5 | ArrayPrototypeForEach, | 6 | 6 | ArrayPrototypeIncludes, | | 7 | + ArrayPrototypeIndexOf, | 7 | 8 | ArrayPrototypePush, | 8 | 9 | ArrayPrototypeSlice, | 9 | 10 | ArrayPrototypeSome, | 10 | 11 | ArrayPrototypeSort, | | 12 | + ArrayPrototypeSplice, | 11 | 13 | FunctionPrototypeCall, | 12 | 14 | Number, | 13 | 15 | ObjectAssign, | @@ -324,7 +326,17 @@ function runTestFile(path, root, inspectPort, filesWatcher) { | 324 | 326 | throw err; | 325 | 327 | } | 326 | 328 | }); | 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; | 328 | 340 | } | 329 | 341 |
| 330 | 342 | function watchFiles(testFiles, root, inspectPort) { | |
Collapse file Copy file name to clipboard +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +const test = require('node:test'); | 1 | 2 | require('./dependency.js'); | 2 | 3 | import('./dependency.mjs'); | 3 | 4 | import('data:text/javascript,'); | | 5 | +test('test has ran'); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-watch-mode.mjs +7-4Lines changed: 7 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,22 +11,25 @@ async function testWatch({ files, fileToUpdate }) { | 11 | 11 | const ran2 = util.createDeferredPromise(); | 12 | 12 | const child = spawn(process.execPath, ['--watch', '--test', '--no-warnings', ...files], { encoding: 'utf8' }); | 13 | 13 | let stdout = ''; | | 14 | + | 14 | 15 | child.stdout.on('data', (data) => { | 15 | 16 | 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(); | 18 | 20 | }); | 19 | 21 |
| 20 | 22 | await ran1.promise; | 21 | | - writeFileSync(fileToUpdate, readFileSync(fileToUpdate, 'utf8')); | | 23 | + const interval = setInterval(() => writeFileSync(fileToUpdate, readFileSync(fileToUpdate, 'utf8')), 50); | 22 | 24 | await ran2.promise; | | 25 | + clearInterval(interval); | 23 | 26 | child.kill(); | 24 | 27 | } | 25 | 28 |
| 26 | 29 | describe('test runner watch mode', () => { | 27 | 30 | it('should run tests repeatedly', async () => { | 28 | 31 | 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'); | 30 | 33 | await testWatch({ files: [file1, file2], fileToUpdate: file2 }); | 31 | 34 | }); | 32 | 35 |
| |
|