Skip to content

Commit

Permalink
refactor reports
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jul 27, 2024
1 parent ca90449 commit ab1dc47
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 66 deletions.
22 changes: 22 additions & 0 deletions lib/reports/v8-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const path = require('path');
const Util = require('../utils/util.js');

const v8JsonReport = async (reportData, reportOptions, options) => {
const v8JsonOptions = {
outputFile: 'coverage-report.json',
... reportOptions
};

// 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 reportPath;
};

module.exports = {
v8JsonReport
};
51 changes: 51 additions & 0 deletions lib/reports/v8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const path = require('path');
const Assets = require('../assets.js');

const v8Report = async (reportData, reportOptions, options) => {

// V8 only options, merged with root options
const v8HtmlOptions = {
outputFile: options.outputFile,
inline: options.inline,
assetsPath: options.assetsPath,
metrics: options.metrics,
... reportOptions
};

// add metrics to data for UI
reportData.metrics = v8HtmlOptions.metrics;

const {
outputFile, inline, assetsPath
} = v8HtmlOptions;

// resolve full report path
const reportPath = path.resolve(options.outputDir, outputFile);
const outputDir = path.dirname(reportPath);
const htmlFile = path.basename(reportPath);

const jsFiles = ['monocart-coverage-app'];
// console.log(jsFiles);

const htmlOptions = {
reportData,
jsFiles,
inline,
assetsPath,
outputDir,
htmlFile,

saveReportPath: 'reportPath',

reportDataFile: 'coverage-data.js'
};

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

return htmlPath;
};

module.exports = {
v8Report
};
71 changes: 5 additions & 66 deletions lib/v8/v8.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const path = require('path');
const EC = require('eight-colors');
const { minimatch } = require('minimatch');
const { mergeScriptCovs } = require('@bcoe/v8-coverage');
const Assets = require('../assets.js');
const Util = require('../utils/util.js');
const { getV8Summary } = require('./v8-summary.js');
const { dedupeFlatRanges } = require('../utils/dedupe.js');
Expand All @@ -11,6 +9,9 @@ const {
} = require('../utils/source-path.js');
const { collectSourceMaps } = require('../converter/collect-source-maps.js');

const { v8Report } = require('../reports/v8.js');
const { v8JsonReport } = require('../reports/v8-json.js');

const getWrapperSource = (offset, source) => {
// NO \n because it break line number in mappings
let startStr = '';
Expand Down Expand Up @@ -312,68 +313,6 @@ const mergeV8Coverage = async (dataList, sourceCache, options) => {

// ============================================================

const handleV8JsonReport = async (reportData, reportOptions, options) => {
const v8JsonOptions = {
outputFile: 'coverage-report.json',
... reportOptions
};

// 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 reportPath;
};


const handleV8HtmlReport = async (reportData, reportOptions, options) => {

// V8 only options, merged with root options
const v8HtmlOptions = {
outputFile: options.outputFile,
inline: options.inline,
assetsPath: options.assetsPath,
metrics: options.metrics,
... reportOptions
};

// add metrics to data for UI
reportData.metrics = v8HtmlOptions.metrics;

const {
outputFile, inline, assetsPath
} = v8HtmlOptions;

// resolve full report path
const reportPath = path.resolve(options.outputDir, outputFile);
const outputDir = path.dirname(reportPath);
const htmlFile = path.basename(reportPath);

const jsFiles = ['monocart-coverage-app'];
// console.log(jsFiles);

const htmlOptions = {
reportData,
jsFiles,
inline,
assetsPath,
outputDir,
htmlFile,

saveReportPath: 'reportPath',

reportDataFile: 'coverage-data.js'
};

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

return htmlPath;
};

const saveV8Report = async (v8list, options, istanbulReportPath) => {

const defaultWatermarks = {
Expand All @@ -400,8 +339,8 @@ const saveV8Report = async (v8list, options, istanbulReportPath) => {

// v8 only reports
const buildInV8Reports = {
'v8': handleV8HtmlReport,
'v8-json': handleV8JsonReport
'v8': v8Report,
'v8-json': v8JsonReport
};

const outputs = {};
Expand Down

0 comments on commit ab1dc47

Please sign in to comment.