| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -510,6 +510,10 @@ test('spies on an object method', (t) => { | |||
| 510 | 510 | ||
| 511 | 511 | <!-- YAML | |
| 512 | 512 | added: v18.15.0 | |
| 513 | + changes: | ||
| 514 | + - version: REPLACEME | ||
| 515 | + pr-url: https://github.com/nodejs/node/pull/47238 | ||
| 516 | + description: Reporters are now exposed at `node:test/reporters`. | ||
| 513 | 517 | --> | |
| 514 | 518 | ||
| 515 | 519 | The `node:test` module supports passing [`--test-reporter`][] | |
@@ -531,6 +535,16 @@ The following built-reporters are supported: | |||
| 531 | 535 | When `stdout` is a [TTY][], the `spec` reporter is used by default. | |
| 532 | 536 | Otherwise, the `tap` reporter is used by default. | |
| 533 | 537 | ||
| 538 | + The reporters are available via the `node:test/reporters` module: | ||
| 539 | + | ||
| 540 | + ```mjs | ||
| 541 | + import { tap, spec, dot } from 'node:test/reporters'; | ||
| 542 | + ``` | ||
| 543 | + | ||
| 544 | + ```cjs | ||
| 545 | + const { tap, spec, dot } = require('node:test/reporters'); | ||
| 546 | + ``` | ||
| 547 | + | ||
| 534 | 548 | ### Custom reporters | |
| 535 | 549 | ||
| 536 | 550 | [`--test-reporter`][] can be used to specify a path to custom reporter. | |
@@ -722,8 +736,20 @@ added: v18.9.0 | |||
| 722 | 736 | **Default:** `undefined`. | |
| 723 | 737 | * Returns: {TestsStream} | |
| 724 | 738 | ||
| 725 | - ```js | ||
| 739 | + ```mjs | ||
| 740 | + import { tap } from 'node:test/reporters'; | ||
| 741 | + import process from 'node:process'; | ||
| 742 | + | ||
| 743 | + run({ files: [path.resolve('./tests/test.js')] }) | ||
| 744 | + .compose(tap) | ||
| 745 | + .pipe(process.stdout); | ||
| 746 | + ``` | ||
| 747 | + | ||
| 748 | + ```cjs | ||
| 749 | + const { tap } = require('node:test/reporters'); | ||
| 750 | + | ||
| 726 | 751 | run({ files: [path.resolve('./tests/test.js')] }) | |
| 752 | + .compose(tap) | ||
| 727 | 753 | .pipe(process.stdout); | |
| 728 | 754 | ``` | |
| 729 | 755 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,38 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const { ObjectDefineProperties } = primordials; | ||
| 4 | + | ||
| 5 | + let dot; | ||
| 6 | + let spec; | ||
| 7 | + let tap; | ||
| 8 | + | ||
| 9 | + ObjectDefineProperties(module.exports, { | ||
| 10 | + __proto__: null, | ||
| 11 | + dot: { | ||
| 12 | + __proto__: null, | ||
| 13 | + configurable: true, | ||
| 14 | + enumerable: true, | ||
| 15 | + get() { | ||
| 16 | + dot ??= require('internal/test_runner/reporter/dot'); | ||
| 17 | + return dot; | ||
| 18 | + }, | ||
| 19 | + }, | ||
| 20 | + spec: { | ||
| 21 | + __proto__: null, | ||
| 22 | + configurable: true, | ||
| 23 | + enumerable: true, | ||
| 24 | + get() { | ||
| 25 | + spec ??= require('internal/test_runner/reporter/spec'); | ||
| 26 | + return spec; | ||
| 27 | + }, | ||
| 28 | + }, | ||
| 29 | + tap: { | ||
| 30 | + __proto__: null, | ||
| 31 | + configurable: true, | ||
| 32 | + enumerable: true, | ||
| 33 | + get() { | ||
| 34 | + tap ??= require('internal/test_runner/reporter/tap'); | ||
| 35 | + return tap; | ||
| 36 | + }, | ||
| 37 | + }, | ||
| 38 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,7 @@ import * as common from '../common/index.mjs'; | |||
| 2 | 2 | import * as fixtures from '../common/fixtures.mjs'; | |
| 3 | 3 | import { join } from 'node:path'; | |
| 4 | 4 | import { describe, it, run } from 'node:test'; | |
| 5 | + import { dot, spec, tap } from 'node:test/reporters'; | ||
| 5 | 6 | import assert from 'node:assert'; | |
| 6 | 7 | ||
| 7 | 8 | const testFixtures = fixtures.path('test-runner'); | |
@@ -65,4 +66,39 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { | |||
| 65 | 66 | code: 'ERR_INVALID_ARG_TYPE' | |
| 66 | 67 | })); | |
| 67 | 68 | }); | |
| 69 | + | ||
| 70 | + it('should be piped with dot', async () => { | ||
| 71 | + const result = await run({ files: [join(testFixtures, 'test/random.cjs')] }).compose(dot).toArray(); | ||
| 72 | + assert.deepStrictEqual(result, [ | ||
| 73 | + '.', | ||
| 74 | + '\n', | ||
| 75 | + ]); | ||
| 76 | + }); | ||
| 77 | + | ||
| 78 | + it('should be piped with spec', async () => { | ||
| 79 | + const specReporter = new spec(); | ||
| 80 | + const result = await run({ files: [join(testFixtures, 'test/random.cjs')] }).compose(specReporter).toArray(); | ||
| 81 | + const stringResults = result.map((bfr) => bfr.toString()); | ||
| 82 | + assert.match(stringResults[0], /this should pass/); | ||
| 83 | + assert.match(stringResults[1], /tests 1/); | ||
| 84 | + assert.match(stringResults[1], /pass 1/); | ||
| 85 | + }); | ||
| 86 | + | ||
| 87 | + it('should be piped with tap', async () => { | ||
| 88 | + const result = await run({ files: [join(testFixtures, 'test/random.cjs')] }).compose(tap).toArray(); | ||
| 89 | + assert.strictEqual(result.length, 13); | ||
| 90 | + assert.strictEqual(result[0], 'TAP version 13\n'); | ||
| 91 | + assert.strictEqual(result[1], '# Subtest: this should pass\n'); | ||
| 92 | + assert.strictEqual(result[2], 'ok 1 - this should pass\n'); | ||
| 93 | + assert.match(result[3], /duration_ms: \d+\.?\d*/); | ||
| 94 | + assert.strictEqual(result[4], '1..1\n'); | ||
| 95 | + assert.strictEqual(result[5], '# tests 1\n'); | ||
| 96 | + assert.strictEqual(result[6], '# suites 0\n'); | ||
| 97 | + assert.strictEqual(result[7], '# pass 1\n'); | ||
| 98 | + assert.strictEqual(result[8], '# fail 0\n'); | ||
| 99 | + assert.strictEqual(result[9], '# cancelled 0\n'); | ||
| 100 | + assert.strictEqual(result[10], '# skipped 0\n'); | ||
| 101 | + assert.strictEqual(result[11], '# todo 0\n'); | ||
| 102 | + assert.match(result[12], /# duration_ms \d+\.?\d*/); | ||
| 103 | + }); | ||
| 68 | 104 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments