| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 345c8c3 commit ecf714e
3 files changed
| 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, | |
@@ -325,7 +327,17 @@ function runTestFile(path, root, inspectPort, filesWatcher) { | |||
| 325 | 327 | throw err; | |
| 326 | 328 | } | |
| 327 | 329 | }); | |
| 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; | ||
| 329 | 341 | } | |
| 330 | 342 | ||
| 331 | 343 | function watchFiles(testFiles, root, inspectPort) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 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'); | ||
| 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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments