debian-mirror-gitlab/scripts/frontend/merge_coverage_frontend.js

35 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-06-08 01:23:25 +05:30
const { resolve } = require('path');
2021-04-17 20:07:23 +05:30
const { sync } = require('glob');
2020-04-08 14:13:33 +05:30
const { createCoverageMap } = require('istanbul-lib-coverage');
const { createContext } = require('istanbul-lib-report');
2021-04-17 20:07:23 +05:30
const { create } = require('istanbul-reports');
2020-04-08 14:13:33 +05:30
const coverageMap = createCoverageMap();
const coverageDir = resolve(__dirname, '../../coverage-frontend');
const reportFiles = sync(`${coverageDir}/*/coverage-final.json`);
// Normalize coverage report generated by jest that has additional "data" key
// https://github.com/facebook/jest/issues/2418#issuecomment-423806659
2021-03-08 18:12:59 +05:30
const normalizeReport = (report) => {
2021-04-17 20:07:23 +05:30
const normalizedReport = { ...report };
2020-04-08 14:13:33 +05:30
Object.entries(normalizedReport).forEach(([k, v]) => {
if (v.data) normalizedReport[k] = v.data;
});
return normalizedReport;
};
reportFiles
2021-04-17 20:07:23 +05:30
.map((reportFile) => {
// eslint-disable-next-line global-require, import/no-dynamic-require
return require(reportFile);
})
2020-04-08 14:13:33 +05:30
.map(normalizeReport)
2021-03-08 18:12:59 +05:30
.forEach((report) => coverageMap.merge(report));
2020-04-08 14:13:33 +05:30
2021-04-17 20:07:23 +05:30
const context = createContext({ coverageMap, dir: 'coverage-frontend' });
2020-04-08 14:13:33 +05:30
2021-03-08 18:12:59 +05:30
['json', 'lcov', 'text-summary', 'clover', 'cobertura'].forEach((reporter) => {
2020-04-08 14:13:33 +05:30
create(reporter, {}).execute(context);
});