node/test/fixtures/test-runner/custom_reporters/coverage.mjs
Phil Nash 3a6a80a4e1
test_runner: report covered lines, functions and branches to reporters
This is a breaking change for the format of test:coverage events. But
the test coverage is still experimental, so I don't believe it requires
a semver-major bump.

Fixes https://github.com/nodejs/node/issues/49303

PR-URL: https://github.com/nodejs/node/pull/49320
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2023-08-30 20:22:45 +00:00

15 lines
374 B
JavaScript

import { Transform } from 'node:stream';
export default class CoverageReporter extends Transform {
constructor(options) {
super({ ...options, writableObjectMode: true });
}
_transform(event, _encoding, callback) {
if (event.type === 'test:coverage') {
callback(null, JSON.stringify(event.data, null, 2));
} else {
callback(null);
}
}
}