@web/test-runner
Version:
Test runner for web applications
36 lines • 1.77 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCodeCoverage = getCodeCoverage;
const nanocolors_1 = require("nanocolors");
const path_1 = __importDefault(require("path"));
const coverageTypes = [
'lines',
'statements',
'branches',
'functions',
];
function getCodeCoverage(testCoverage, watch, coverageConfig) {
const entries = [];
const coverageSum = coverageTypes.reduce((all, type) => all + testCoverage.summary[type].pct, 0);
const avgCoverage = Math.round((coverageSum * 100) / 4) / 100;
if (!Number.isNaN(avgCoverage)) {
const percent = `${avgCoverage} %`;
entries.push(`Code coverage: ${(0, nanocolors_1.bold)(testCoverage.passed ? (0, nanocolors_1.green)(percent) : (0, nanocolors_1.red)(percent))}`);
}
if (!testCoverage.passed && coverageConfig.threshold) {
coverageTypes.forEach(type => {
if (testCoverage.summary[type].pct < coverageConfig.threshold[type]) {
entries.push(`Coverage for ${(0, nanocolors_1.bold)(type)} failed with ${(0, nanocolors_1.bold)((0, nanocolors_1.red)(`${testCoverage.summary[type].pct} %`))} compared to configured ${(0, nanocolors_1.bold)(`${coverageConfig.threshold[type]} %`)}`);
}
});
}
if (!watch && coverageConfig.report && coverageConfig.reporters?.includes('lcov')) {
entries.push(`View full coverage report at ${(0, nanocolors_1.underline)(path_1.default.join(coverageConfig.reportDir ?? '', 'lcov-report', 'index.html'))}`);
}
entries.push('');
return entries;
}
//# sourceMappingURL=getCodeCoverage.js.map