2020-04-08 14:13:33 +05:30
|
|
|
const { create } = require('istanbul-reports');
|
|
|
|
const { createCoverageMap } = require('istanbul-lib-coverage');
|
|
|
|
const { createContext } = require('istanbul-lib-report');
|
|
|
|
const { resolve } = require('path');
|
|
|
|
const { sync } = require('glob');
|
|
|
|
|
|
|
|
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) => {
|
2020-04-08 14:13:33 +05:30
|
|
|
const normalizedReport = Object.assign({}, report);
|
|
|
|
Object.entries(normalizedReport).forEach(([k, v]) => {
|
|
|
|
if (v.data) normalizedReport[k] = v.data;
|
|
|
|
});
|
|
|
|
return normalizedReport;
|
|
|
|
};
|
|
|
|
|
|
|
|
reportFiles
|
2021-03-08 18:12:59 +05:30
|
|
|
.map((reportFile) => 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
|
|
|
|
|
|
|
const context = createContext({ coverageMap: coverageMap, dir: 'coverage-frontend' });
|
|
|
|
|
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);
|
|
|
|
});
|