2021-05-14 11:10:35 -04:00
|
|
|
const { resolve } = require('path');
|
2021-03-10 10:09:11 -05:00
|
|
|
const { sync } = require('glob');
|
2020-02-26 04:08:47 -05:00
|
|
|
const { createCoverageMap } = require('istanbul-lib-coverage');
|
|
|
|
const { createContext } = require('istanbul-lib-report');
|
2021-03-10 10:09:11 -05:00
|
|
|
const { create } = require('istanbul-reports');
|
2020-02-26 04:08:47 -05:00
|
|
|
|
|
|
|
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
|
2020-12-23 16:10:24 -05:00
|
|
|
const normalizeReport = (report) => {
|
2021-03-10 10:09:11 -05:00
|
|
|
const normalizedReport = { ...report };
|
2020-02-26 04:08:47 -05:00
|
|
|
Object.entries(normalizedReport).forEach(([k, v]) => {
|
|
|
|
if (v.data) normalizedReport[k] = v.data;
|
|
|
|
});
|
|
|
|
return normalizedReport;
|
|
|
|
};
|
|
|
|
|
|
|
|
reportFiles
|
2021-03-10 10:09:11 -05:00
|
|
|
.map((reportFile) => {
|
|
|
|
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
|
|
return require(reportFile);
|
|
|
|
})
|
2020-02-26 04:08:47 -05:00
|
|
|
.map(normalizeReport)
|
2020-12-23 16:10:24 -05:00
|
|
|
.forEach((report) => coverageMap.merge(report));
|
2020-02-26 04:08:47 -05:00
|
|
|
|
2021-03-10 10:09:11 -05:00
|
|
|
const context = createContext({ coverageMap, dir: 'coverage-frontend' });
|
2020-02-26 04:08:47 -05:00
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
['json', 'lcov', 'text-summary', 'clover', 'cobertura'].forEach((reporter) => {
|
2020-02-26 04:08:47 -05:00
|
|
|
create(reporter, {}).execute(context);
|
|
|
|
});
|