| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0885546 commit 1eda87c
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3016,6 +3016,11 @@ defined. The corresponding declaration ordered event is `'test:start'`. | |||
| 3016 | 3016 | `undefined` if the test was run through the REPL. | |
| 3017 | 3017 | * `message` {string} The diagnostic message. | |
| 3018 | 3018 | * `nesting` {number} The nesting level of the test. | |
| 3019 | + * `level` {string} The severity level of the diagnostic message. | ||
| 3020 | + Possible values are: | ||
| 3021 | + * `'info'`: Informational messages. | ||
| 3022 | + * `'warn'`: Warnings. | ||
| 3023 | + * `'error'`: Errors. | ||
| 3019 | 3024 | ||
| 3020 | 3025 | Emitted when [`context.diagnostic`][] is called. | |
| 3021 | 3026 | This event is guaranteed to be emitted in the same order as the tests are | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -94,8 +94,10 @@ class SpecReporter extends Transform { | |||
| 94 | 94 | case 'test:stderr': | |
| 95 | 95 | case 'test:stdout': | |
| 96 | 96 | return data.message; | |
| 97 | - case 'test:diagnostic': | ||
| 98 | - return `${reporterColorMap[type]}${indent(data.nesting)}${reporterUnicodeSymbolMap[type]}${data.message}${colors.white}\n`; | ||
| 97 | + case 'test:diagnostic':{ | ||
| 98 | + const diagnosticColor = reporterColorMap[data.level] || reporterColorMap['test:diagnostic']; | ||
| 99 | + return `${diagnosticColor}${indent(data.nesting)}${reporterUnicodeSymbolMap[type]}${data.message}${colors.white}\n`; | ||
| 100 | + } | ||
| 99 | 101 | case 'test:coverage': | |
| 100 | 102 | return getCoverageReport(indent(data.nesting), data.summary, | |
| 101 | 103 | reporterUnicodeSymbolMap['test:coverage'], colors.blue, true); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,6 +37,15 @@ const reporterColorMap = { | |||
| 37 | 37 | get 'test:diagnostic'() { | |
| 38 | 38 | return colors.blue; | |
| 39 | 39 | }, | |
| 40 | + get 'info'() { | ||
| 41 | + return colors.blue; | ||
| 42 | + }, | ||
| 43 | + get 'warn'() { | ||
| 44 | + return colors.yellow; | ||
| 45 | + }, | ||
| 46 | + get 'error'() { | ||
| 47 | + return colors.red; | ||
| 48 | + }, | ||
| 40 | 49 | }; | |
| 41 | 50 | ||
| 42 | 51 | function indent(nesting) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1235,7 +1235,7 @@ class Test extends AsyncResource { | |||
| 1235 | 1235 | if (actual < threshold) { | |
| 1236 | 1236 | harness.success = false; | |
| 1237 | 1237 | process.exitCode = kGenericUserError; | |
| 1238 | - reporter.diagnostic(nesting, loc, `Error: ${NumberPrototypeToFixed(actual, 2)}% ${name} coverage does not meet threshold of ${threshold}%.`); | ||
| 1238 | + reporter.diagnostic(nesting, loc, `Error: ${NumberPrototypeToFixed(actual, 2)}% ${name} coverage does not meet threshold of ${threshold}%.`, 'error'); | ||
| 1239 | 1239 | } | |
| 1240 | 1240 | } | |
| 1241 | 1241 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,11 +116,12 @@ class TestsStream extends Readable { | |||
| 116 | 116 | }); | |
| 117 | 117 | } | |
| 118 | 118 | ||
| 119 | - diagnostic(nesting, loc, message) { | ||
| 119 | + diagnostic(nesting, loc, message, level = 'info') { | ||
| 120 | 120 | this[kEmitMessage]('test:diagnostic', { | |
| 121 | 121 | __proto__: null, | |
| 122 | 122 | nesting, | |
| 123 | 123 | message, | |
| 124 | + level, | ||
| 124 | 125 | ...loc, | |
| 125 | 126 | }); | |
| 126 | 127 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,6 +90,26 @@ for (const coverage of coverages) { | |||
| 90 | 90 | assert(!findCoverageFileForPid(result.pid)); | |
| 91 | 91 | }); | |
| 92 | 92 | ||
| 93 | + test(`test failing ${coverage.flag} with red color`, () => { | ||
| 94 | + const result = spawnSync(process.execPath, [ | ||
| 95 | + '--test', | ||
| 96 | + '--experimental-test-coverage', | ||
| 97 | + '--test-coverage-exclude=!test/**', | ||
| 98 | + `${coverage.flag}=99`, | ||
| 99 | + '--test-reporter', 'spec', | ||
| 100 | + fixture, | ||
| 101 | + ], { | ||
| 102 | + env: { ...process.env, FORCE_COLOR: '3' }, | ||
| 103 | + }); | ||
| 104 | + | ||
| 105 | + const stdout = result.stdout.toString(); | ||
| 106 | + // eslint-disable-next-line no-control-regex | ||
| 107 | + const redColorRegex = /\u001b\[31mℹ Error: \d{2}\.\d{2}% \w+ coverage does not meet threshold of 99%/; | ||
| 108 | + assert.match(stdout, redColorRegex, 'Expected red color code not found in diagnostic message'); | ||
| 109 | + assert.strictEqual(result.status, 1); | ||
| 110 | + assert(!findCoverageFileForPid(result.pid)); | ||
| 111 | + }); | ||
| 112 | + | ||
| 93 | 113 | test(`test failing ${coverage.flag}`, () => { | |
| 94 | 114 | const result = spawnSync(process.execPath, [ | |
| 95 | 115 | '--test', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,24 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { | |||
| 33 | 33 | for await (const _ of stream); | |
| 34 | 34 | }); | |
| 35 | 35 | ||
| 36 | + it('should emit diagnostic events with level parameter', async () => { | ||
| 37 | + const diagnosticEvents = []; | ||
| 38 | + | ||
| 39 | + const stream = run({ | ||
| 40 | + files: [join(testFixtures, 'coverage.js')], | ||
| 41 | + reporter: 'spec', | ||
| 42 | + }); | ||
| 43 | + | ||
| 44 | + stream.on('test:diagnostic', (event) => { | ||
| 45 | + diagnosticEvents.push(event); | ||
| 46 | + }); | ||
| 47 | + // eslint-disable-next-line no-unused-vars | ||
| 48 | + for await (const _ of stream); | ||
| 49 | + assert(diagnosticEvents.length > 0, 'No diagnostic events were emitted'); | ||
| 50 | + const infoEvent = diagnosticEvents.find((e) => e.level === 'info'); | ||
| 51 | + assert(infoEvent, 'No diagnostic events with level "info" were emitted'); | ||
| 52 | + }); | ||
| 53 | + | ||
| 36 | 54 | const argPrintingFile = join(testFixtures, 'print-arguments.js'); | |
| 37 | 55 | it('should allow custom arguments via execArgv', async () => { | |
| 38 | 56 | const result = await run({ files: [argPrintingFile], execArgv: ['-p', '"Printed"'] }).compose(spec).toArray(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments