Skip to content

Commit

Permalink
fix Prototype-polluting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jul 27, 2024
1 parent d8d7351 commit 7cfbdd2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
30 changes: 14 additions & 16 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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;
};

// ========================================================================================================
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 10 additions & 8 deletions lib/istanbul/istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions lib/v8/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7cfbdd2

Please sign in to comment.