GeezerVison is showing github.com — test_runner: print coverage and diagnostic info with dot reporter · nodejs/node@2df1681
File treeExpand file treeCollapse file tree Open diff view settings lib/internal/test_runner/reporter fixtures/test-runner/output
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/reporter/dot.js +24-1Lines changed: 24 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,12 +4,19 @@ const { | 4 | 4 | MathMax, | 5 | 5 | } = primordials; | 6 | 6 | const colors = require('internal/util/colors'); | 7 | | -const { formatTestReport } = require('internal/test_runner/reporter/utils'); | | 7 | +const { getCoverageReport } = require('internal/test_runner/utils'); | | 8 | +const { | | 9 | + formatTestReport, | | 10 | + reporterColorMap, | | 11 | + reporterUnicodeSymbolMap, | | 12 | +} = require('internal/test_runner/reporter/utils'); | 8 | 13 |
| 9 | 14 | module.exports = async function* dot(source) { | 10 | 15 | let count = 0; | 11 | 16 | let columns = getLineLength(); | 12 | 17 | const failedTests = []; | | 18 | + const diagnostics = []; | | 19 | + let coverage; | 13 | 20 | for await (const { type, data } of source) { | 14 | 21 | if (type === 'test:pass') { | 15 | 22 | yield `${colors.green}.${colors.reset}`; | @@ -25,8 +32,24 @@ module.exports = async function* dot(source) { | 25 | 32 | columns = getLineLength(); | 26 | 33 | count = 0; | 27 | 34 | } | | 35 | + if (type === 'test:diagnostic' && data.level === 'error') { | | 36 | + ArrayPrototypePush(diagnostics, data); | | 37 | + } | | 38 | + if (type === 'test:coverage') { | | 39 | + coverage = data; | | 40 | + } | 28 | 41 | } | 29 | 42 | yield '\n'; | | 43 | + if (diagnostics.length > 0) { | | 44 | + for (const diagnostic of diagnostics) { | | 45 | + const color = reporterColorMap[diagnostic.level] || reporterColorMap['test:diagnostic']; | | 46 | + yield `${color}${reporterUnicodeSymbolMap['test:diagnostic']}${diagnostic.message}${colors.white}\n`; | | 47 | + } | | 48 | + if (coverage) { | | 49 | + yield getCoverageReport('', coverage.summary, | | 50 | + reporterUnicodeSymbolMap['test:coverage'], colors.blue, true); | | 51 | + } | | 52 | + } | 30 | 53 | if (failedTests.length > 0) { | 31 | 54 | yield `\n${colors.red}Failed tests:${colors.white}\n\n`; | 32 | 55 | for (const test of failedTests) { | |
Collapse file Copy file name to clipboard +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +require('../../../common'); | | 3 | +const fixtures = require('../../../common/fixtures'); | | 4 | +const spawn = require('node:child_process').spawn; | | 5 | + | | 6 | +spawn( | | 7 | + process.execPath, | | 8 | + [ | | 9 | + '--no-warnings', | | 10 | + '--experimental-test-coverage', | | 11 | + '--test-coverage-exclude=!test/**', | | 12 | + '--test-coverage-lines=99', | | 13 | + '--test-reporter', 'dot', | | 14 | + fixtures.path('test-runner/coverage.js'), | | 15 | + ], | | 16 | + { stdio: 'inherit' }, | | 17 | +); |
Collapse file Copy file name to clipboard +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +invalid tap output | | 2 | +. | | 3 | +ℹ Error: 78.35% line coverage does not meet threshold of 99%. | | 4 | +ℹ start of coverage report | | 5 | +ℹ -------------------------------------------------------------------------------------------- | | 6 | +ℹ file | line % | branch % | funcs % | uncovered lines | | 7 | +ℹ -------------------------------------------------------------------------------------------- | | 8 | +ℹ test | | | | | | 9 | +ℹ fixtures | | | | | | 10 | +ℹ test-runner | | | | | | 11 | +ℹ coverage.js | 78.65 | 38.46 | 60.00 | 12-13 16-22 27 39 43-44 61-62 66-67 71-72 | | 12 | +ℹ invalid-tap.js | 100.00 | 100.00 | 100.00 | | | 13 | +ℹ v8-coverage | | | | | | 14 | +ℹ throw.js | 71.43 | 50.00 | 100.00 | 5-6 | | 15 | +ℹ -------------------------------------------------------------------------------------------- | | 16 | +ℹ all files | 78.35 | 43.75 | 60.00 | | | 17 | +ℹ -------------------------------------------------------------------------------------------- | | 18 | +ℹ end of coverage report |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-coverage-thresholds.js +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -170,4 +170,25 @@ for (const coverage of coverages) { | 170 | 170 | assert.strictEqual(result.status, 1); | 171 | 171 | assert(!findCoverageFileForPid(result.pid)); | 172 | 172 | }); | | 173 | + | | 174 | + test(`test failing ${coverage.flag} with dot reporter`, () => { | | 175 | + const result = spawnSync(process.execPath, [ | | 176 | + '--test', | | 177 | + '--experimental-test-coverage', | | 178 | + '--test-coverage-exclude=!test/**', | | 179 | + `${coverage.flag}=99`, | | 180 | + '--test-reporter', 'dot', | | 181 | + fixture, | | 182 | + ]); | | 183 | + | | 184 | + const stdout = result.stdout.toString(); | | 185 | + assert.match( | | 186 | + stdout, | | 187 | + RegExp(`Error: ${coverage.actual.toFixed(2)}% ${coverage.name} coverage does not meet threshold of 99%`) | | 188 | + ); | | 189 | + assert.match(stdout, /start of coverage report/); | | 190 | + assert.match(stdout, /end of coverage report/); | | 191 | + assert.strictEqual(result.status, 1); | | 192 | + assert(!findCoverageFileForPid(result.pid)); | | 193 | + }); | 173 | 194 | } |
Collapse file Copy file name to clipboard +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Test that the output of test-runner/output/dot_reporter_coverage_threshold.js matches | | 2 | +// test-runner/output/dot_reporter_coverage_threshold.snapshot | | 3 | +import * as common from '../common/index.mjs'; | | 4 | +import * as fixtures from '../common/fixtures.mjs'; | | 5 | +import { spawnAndAssert, specTransform, ensureCwdIsProjectRoot } from '../common/assertSnapshot.js'; | | 6 | + | | 7 | +if (!process.features.inspector) { | | 8 | + common.skip('inspector support required'); | | 9 | +} | | 10 | + | | 11 | +ensureCwdIsProjectRoot(); | | 12 | +await spawnAndAssert( | | 13 | + fixtures.path('test-runner/output/dot_reporter_coverage_threshold.js'), | | 14 | + specTransform, | | 15 | +); |
|