summaryrefslogtreecommitdiff
path: root/scripts/frontend/merge_coverage_frontend.js
blob: 507695b45e53707f768c63712ff2baf6741113fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
const normalizeReport = report => {
  const normalizedReport = Object.assign({}, report);
  Object.entries(normalizedReport).forEach(([k, v]) => {
    if (v.data) normalizedReport[k] = v.data;
  });
  return normalizedReport;
};

reportFiles
  .map(reportFile => require(reportFile))
  .map(normalizeReport)
  .forEach(report => coverageMap.merge(report));

const context = createContext({ coverageMap: coverageMap, dir: 'coverage-frontend' });

['json', 'lcov', 'text-summary', 'clover'].forEach(reporter => {
  create(reporter, {}).execute(context);
});