GeezerVison is showing github.com — test_runner: add enqueue and dequeue events · nodejs/node@de4f14c
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: doc/api/test.md +23-1Lines changed: 23 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1459,6 +1459,16 @@ object, streaming a series of events representing the execution of the tests. | 1459 | 1459 |
| 1460 | 1460 | Emitted when code coverage is enabled and all tests have completed. | 1461 | 1461 |
| | 1462 | +### Event: `'test:dequeue'` | | 1463 | + | | 1464 | +* `data` {Object} | | 1465 | + * `file` {string|undefined} The path of the test file, | | 1466 | + undefined if test is not ran through a file. | | 1467 | + * `name` {string} The test name. | | 1468 | + * `nesting` {number} The nesting level of the test. | | 1469 | + | | 1470 | +Emitted when a test is dequeued, right before it is executed. | | 1471 | + | 1462 | 1472 | ### Event: `'test:diagnostic'` | 1463 | 1473 |
| 1464 | 1474 | * `data` {Object} | @@ -1469,6 +1479,16 @@ Emitted when code coverage is enabled and all tests have completed. | 1469 | 1479 |
| 1470 | 1480 | Emitted when [`context.diagnostic`][] is called. | 1471 | 1481 |
| | 1482 | +### Event: `'test:enqueue'` | | 1483 | + | | 1484 | +* `data` {Object} | | 1485 | + * `file` {string|undefined} The path of the test file, | | 1486 | + undefined if test is not ran through a file. | | 1487 | + * `name` {string} The test name. | | 1488 | + * `nesting` {number} The nesting level of the test. | | 1489 | + | | 1490 | +Emitted when a test is enqueued for execution. | | 1491 | + | 1472 | 1492 | ### Event: `'test:fail'` | 1473 | 1493 |
| 1474 | 1494 | * `data` {Object} | @@ -1518,7 +1538,9 @@ Emitted when all subtests have completed for a given test. | 1518 | 1538 | * `name` {string} The test name. | 1519 | 1539 | * `nesting` {number} The nesting level of the test. | 1520 | 1540 |
| 1521 | | -Emitted when a test starts. | | 1541 | +Emitted when a test starts reporting its own and its subtests status. | | 1542 | +This event is guaranteed to be emitted in the same order as the tests are | | 1543 | +defined. | 1522 | 1544 |
| 1523 | 1545 | ### Event: `'test:stderr'` | 1524 | 1546 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -311,7 +311,9 @@ class Test extends AsyncResource { | 311 | 311 | async processPendingSubtests() { | 312 | 312 | while (this.pendingSubtests.length > 0 && this.hasConcurrency()) { | 313 | 313 | const deferred = ArrayPrototypeShift(this.pendingSubtests); | 314 | | - await deferred.test.run(); | | 314 | + const test = deferred.test; | | 315 | + this.reporter.dequeue(test.nesting, kFilename, test.name); | | 316 | + await test.run(); | 315 | 317 | deferred.resolve(); | 316 | 318 | } | 317 | 319 | } | @@ -469,6 +471,7 @@ class Test extends AsyncResource { | 469 | 471 | // If there is enough available concurrency to run the test now, then do | 470 | 472 | // it. Otherwise, return a Promise to the caller and mark the test as | 471 | 473 | // pending for later execution. | | 474 | + this.reporter.enqueue(this.nesting, kFilename, this.name); | 472 | 475 | if (!this.parent.hasConcurrency()) { | 473 | 476 | const deferred = createDeferredPromise(); | 474 | 477 |
| @@ -477,6 +480,7 @@ class Test extends AsyncResource { | 477 | 480 | return deferred.promise; | 478 | 481 | } | 479 | 482 |
| | 483 | + this.reporter.dequeue(this.nesting, kFilename, this.name); | 480 | 484 | return this.run(); | 481 | 485 | } | 482 | 486 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/tests_stream.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,6 +49,14 @@ class TestsStream extends Readable { | 49 | 49 | return { __proto__: null, todo: reason ?? true }; | 50 | 50 | } | 51 | 51 |
| | 52 | + enqueue(nesting, file, name) { | | 53 | + this[kEmitMessage]('test:enqueue', { __proto__: null, nesting, file, name }); | | 54 | + } | | 55 | + | | 56 | + dequeue(nesting, file, name) { | | 57 | + this[kEmitMessage]('test:dequeue', { __proto__: null, nesting, file, name }); | | 58 | + } | | 59 | + | 52 | 60 | start(nesting, file, name) { | 53 | 61 | this[kEmitMessage]('test:start', { __proto__: null, nesting, file, name }); | 54 | 62 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-reporters.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -97,7 +97,7 @@ describe('node:test reporters', { concurrency: true }, () => { | 97 | 97 | testFile]); | 98 | 98 | assert.strictEqual(child.stderr.toString(), ''); | 99 | 99 | const stdout = child.stdout.toString(); | 100 | | - assert.match(stdout, /{"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/); | | 100 | + assert.match(stdout, /{"test:enqueue":5,"test:dequeue":5,"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/); | 101 | 101 | assert.strictEqual(stdout.slice(0, filename.length + 2), `${filename} {`); | 102 | 102 | }); | 103 | 103 | }); | @@ -109,7 +109,7 @@ describe('node:test reporters', { concurrency: true }, () => { | 109 | 109 | assert.strictEqual(child.stderr.toString(), ''); | 110 | 110 | assert.match( | 111 | 111 | child.stdout.toString(), | 112 | | - /^package: reporter-cjs{"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/, | | 112 | + /^package: reporter-cjs{"test:enqueue":5,"test:dequeue":5,"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/, | 113 | 113 | ); | 114 | 114 | }); | 115 | 115 |
| @@ -120,7 +120,7 @@ describe('node:test reporters', { concurrency: true }, () => { | 120 | 120 | assert.strictEqual(child.stderr.toString(), ''); | 121 | 121 | assert.match( | 122 | 122 | child.stdout.toString(), | 123 | | - /^package: reporter-esm{"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/, | | 123 | + /^package: reporter-esm{"test:enqueue":5,"test:dequeue":5,"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/, | 124 | 124 | ); | 125 | 125 | }); | 126 | 126 |
| |
|