Skip to content

Commit

Permalink
test: add test for spec reporter red color output
Browse files Browse the repository at this point in the history
Add a test in  to verify that
the diagnostic error messages about unmet coverage thresholds
are displayed in red when using the spec reporter.

Fixes: nodejs#55922
  • Loading branch information
hpatel292-seneca committed Nov 27, 2024
1 parent b490d9d commit 3e4d5e6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/parallel/test-runner-coverage-thresholds.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ for (const coverage of coverages) {
assert(!findCoverageFileForPid(result.pid));
});

test(`test failing ${coverage.flag} with red color`, () => {
const result = spawnSync(process.execPath, [
'--test',
'--experimental-test-coverage',
`${coverage.flag}=99`,
'--test-reporter', 'spec',
fixture,
], {
env: { ...process.env, FORCE_COLOR: '3' },
});

const stdout = result.stdout.toString();
const redColorRegex = /\u001b\[31mℹ Error: \d{2}\.\d{2}% \w+ coverage does not meet threshold of 99%/;
assert.match(stdout, redColorRegex, 'Expected red color code not found in diagnostic message');
assert.strictEqual(result.status, 1);
assert(!findCoverageFileForPid(result.pid));
});

test(`test failing ${coverage.flag}`, () => {
const result = spawnSync(process.execPath, [
'--test',
Expand Down

0 comments on commit 3e4d5e6

Please sign in to comment.