| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 30c9181 commit aac5ad9
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2438,6 +2438,9 @@ A successful call to [`run()`][] method will return a new {TestsStream} | |||
| 2438 | 2438 | object, streaming a series of events representing the execution of the tests. | |
| 2439 | 2439 | `TestsStream` will emit events, in the order of the tests definition | |
| 2440 | 2440 | ||
| 2441 | + Some of the events are guaranteed to be emitted in the same order as the tests | ||
| 2442 | + are defined, while others are emitted in the order that the tests execute. | ||
| 2443 | + | ||
| 2441 | 2444 | ### Event: `'test:coverage'` | |
| 2442 | 2445 | ||
| 2443 | 2446 | * `data` {Object} | |
@@ -2484,6 +2487,34 @@ object, streaming a series of events representing the execution of the tests. | |||
| 2484 | 2487 | ||
| 2485 | 2488 | Emitted when code coverage is enabled and all tests have completed. | |
| 2486 | 2489 | ||
| 2490 | + ### Event: `'test:complete'` | ||
| 2491 | + | ||
| 2492 | + * `data` {Object} | ||
| 2493 | + * `column` {number|undefined} The column number where the test is defined, or | ||
| 2494 | + `undefined` if the test was run through the REPL. | ||
| 2495 | + * `details` {Object} Additional execution metadata. | ||
| 2496 | + * `passed` {boolean} Whether the test passed or not. | ||
| 2497 | + * `duration_ms` {number} The duration of the test in milliseconds. | ||
| 2498 | + * `error` {Error|undefined} An error wrapping the error thrown by the test | ||
| 2499 | + if it did not pass. | ||
| 2500 | + * `cause` {Error} The actual error thrown by the test. | ||
| 2501 | + * `type` {string|undefined} The type of the test, used to denote whether | ||
| 2502 | + this is a suite. | ||
| 2503 | + * `file` {string|undefined} The path of the test file, | ||
| 2504 | + `undefined` if test was run through the REPL. | ||
| 2505 | + * `line` {number|undefined} The line number where the test is defined, or | ||
| 2506 | + `undefined` if the test was run through the REPL. | ||
| 2507 | + * `name` {string} The test name. | ||
| 2508 | + * `nesting` {number} The nesting level of the test. | ||
| 2509 | + * `testNumber` {number} The ordinal number of the test. | ||
| 2510 | + * `todo` {string|boolean|undefined} Present if [`context.todo`][] is called | ||
| 2511 | + * `skip` {string|boolean|undefined} Present if [`context.skip`][] is called | ||
| 2512 | + | ||
| 2513 | + Emitted when a test completes its execution. | ||
| 2514 | + This event is not emitted in the same order as the tests are | ||
| 2515 | + defined. | ||
| 2516 | + The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`. | ||
| 2517 | + | ||
| 2487 | 2518 | ### Event: `'test:dequeue'` | |
| 2488 | 2519 | ||
| 2489 | 2520 | * `data` {Object} | |
@@ -2497,6 +2528,8 @@ Emitted when code coverage is enabled and all tests have completed. | |||
| 2497 | 2528 | * `nesting` {number} The nesting level of the test. | |
| 2498 | 2529 | ||
| 2499 | 2530 | Emitted when a test is dequeued, right before it is executed. | |
| 2531 | + This event is not guaranteed to be emitted in the same order as the tests are | ||
| 2532 | + defined. The corresponding declaration ordered event is `'test:start'`. | ||
| 2500 | 2533 | ||
| 2501 | 2534 | ### Event: `'test:diagnostic'` | |
| 2502 | 2535 | ||
@@ -2511,6 +2544,8 @@ Emitted when a test is dequeued, right before it is executed. | |||
| 2511 | 2544 | * `nesting` {number} The nesting level of the test. | |
| 2512 | 2545 | ||
| 2513 | 2546 | Emitted when [`context.diagnostic`][] is called. | |
| 2547 | + This event is guaranteed to be emitted in the same order as the tests are | ||
| 2548 | + defined. | ||
| 2514 | 2549 | ||
| 2515 | 2550 | ### Event: `'test:enqueue'` | |
| 2516 | 2551 | ||
@@ -2548,6 +2583,9 @@ Emitted when a test is enqueued for execution. | |||
| 2548 | 2583 | * `skip` {string|boolean|undefined} Present if [`context.skip`][] is called | |
| 2549 | 2584 | ||
| 2550 | 2585 | Emitted when a test fails. | |
| 2586 | + This event is guaranteed to be emitted in the same order as the tests are | ||
| 2587 | + defined. | ||
| 2588 | + The corresponding execution ordered event is `'test:complete'`. | ||
| 2551 | 2589 | ||
| 2552 | 2590 | ### Event: `'test:pass'` | |
| 2553 | 2591 | ||
@@ -2569,6 +2607,9 @@ Emitted when a test fails. | |||
| 2569 | 2607 | * `skip` {string|boolean|undefined} Present if [`context.skip`][] is called | |
| 2570 | 2608 | ||
| 2571 | 2609 | Emitted when a test passes. | |
| 2610 | + This event is guaranteed to be emitted in the same order as the tests are | ||
| 2611 | + defined. | ||
| 2612 | + The corresponding execution ordered event is `'test:complete'`. | ||
| 2572 | 2613 | ||
| 2573 | 2614 | ### Event: `'test:plan'` | |
| 2574 | 2615 | ||
@@ -2583,6 +2624,8 @@ Emitted when a test passes. | |||
| 2583 | 2624 | * `count` {number} The number of subtests that have ran. | |
| 2584 | 2625 | ||
| 2585 | 2626 | Emitted when all subtests have completed for a given test. | |
| 2627 | + This event is guaranteed to be emitted in the same order as the tests are | ||
| 2628 | + defined. | ||
| 2586 | 2629 | ||
| 2587 | 2630 | ### Event: `'test:start'` | |
| 2588 | 2631 | ||
@@ -2599,6 +2642,7 @@ Emitted when all subtests have completed for a given test. | |||
| 2599 | 2642 | Emitted when a test starts reporting its own and its subtests status. | |
| 2600 | 2643 | This event is guaranteed to be emitted in the same order as the tests are | |
| 2601 | 2644 | defined. | |
| 2645 | + The corresponding execution ordered event is `'test:dequeue'`. | ||
| 2602 | 2646 | ||
| 2603 | 2647 | ### Event: `'test:stderr'` | |
| 2604 | 2648 | ||
@@ -2612,6 +2656,8 @@ defined. | |||
| 2612 | 2656 | ||
| 2613 | 2657 | Emitted when a running test writes to `stderr`. | |
| 2614 | 2658 | This event is only emitted if `--test` flag is passed. | |
| 2659 | + This event is not guaranteed to be emitted in the same order as the tests are | ||
| 2660 | + defined. | ||
| 2615 | 2661 | ||
| 2616 | 2662 | ### Event: `'test:stdout'` | |
| 2617 | 2663 | ||
@@ -2625,6 +2671,8 @@ This event is only emitted if `--test` flag is passed. | |||
| 2625 | 2671 | ||
| 2626 | 2672 | Emitted when a running test writes to `stdout`. | |
| 2627 | 2673 | This event is only emitted if `--test` flag is passed. | |
| 2674 | + This event is not guaranteed to be emitted in the same order as the tests are | ||
| 2675 | + defined. | ||
| 2628 | 2676 | ||
| 2629 | 2677 | ### Event: `'test:watch:drained'` | |
| 2630 | 2678 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -726,6 +726,10 @@ class Test extends AsyncResource { | |||
| 726 | 726 | this.mock?.reset(); | |
| 727 | 727 | ||
| 728 | 728 | if (this.parent !== null) { | |
| 729 | + const report = this.getReportDetails(); | ||
| 730 | + report.details.passed = this.passed; | ||
| 731 | + this.reporter.complete(this.nesting, this.loc, this.testNumber, this.name, report.details, report.directive); | ||
| 732 | + | ||
| 729 | 733 | this.parent.activeSubtests--; | |
| 730 | 734 | this.parent.addReadySubtest(this); | |
| 731 | 735 | this.parent.processReadySubtestRange(false); | |
@@ -806,13 +810,7 @@ class Test extends AsyncResource { | |||
| 806 | 810 | return Number(this.endTime - this.startTime) / 1_000_000; | |
| 807 | 811 | } | |
| 808 | 812 | ||
| 809 | - report() { | ||
| 810 | - countCompletedTest(this); | ||
| 811 | - if (this.subtests.length > 0) { | ||
| 812 | - this.reporter.plan(this.subtests[0].nesting, this.loc, this.subtests.length); | ||
| 813 | - } else { | ||
| 814 | - this.reportStarted(); | ||
| 815 | - } | ||
| 813 | + getReportDetails() { | ||
| 816 | 814 | let directive; | |
| 817 | 815 | const details = { __proto__: null, duration_ms: this.duration() }; | |
| 818 | 816 | ||
@@ -825,12 +823,25 @@ class Test extends AsyncResource { | |||
| 825 | 823 | if (this.reportedType) { | |
| 826 | 824 | details.type = this.reportedType; | |
| 827 | 825 | } | |
| 826 | + if (!this.passed) { | ||
| 827 | + details.error = this.error; | ||
| 828 | + } | ||
| 829 | + return { __proto__: null, details, directive }; | ||
| 830 | + } | ||
| 831 | + | ||
| 832 | + report() { | ||
| 833 | + countCompletedTest(this); | ||
| 834 | + if (this.subtests.length > 0) { | ||
| 835 | + this.reporter.plan(this.subtests[0].nesting, this.loc, this.subtests.length); | ||
| 836 | + } else { | ||
| 837 | + this.reportStarted(); | ||
| 838 | + } | ||
| 839 | + const report = this.getReportDetails(); | ||
| 828 | 840 | ||
| 829 | 841 | if (this.passed) { | |
| 830 | - this.reporter.ok(this.nesting, this.loc, this.testNumber, this.name, details, directive); | ||
| 842 | + this.reporter.ok(this.nesting, this.loc, this.testNumber, this.name, report.details, report.directive); | ||
| 831 | 843 | } else { | |
| 832 | - details.error = this.error; | ||
| 833 | - this.reporter.fail(this.nesting, this.loc, this.testNumber, this.name, details, directive); | ||
| 844 | + this.reporter.fail(this.nesting, this.loc, this.testNumber, this.name, report.details, report.directive); | ||
| 834 | 845 | } | |
| 835 | 846 | ||
| 836 | 847 | for (let i = 0; i < this.diagnostics.length; i++) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,6 +53,18 @@ class TestsStream extends Readable { | |||
| 53 | 53 | }); | |
| 54 | 54 | } | |
| 55 | 55 | ||
| 56 | + complete(nesting, loc, testNumber, name, details, directive) { | ||
| 57 | + this[kEmitMessage]('test:complete', { | ||
| 58 | + __proto__: null, | ||
| 59 | + name, | ||
| 60 | + nesting, | ||
| 61 | + testNumber, | ||
| 62 | + details, | ||
| 63 | + ...loc, | ||
| 64 | + ...directive, | ||
| 65 | + }); | ||
| 66 | + } | ||
| 67 | + | ||
| 56 | 68 | plan(nesting, loc, count) { | |
| 57 | 69 | this[kEmitMessage]('test:plan', { | |
| 58 | 70 | __proto__: null, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -96,7 +96,7 @@ describe('node:test reporters', { concurrency: true }, () => { | |||
| 96 | 96 | testFile]); | |
| 97 | 97 | assert.strictEqual(child.stderr.toString(), ''); | |
| 98 | 98 | const stdout = child.stdout.toString(); | |
| 99 | - assert.match(stdout, /{"test:enqueue":5,"test:dequeue":5,"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/); | ||
| 99 | + assert.match(stdout, /{"test:enqueue":5,"test:dequeue":5,"test:complete":5,"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/); | ||
| 100 | 100 | assert.strictEqual(stdout.slice(0, filename.length + 2), `${filename} {`); | |
| 101 | 101 | }); | |
| 102 | 102 | }); | |
@@ -108,7 +108,7 @@ describe('node:test reporters', { concurrency: true }, () => { | |||
| 108 | 108 | assert.strictEqual(child.stderr.toString(), ''); | |
| 109 | 109 | assert.match( | |
| 110 | 110 | child.stdout.toString(), | |
| 111 | - /^package: reporter-cjs{"test:enqueue":5,"test:dequeue":5,"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/, | ||
| 111 | + /^package: reporter-cjs{"test:enqueue":5,"test:dequeue":5,"test:complete":5,"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/, | ||
| 112 | 112 | ); | |
| 113 | 113 | }); | |
| 114 | 114 | ||
@@ -119,7 +119,7 @@ describe('node:test reporters', { concurrency: true }, () => { | |||
| 119 | 119 | assert.strictEqual(child.stderr.toString(), ''); | |
| 120 | 120 | assert.match( | |
| 121 | 121 | child.stdout.toString(), | |
| 122 | - /^package: reporter-esm{"test:enqueue":5,"test:dequeue":5,"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/, | ||
| 122 | + /^package: reporter-esm{"test:enqueue":5,"test:dequeue":5,"test:complete":5,"test:start":4,"test:pass":2,"test:fail":2,"test:plan":2,"test:diagnostic":\d+}$/, | ||
| 123 | 123 | ); | |
| 124 | 124 | }); | |
| 125 | 125 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments