| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,6 @@ const { createInterface } = require('readline'); | |||
| 36 | 36 | const { deserializeError } = require('internal/error_serdes'); | |
| 37 | 37 | const { Buffer } = require('buffer'); | |
| 38 | 38 | const { FilesWatcher } = require('internal/watch_mode/files_watcher'); | |
| 39 | - const { queueMicrotask } = require('internal/process/task_queues'); | ||
| 40 | 39 | const console = require('internal/console/global'); | |
| 41 | 40 | const { | |
| 42 | 41 | codes: { | |
@@ -380,10 +379,16 @@ function runTestFile(path, filesWatcher, opts) { | |||
| 380 | 379 | if (watchMode) { | |
| 381 | 380 | filesWatcher.runningProcesses.delete(path); | |
| 382 | 381 | filesWatcher.runningSubtests.delete(path); | |
| 383 | - if (filesWatcher.runningSubtests.size === 0) { | ||
| 384 | - opts.root.reporter[kEmitMessage]('test:watch:drained'); | ||
| 385 | - queueMicrotask(() => opts.root.postRun()); | ||
| 386 | - } | ||
| 382 | + (async () => { | ||
| 383 | + try { | ||
| 384 | + await subTestEnded; | ||
| 385 | + } finally { | ||
| 386 | + if (filesWatcher.runningSubtests.size === 0) { | ||
| 387 | + opts.root.reporter[kEmitMessage]('test:watch:drained'); | ||
| 388 | + opts.root.postRun(); | ||
| 389 | + } | ||
| 390 | + } | ||
| 391 | + })(); | ||
| 387 | 392 | } | |
| 388 | 393 | ||
| 389 | 394 | if (code !== 0 || signal !== null) { | |
@@ -402,7 +407,8 @@ function runTestFile(path, filesWatcher, opts) { | |||
| 402 | 407 | throw err; | |
| 403 | 408 | } | |
| 404 | 409 | }); | |
| 405 | - return subtest.start(); | ||
| 410 | + const subTestEnded = subtest.start(); | ||
| 411 | + return subTestEnded; | ||
| 406 | 412 | } | |
| 407 | 413 | ||
| 408 | 414 | function watchFiles(testFiles, opts) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | // Flags: --expose-internals | |
| 2 | 2 | import * as common from '../common/index.mjs'; | |
| 3 | 3 | import { describe, it } from 'node:test'; | |
| 4 | + import assert from 'node:assert'; | ||
| 4 | 5 | import { spawn } from 'node:child_process'; | |
| 5 | 6 | import { writeFileSync } from 'node:fs'; | |
| 6 | 7 | import util from 'internal/util'; | |
@@ -36,21 +37,33 @@ async function testWatch({ fileToUpdate, file }) { | |||
| 36 | 37 | ['--watch', '--test', file ? fixturePaths[file] : undefined].filter(Boolean), | |
| 37 | 38 | { encoding: 'utf8', stdio: 'pipe', cwd: tmpdir.path }); | |
| 38 | 39 | let stdout = ''; | |
| 40 | + let currentRun = ''; | ||
| 41 | + const runs = []; | ||
| 39 | 42 | ||
| 40 | 43 | child.stdout.on('data', (data) => { | |
| 41 | 44 | stdout += data.toString(); | |
| 42 | - const testRuns = stdout.match(/ - test has ran/g); | ||
| 45 | + currentRun += data.toString(); | ||
| 46 | + const testRuns = stdout.match(/# duration_ms\s\d+/g); | ||
| 43 | 47 | if (testRuns?.length >= 1) ran1.resolve(); | |
| 44 | 48 | if (testRuns?.length >= 2) ran2.resolve(); | |
| 45 | 49 | }); | |
| 46 | 50 | ||
| 47 | 51 | await ran1.promise; | |
| 52 | + runs.push(currentRun); | ||
| 53 | + currentRun = ''; | ||
| 48 | 54 | const content = fixtureContent[fileToUpdate]; | |
| 49 | 55 | const path = fixturePaths[fileToUpdate]; | |
| 50 | 56 | const interval = setInterval(() => writeFileSync(path, content), common.platformTimeout(1000)); | |
| 51 | 57 | await ran2.promise; | |
| 58 | + runs.push(currentRun); | ||
| 52 | 59 | clearInterval(interval); | |
| 53 | 60 | child.kill(); | |
| 61 | + for (const run of runs) { | ||
| 62 | + assert.match(run, /# tests 1/); | ||
| 63 | + assert.match(run, /# pass 1/); | ||
| 64 | + assert.match(run, /# fail 0/); | ||
| 65 | + assert.match(run, /# cancelled 0/); | ||
| 66 | + } | ||
| 54 | 67 | } | |
| 55 | 68 | ||
| 56 | 69 | describe('test runner watch mode', () => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments