Skip to content

Commit

Permalink
added version to coverageResults
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jul 21, 2024
1 parent 312e8c4 commit d630cc1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,11 @@ declare namespace MCR {
}
}


export type CoverageResults = {
type: "v8" | "istanbul";
reportPath: string;
version: string;
name: string;
watermarks: Watermarks;
summary: CoverageSummary;
Expand Down
1 change: 1 addition & 0 deletions lib/istanbul/istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const saveIstanbulReports = (coverageData, fileSources, options) => {
const coverageResults = {
type: 'istanbul',
reportPath,
version: Util.version,
name: options.name,
watermarks: contextOptions.watermarks,
// summary and files
Expand Down
16 changes: 13 additions & 3 deletions lib/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const CG = require('console-grid');
const Share = require('../platform/share.js');
const request = require('./request.js');
const { deflateSync } = require('lz-utils');

const version = require('../../package.json').version;
const acornWalk = require('acorn-walk');

const { findUpSync, supportsColor } = require('../packages/monocart-coverage-vendor.js');
Expand All @@ -21,6 +21,8 @@ if (!supportsColor.stdout) {
}

const Util = {
version,

... Share,

EC,
Expand Down Expand Up @@ -229,9 +231,18 @@ const Util = {
outputDir,
htmlFile,

saveReportPath,

reportDataFile
} = options;

// save path
const htmlPath = path.resolve(outputDir, htmlFile);
const reportPath = Util.relativePath(htmlPath);
if (saveReportPath) {
reportData[saveReportPath] = reportPath;
}

// report data
const reportDataCompressed = deflateSync(JSON.stringify(reportData));
const reportDataStr = `window.reportData = '${reportDataCompressed}';`;
Expand Down Expand Up @@ -277,7 +288,6 @@ const Util = {
}

// html
const htmlPath = path.resolve(outputDir, htmlFile);
const template = Util.getTemplate(path.resolve(__dirname, '../default/template.html'));
const html = Util.replace(template, {
title: reportData.title,
Expand All @@ -286,7 +296,7 @@ const Util = {

await Util.writeFile(htmlPath, html);

return Util.relativePath(htmlPath);
return reportPath;
},

runCustomReporter: async (reportName, reportData, reportOptions, globalOptions) => {
Expand Down
17 changes: 14 additions & 3 deletions lib/v8/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const {
resolveAnonymousUrl, normalizeSourcePath, getSourcePathReplacer
} = require('../utils/source-path.js');
const { collectSourceMaps } = require('../converter/collect-source-maps.js');
const version = require('../../package.json').version;

const getWrapperSource = (offset, source) => {
// NO \n because it break line number in mappings
Expand Down Expand Up @@ -321,8 +320,12 @@ const handleV8JsonReport = async (reportData, reportOptions, options) => {

// console.log(mergedOptions);
const jsonPath = path.resolve(options.outputDir, v8JsonOptions.outputFile);
const reportPath = Util.relativePath(jsonPath);

reportData.reportPath = reportPath;

await Util.writeFile(jsonPath, JSON.stringify(reportData));
return Util.relativePath(jsonPath);
return reportPath;
};


Expand Down Expand Up @@ -367,9 +370,12 @@ const handleV8HtmlReport = async (reportData, reportOptions, options) => {
outputDir,
htmlFile,

saveReportPath: 'reportPath',

reportDataFile: 'coverage-data.js'
};

// compress json data for html
const htmlPath = await Util.saveHtmlReport(htmlOptions);

return htmlPath;
Expand All @@ -389,8 +395,11 @@ const saveV8Report = async (v8list, options, istanbulReportPath) => {
const summary = getV8Summary(v8list, watermarks);

const reportData = {
type: 'v8',
// override with saved file path
reportPath: '',
version: Util.version,
name: options.name,
version,
watermarks,
summary,
files: v8list
Expand Down Expand Up @@ -431,7 +440,9 @@ const saveV8Report = async (v8list, options, istanbulReportPath) => {

const coverageResults = {
type: 'v8',
// html or json
reportPath,
version: Util.version,
name: options.name,
watermarks,
summary,
Expand Down
2 changes: 1 addition & 1 deletion test/test-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const generate = async () => {
console.log('generate istanbul coverage reports ...');

const coverageResults = await MCR(coverageOptions).generate();

console.log('istanbul coverageResults', Object.keys(coverageResults));
console.log('istanbul coverage reportPath', EC.magenta(coverageResults.reportPath));
};

Expand Down
1 change: 1 addition & 0 deletions test/test-v8-and-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const generate = async () => {
console.log('generate v8-and-istanbul coverage reports ...');
// to istanbul
const coverageResults = await MCR(multipleReportsOptions).generate();
console.log('v8-to-istanbul coverageResults', Object.keys(coverageResults));
console.log('reportPath', EC.magenta(coverageResults.reportPath));
};

Expand Down
1 change: 1 addition & 0 deletions test/test-v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ const generate = async () => {
console.log('generate v8 coverage reports ...');

const coverageResults = await MCR(coverageOptions).generate();
console.log('v8 coverageResults', Object.keys(coverageResults));
console.log('v8 coverage reportPath', EC.magenta(coverageResults.reportPath));
};

Expand Down

0 comments on commit d630cc1

Please sign in to comment.