diff options
author | Moshe Atlow <moshe@atlow.co.il> | 2023-02-08 21:14:48 +0200 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2023-03-14 07:54:15 +0100 |
commit | ecf714e1d5a0735383f35c601610093d17972e74 (patch) | |
tree | 9e950638fb4e27b6816ac5ea845f1d3ae7007f04 | |
parent | 345c8c343b979b9b7aa745bf13a7af757f17db03 (diff) | |
download | node-new-ecf714e1d5a0735383f35c601610093d17972e74.tar.gz |
test_runner: reset count on watch mode
PR-URL: https://github.com/nodejs/node/pull/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>
-rw-r--r-- | lib/internal/test_runner/runner.js | 14 | ||||
-rw-r--r-- | test/fixtures/test-runner/dependent.js | 2 | ||||
-rw-r--r-- | test/parallel/test-runner-watch-mode.mjs | 11 |
3 files changed, 22 insertions, 5 deletions
diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 2e0c62505f..5108fc3283 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -4,10 +4,12 @@ const { ArrayPrototypeFilter, ArrayPrototypeForEach, ArrayPrototypeIncludes, + ArrayPrototypeIndexOf, ArrayPrototypePush, ArrayPrototypeSlice, ArrayPrototypeSome, ArrayPrototypeSort, + ArrayPrototypeSplice, FunctionPrototypeCall, Number, ObjectAssign, @@ -325,7 +327,17 @@ function runTestFile(path, root, inspectPort, filesWatcher) { throw err; } }); - return subtest.start(); + const promise = subtest.start(); + if (filesWatcher) { + return PromisePrototypeThen(promise, () => { + const index = ArrayPrototypeIndexOf(root.subtests, subtest); + if (index !== -1) { + ArrayPrototypeSplice(root.subtests, index, 1); + root.waitingOn--; + } + }); + } + return promise; } function watchFiles(testFiles, root, inspectPort) { diff --git a/test/fixtures/test-runner/dependent.js b/test/fixtures/test-runner/dependent.js index c382b0f989..6eb2ef2fda 100644 --- a/test/fixtures/test-runner/dependent.js +++ b/test/fixtures/test-runner/dependent.js @@ -1,3 +1,5 @@ +const test = require('node:test'); require('./dependency.js'); import('./dependency.mjs'); import('data:text/javascript,'); +test('test has ran'); diff --git a/test/parallel/test-runner-watch-mode.mjs b/test/parallel/test-runner-watch-mode.mjs index 6803ac4e34..1fbc7a7c58 100644 --- a/test/parallel/test-runner-watch-mode.mjs +++ b/test/parallel/test-runner-watch-mode.mjs @@ -11,22 +11,25 @@ async function testWatch({ files, fileToUpdate }) { const ran2 = util.createDeferredPromise(); const child = spawn(process.execPath, ['--watch', '--test', '--no-warnings', ...files], { encoding: 'utf8' }); let stdout = ''; + child.stdout.on('data', (data) => { stdout += data.toString(); - if (/ok 2/.test(stdout)) ran1.resolve(); - if (/ok 3/.test(stdout)) ran2.resolve(); + const matches = stdout.match(/test has ran/g); + if (matches?.length >= 1) ran1.resolve(); + if (matches?.length >= 2) ran2.resolve(); }); await ran1.promise; - writeFileSync(fileToUpdate, readFileSync(fileToUpdate, 'utf8')); + const interval = setInterval(() => writeFileSync(fileToUpdate, readFileSync(fileToUpdate, 'utf8')), 50); await ran2.promise; + clearInterval(interval); child.kill(); } describe('test runner watch mode', () => { it('should run tests repeatedly', async () => { const file1 = fixtures.path('test-runner/index.test.js'); - const file2 = fixtures.path('test-runner/subdir/subdir_test.js'); + const file2 = fixtures.path('test-runner/dependent.js'); await testWatch({ files: [file1, file2], fileToUpdate: file2 }); }); |