| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3a3a6d8 commit a49e17e
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1218,6 +1218,8 @@ object, streaming a series of events representing the execution of the tests. | |||
| 1218 | 1218 | ### Event: `'test:diagnostic'` | |
| 1219 | 1219 | ||
| 1220 | 1220 | * `data` {Object} | |
| 1221 | + * `file` {string|undefined} The path of the test file, | ||
| 1222 | + undefined if test is not ran through a file. | ||
| 1221 | 1223 | * `message` {string} The diagnostic message. | |
| 1222 | 1224 | * `nesting` {number} The nesting level of the test. | |
| 1223 | 1225 | ||
@@ -1229,6 +1231,8 @@ Emitted when [`context.diagnostic`][] is called. | |||
| 1229 | 1231 | * `details` {Object} Additional execution metadata. | |
| 1230 | 1232 | * `duration` {number} The duration of the test in milliseconds. | |
| 1231 | 1233 | * `error` {Error} The error thrown by the test. | |
| 1234 | + * `file` {string|undefined} The path of the test file, | ||
| 1235 | + undefined if test is not ran through a file. | ||
| 1232 | 1236 | * `name` {string} The test name. | |
| 1233 | 1237 | * `nesting` {number} The nesting level of the test. | |
| 1234 | 1238 | * `testNumber` {number} The ordinal number of the test. | |
@@ -1242,6 +1246,8 @@ Emitted when a test fails. | |||
| 1242 | 1246 | * `data` {Object} | |
| 1243 | 1247 | * `details` {Object} Additional execution metadata. | |
| 1244 | 1248 | * `duration` {number} The duration of the test in milliseconds. | |
| 1249 | + * `file` {string|undefined} The path of the test file, | ||
| 1250 | + undefined if test is not ran through a file. | ||
| 1245 | 1251 | * `name` {string} The test name. | |
| 1246 | 1252 | * `nesting` {number} The nesting level of the test. | |
| 1247 | 1253 | * `testNumber` {number} The ordinal number of the test. | |
@@ -1253,6 +1259,8 @@ Emitted when a test passes. | |||
| 1253 | 1259 | ### Event: `'test:plan'` | |
| 1254 | 1260 | ||
| 1255 | 1261 | * `data` {Object} | |
| 1262 | + * `file` {string|undefined} The path of the test file, | ||
| 1263 | + undefined if test is not ran through a file. | ||
| 1256 | 1264 | * `nesting` {number} The nesting level of the test. | |
| 1257 | 1265 | * `count` {number} The number of subtests that have ran. | |
| 1258 | 1266 | ||
@@ -1261,6 +1269,8 @@ Emitted when all subtests have completed for a given test. | |||
| 1261 | 1269 | ### Event: `'test:start'` | |
| 1262 | 1270 | ||
| 1263 | 1271 | * `data` {Object} | |
| 1272 | + * `file` {string|undefined} The path of the test file, | ||
| 1273 | + undefined if test is not ran through a file. | ||
| 1264 | 1274 | * `name` {string} The test name. | |
| 1265 | 1275 | * `nesting` {number} The nesting level of the test. | |
| 1266 | 1276 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -140,11 +140,11 @@ class FileTest extends Test { | |||
| 140 | 140 | break; | |
| 141 | 141 | ||
| 142 | 142 | case TokenKind.TAP_PLAN: | |
| 143 | - this.reporter.plan(nesting, node.end - node.start + 1); | ||
| 143 | + this.reporter.plan(nesting, this.name, node.end - node.start + 1); | ||
| 144 | 144 | break; | |
| 145 | 145 | ||
| 146 | 146 | case TokenKind.TAP_SUBTEST_POINT: | |
| 147 | - this.reporter.start(nesting, node.name); | ||
| 147 | + this.reporter.start(nesting, this.name, node.name); | ||
| 148 | 148 | break; | |
| 149 | 149 | ||
| 150 | 150 | case TokenKind.TAP_TEST_POINT: | |
@@ -164,6 +164,7 @@ class FileTest extends Test { | |||
| 164 | 164 | if (pass) { | |
| 165 | 165 | this.reporter.ok( | |
| 166 | 166 | nesting, | |
| 167 | + this.name, | ||
| 167 | 168 | node.id, | |
| 168 | 169 | node.description, | |
| 169 | 170 | YAMLToJs(node.diagnostics), | |
@@ -172,6 +173,7 @@ class FileTest extends Test { | |||
| 172 | 173 | } else { | |
| 173 | 174 | this.reporter.fail( | |
| 174 | 175 | nesting, | |
| 176 | + this.name, | ||
| 175 | 177 | node.id, | |
| 176 | 178 | node.description, | |
| 177 | 179 | YAMLToJs(node.diagnostics), | |
@@ -185,11 +187,11 @@ class FileTest extends Test { | |||
| 185 | 187 | // Ignore file top level diagnostics | |
| 186 | 188 | break; | |
| 187 | 189 | } | |
| 188 | - this.reporter.diagnostic(nesting, node.comment); | ||
| 190 | + this.reporter.diagnostic(nesting, this.name, node.comment); | ||
| 189 | 191 | break; | |
| 190 | 192 | ||
| 191 | 193 | case TokenKind.UNKNOWN: | |
| 192 | - this.reporter.diagnostic(nesting, node.value); | ||
| 194 | + this.reporter.diagnostic(nesting, this.name, node.value); | ||
| 193 | 195 | break; | |
| 194 | 196 | } | |
| 195 | 197 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,7 @@ const testNamePatterns = testNamePatternFlag?.length > 0 ? | |||
| 74 | 74 | (re) => convertStringToRegExp(re, '--test-name-pattern') | |
| 75 | 75 | ) : null; | |
| 76 | 76 | const kShouldAbort = Symbol('kShouldAbort'); | |
| 77 | + const kFilename = process.argv?.[1]; | ||
| 77 | 78 | const kHookNames = ObjectSeal(['before', 'after', 'beforeEach', 'afterEach']); | |
| 78 | 79 | const kUnwrapErrors = new SafeSet() | |
| 79 | 80 | .add(kTestCodeFailure).add(kHookFailure) | |
@@ -632,19 +633,19 @@ class Test extends AsyncResource { | |||
| 632 | 633 | this.parent.processPendingSubtests(); | |
| 633 | 634 | } else if (!this.reported) { | |
| 634 | 635 | this.reported = true; | |
| 635 | - this.reporter.plan(this.nesting, this.subtests.length); | ||
| 636 | + this.reporter.plan(this.nesting, kFilename, this.subtests.length); | ||
| 636 | 637 | ||
| 637 | 638 | for (let i = 0; i < this.diagnostics.length; i++) { | |
| 638 | - this.reporter.diagnostic(this.nesting, this.diagnostics[i]); | ||
| 639 | + this.reporter.diagnostic(this.nesting, kFilename, this.diagnostics[i]); | ||
| 639 | 640 | } | |
| 640 | 641 | ||
| 641 | - this.reporter.diagnostic(this.nesting, `tests ${this.subtests.length}`); | ||
| 642 | - this.reporter.diagnostic(this.nesting, `pass ${counters.passed}`); | ||
| 643 | - this.reporter.diagnostic(this.nesting, `fail ${counters.failed}`); | ||
| 644 | - this.reporter.diagnostic(this.nesting, `cancelled ${counters.cancelled}`); | ||
| 645 | - this.reporter.diagnostic(this.nesting, `skipped ${counters.skipped}`); | ||
| 646 | - this.reporter.diagnostic(this.nesting, `todo ${counters.todo}`); | ||
| 647 | - this.reporter.diagnostic(this.nesting, `duration_ms ${this.#duration()}`); | ||
| 642 | + this.reporter.diagnostic(this.nesting, kFilename, `tests ${this.subtests.length}`); | ||
| 643 | + this.reporter.diagnostic(this.nesting, kFilename, `pass ${counters.passed}`); | ||
| 644 | + this.reporter.diagnostic(this.nesting, kFilename, `fail ${counters.failed}`); | ||
| 645 | + this.reporter.diagnostic(this.nesting, kFilename, `cancelled ${counters.cancelled}`); | ||
| 646 | + this.reporter.diagnostic(this.nesting, kFilename, `skipped ${counters.skipped}`); | ||
| 647 | + this.reporter.diagnostic(this.nesting, kFilename, `todo ${counters.todo}`); | ||
| 648 | + this.reporter.diagnostic(this.nesting, kFilename, `duration_ms ${this.#duration()}`); | ||
| 648 | 649 | this.reporter.push(null); | |
| 649 | 650 | } | |
| 650 | 651 | } | |
@@ -680,7 +681,7 @@ class Test extends AsyncResource { | |||
| 680 | 681 | ||
| 681 | 682 | report() { | |
| 682 | 683 | if (this.subtests.length > 0) { | |
| 683 | - this.reporter.plan(this.subtests[0].nesting, this.subtests.length); | ||
| 684 | + this.reporter.plan(this.subtests[0].nesting, kFilename, this.subtests.length); | ||
| 684 | 685 | } else { | |
| 685 | 686 | this.reportStarted(); | |
| 686 | 687 | } | |
@@ -694,14 +695,14 @@ class Test extends AsyncResource { | |||
| 694 | 695 | } | |
| 695 | 696 | ||
| 696 | 697 | if (this.passed) { | |
| 697 | - this.reporter.ok(this.nesting, this.testNumber, this.name, details, directive); | ||
| 698 | + this.reporter.ok(this.nesting, kFilename, this.testNumber, this.name, details, directive); | ||
| 698 | 699 | } else { | |
| 699 | 700 | details.error = this.error; | |
| 700 | - this.reporter.fail(this.nesting, this.testNumber, this.name, details, directive); | ||
| 701 | + this.reporter.fail(this.nesting, kFilename, this.testNumber, this.name, details, directive); | ||
| 701 | 702 | } | |
| 702 | 703 | ||
| 703 | 704 | for (let i = 0; i < this.diagnostics.length; i++) { | |
| 704 | - this.reporter.diagnostic(this.nesting, this.diagnostics[i]); | ||
| 705 | + this.reporter.diagnostic(this.nesting, kFilename, this.diagnostics[i]); | ||
| 705 | 706 | } | |
| 706 | 707 | } | |
| 707 | 708 | ||
@@ -711,7 +712,7 @@ class Test extends AsyncResource { | |||
| 711 | 712 | } | |
| 712 | 713 | this.#reportedSubtest = true; | |
| 713 | 714 | this.parent.reportStarted(); | |
| 714 | - this.reporter.start(this.nesting, this.name); | ||
| 715 | + this.reporter.start(this.nesting, kFilename, this.name); | ||
| 715 | 716 | } | |
| 716 | 717 | } | |
| 717 | 718 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,16 +27,16 @@ class TestsStream extends Readable { | |||
| 27 | 27 | } | |
| 28 | 28 | } | |
| 29 | 29 | ||
| 30 | - fail(nesting, testNumber, name, details, directive) { | ||
| 31 | - this.#emit('test:fail', { __proto__: null, name, nesting, testNumber, details, ...directive }); | ||
| 30 | + fail(nesting, file, testNumber, name, details, directive) { | ||
| 31 | + this.#emit('test:fail', { __proto__: null, name, nesting, file, testNumber, details, ...directive }); | ||
| 32 | 32 | } | |
| 33 | 33 | ||
| 34 | - ok(nesting, testNumber, name, details, directive) { | ||
| 35 | - this.#emit('test:pass', { __proto__: null, name, nesting, testNumber, details, ...directive }); | ||
| 34 | + ok(nesting, file, testNumber, name, details, directive) { | ||
| 35 | + this.#emit('test:pass', { __proto__: null, name, nesting, file, testNumber, details, ...directive }); | ||
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | - plan(nesting, count) { | ||
| 39 | - this.#emit('test:plan', { __proto__: null, nesting, count }); | ||
| 38 | + plan(nesting, file, count) { | ||
| 39 | + this.#emit('test:plan', { __proto__: null, nesting, file, count }); | ||
| 40 | 40 | } | |
| 41 | 41 | ||
| 42 | 42 | getSkip(reason = undefined) { | |
@@ -47,12 +47,12 @@ class TestsStream extends Readable { | |||
| 47 | 47 | return { __proto__: null, todo: reason ?? true }; | |
| 48 | 48 | } | |
| 49 | 49 | ||
| 50 | - start(nesting, name) { | ||
| 51 | - this.#emit('test:start', { __proto__: null, nesting, name }); | ||
| 50 | + start(nesting, file, name) { | ||
| 51 | + this.#emit('test:start', { __proto__: null, nesting, file, name }); | ||
| 52 | 52 | } | |
| 53 | 53 | ||
| 54 | - diagnostic(nesting, message) { | ||
| 55 | - this.#emit('test:diagnostic', { __proto__: null, nesting, message }); | ||
| 54 | + diagnostic(nesting, file, message) { | ||
| 55 | + this.#emit('test:diagnostic', { __proto__: null, nesting, file, message }); | ||
| 56 | 56 | } | |
| 57 | 57 | ||
| 58 | 58 | #emit(type, data) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,12 @@ | |||
| 1 | + const assert = require('assert'); | ||
| 2 | + const path = require('path'); | ||
| 3 | + | ||
| 1 | 4 | module.exports = async function * customReporter(source) { | |
| 2 | 5 | const counters = {}; | |
| 3 | 6 | for await (const event of source) { | |
| 7 | + if (event.data.file) { | ||
| 8 | + assert.strictEqual(event.data.file, path.resolve(__dirname, '../reporters.js')); | ||
| 9 | + } | ||
| 4 | 10 | counters[event.type] = (counters[event.type] ?? 0) + 1; | |
| 5 | 11 | } | |
| 6 | 12 | yield "custom.js "; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments