diff --git a/lib/generate.js b/lib/generate.js index 3d9a34f5..ddb87adc 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -110,7 +110,7 @@ const getReportGroup = (reports, lcov, dataType) => { } // group v8 and istanbul - const reportGroup = {}; + const groupMap = new Map(); Object.keys(reportMap).forEach((k) => { const options = reportMap[k]; @@ -120,24 +120,24 @@ const getReportGroup = (reports, lcov, dataType) => { type = options.type || 'v8'; } - let group = reportGroup[type]; + let group = groupMap.get(type); if (!group) { - group = {}; - reportGroup[type] = group; + group = new Map(); + groupMap.set(type, group); } - group[k] = options; + group.set(k, options); }); // requires a default istanbul report if data is istanbul - if (dataType === 'istanbul' && !reportGroup.istanbul) { - reportGroup.istanbul = { - html: {} - }; + if (dataType === 'istanbul' && !groupMap.has('istanbul')) { + const istanbulGroup = new Map(); + istanbulGroup.set('html', {}); + groupMap.set('istanbul', istanbulGroup); } - return reportGroup; + return groupMap; }; // ======================================================================================================== @@ -146,7 +146,7 @@ const getReportGroup = (reports, lcov, dataType) => { const generateV8ListReports = async (v8list, coverageData, fileSources, options) => { let istanbulReportPath; // v8 to istanbul reports - if (options.reportGroup.istanbul) { + if (options.reportGroup.has('istanbul')) { const istanbulCoverageResults = await saveIstanbulReports(coverageData, fileSources, options); istanbulReportPath = istanbulCoverageResults.reportPath; } @@ -200,11 +200,9 @@ const generateCoverageReports = async (dataList, sourceCache, options) => { // [ 'type', 'reportPath', 'name', 'watermarks', 'summary', 'files' ] // console.log(Object.keys(coverageResults)); - const bothGroup = options.reportGroup.both; - if (bothGroup) { - const bothReports = Object.keys(bothGroup); - for (const reportName of bothReports) { - const reportOptions = bothGroup[reportName]; + if (options.reportGroup.has('both')) { + const bothGroup = options.reportGroup.get('both'); + for (const [reportName, reportOptions] of bothGroup) { const builtInHandler = bothBuiltInReports[reportName]; const t1 = Date.now(); if (builtInHandler) { diff --git a/lib/istanbul/istanbul.js b/lib/istanbul/istanbul.js index 53a04a7e..10214de9 100644 --- a/lib/istanbul/istanbul.js +++ b/lib/istanbul/istanbul.js @@ -87,14 +87,16 @@ const saveIstanbulReports = (coverageData, fileSources, options) => { // create a context for report generation const context = istanbulLibReport.createContext(contextOptions); - const istanbulGroup = options.reportGroup.istanbul; - Object.keys(istanbulGroup).forEach((reportName) => { - const t1 = Date.now(); - const reportOptions = istanbulGroup[reportName]; - const report = istanbulReports.create(reportName, reportOptions); - report.execute(context); - Util.logTime(`┌ [generate] saved report: ${reportName}`, t1); - }); + const istanbulGroup = options.reportGroup.get('istanbul'); + // already has + if (istanbulGroup) { + for (const [reportName, reportOptions] of istanbulGroup) { + const t1 = Date.now(); + const report = istanbulReports.create(reportName, reportOptions); + report.execute(context); + Util.logTime(`┌ [generate] saved report: ${reportName}`, t1); + } + } // add watermarks and color const coverageReport = new IstanbulSummary(); diff --git a/lib/v8/v8.js b/lib/v8/v8.js index 9a76f16a..a12671fa 100644 --- a/lib/v8/v8.js +++ b/lib/v8/v8.js @@ -405,12 +405,10 @@ const saveV8Report = async (v8list, options, istanbulReportPath) => { }; const outputs = {}; - const v8Group = options.reportGroup.v8; + const v8Group = options.reportGroup.get('v8'); // could be no v8 only reports, but have `both` data reports if (v8Group) { - const v8Reports = Object.keys(v8Group); - for (const reportName of v8Reports) { - const reportOptions = v8Group[reportName]; + for (const [reportName, reportOptions] of v8Group) { const buildInHandler = buildInV8Reports[reportName]; const t1 = Date.now(); if (buildInHandler) {