Skip to content

Commit

Permalink
moveout v8 options
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Dec 6, 2023
1 parent 0f94f14 commit 16b0fc0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 69 deletions.
48 changes: 21 additions & 27 deletions lib/default/options.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
const defaultOptions = {
module.exports = {

// logging levels: off, error, info, debug
// (String) logging levels: off, error, info, debug
logging: 'info',

// (String)
// (String) output dir
outputDir: './coverage-reports',

// (String) v8 or html for istanbul by default
// (Array) multiple reports with options
// v8 report or istanbul supported reports
// reports: [
// ['v8', {
// // report name (V8 only)
// name: 'Coverage Report',
// outputFile: "index.html",
// // (Boolean) Whether inline all scripts to the single HTML file. (V8 only)
// inline: false,
// // assets path if not inline. (V8 only)
// assetsPath: './assets'
// }],
// ['v8'],
// ['html', {
// subdir: 'my-sub-dir'
// }],
// 'lcov'
// ],
reports: '',

// (Function) A filter function to execute for each element in the V8 list. (V8 only)
// (String) Report name. Defaults to "Coverage Report".
name: 'Coverage Report',

// [V8 only](String) Output [sub dir/]filename. Defaults to "index.html"
outputFile: 'index.html',

// [V8 only](Boolean) Whether inline all scripts to the single HTML file. Defaults to false.
inline: false,

// [V8 only](String) Assets path if not inline. Defaults to "./assets"
assetsPath: './assets',

// [V8 only](Function) A filter function to execute for each element in the V8 list.
// entryFilter: (entry) => {
// if (entry.url.indexOf('googleapis.com') !== -1) {
// return false;
Expand All @@ -34,10 +39,12 @@ const defaultOptions = {
// },
entryFilter: null,

// (Function) A filter function to execute for each element in the sources which unpacked from the source map. (V8 only)
// [V8 only](Function) A filter function to execute for each element in the sources which unpacked from the source map.
// sourceFilter: (sourcePath) => sourcePath.search(/src\/.+/) !== -1,
sourceFilter: null,

// [Istanbul only] defaultSummarizer, sourceFinder

// (Function) source path handler.
// sourcePath: (filePath) => `wwwroot/${filePath}`,
sourcePath: null,
Expand All @@ -46,16 +53,3 @@ const defaultOptions = {
// (Object) Istanbul: { statements:[50,80], functions:[50,80], branches:[50,80], lines:[50,80] }, V8: { bytes:[50,80] }.
watermarks: [50, 80]
};

const defaultV8ReportOptions = {
name: 'Coverage Report',
outputFile: 'index.html',
inline: false,
assetsPath: './assets'
};


module.exports = {
defaultOptions,
defaultV8ReportOptions
};
8 changes: 1 addition & 7 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const { mergeV8Coverage, saveV8Report } = require('./v8/v8.js');

const { convertV8List } = require('./converter/converter.js');

const { defaultV8ReportOptions } = require('./default/options.js');

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

// maybe v8 or to istanbul reports
Expand All @@ -28,11 +26,7 @@ const generateV8ListReports = async (v8list, coverageData, fileSources, options)

// generate v8 report
if (v8) {
const v8ReportOptions = {
... defaultV8ReportOptions,
... v8
};
report = await saveV8Report(v8list, options, v8ReportOptions);
report = await saveV8Report(v8list, options);
}

return report;
Expand Down
39 changes: 21 additions & 18 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,45 @@ export type V8CoverageEntry = {
functions?: any[]
}

export type V8ReportOptions = {
// report name. Defaults to "Coverage Report".
name?: string,

// output dir and filename. Defaults to "index.html"
outputFile?: string,

// Whether inline all scripts to the single HTML file. Defaults to false.
inline?: boolean,

// assets path if not inline. Defaults to "./assets"
assetsPath?: string
}

export type ReportDescription =
['v8'] | ['v8', V8ReportOptions] |
['v8'] |
// html, html-spa, json, lcov and so on
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/istanbul-reports/index.d.ts
[string] | [string, any];

export type CoverageReportOptions = {

// logging levels: off, error, info, debug
// (String) logging levels: off, error, info, debug
logging?: string,

// (String) output dir
outputDir?: string,

// (String) v8 or html for istanbul by default
// (Array) multiple reports with options
// v8 report or istanbul supported reports
reports?: string | ReportDescription[],

// (Function) A filter function to execute for each element in the V8 list. (V8 only)
// (String) Report name. Defaults to "Coverage Report".
name?: string,

// [V8 only](String) Output [sub dir/]filename. Defaults to "index.html"
outputFile?: string,

// [V8 only](Boolean) Whether inline all scripts to the single HTML file. Defaults to false.
inline?: boolean,

// [V8 only](String) Assets path if not inline. Defaults to "./assets"
assetsPath?: string

// [V8 only](Function) A filter function to execute for each element in the V8 list.
entryFilter?: (entry: V8CoverageEntry) => boolean,

// (Function) A filter function to execute for each element in the sources which unpacked from the source map. (V8 only)
// [V8 only](Function) A filter function to execute for each element in the sources which unpacked from the source map.
sourceFilter?: (sourcePath: string) => boolean,

// [Istanbul only] defaultSummarizer, sourceFinder

// (Function) source path handler.
sourcePath?: (filePath: string) => string,

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const path = require('path');
const { defaultOptions } = require('./default/options.js');
const defaultOptions = require('./default/options.js');
const Util = require('./utils/util.js');

const { initV8ListAndSourcemap } = require('./v8/v8.js');
Expand Down
26 changes: 10 additions & 16 deletions lib/v8/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,9 @@ const mergeV8Coverage = async (dataList, options) => {

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

const saveV8HtmlReport = async (reportData, v8ReportOptions) => {
const saveV8HtmlReport = async (reportData, options) => {

const {
inline, assetsPath, outputFile
} = v8ReportOptions;
const outputFile = path.resolve(options.outputDir, options.outputFile);

const outputDir = path.dirname(outputFile);
const htmlFile = path.basename(outputFile);
Expand All @@ -186,24 +184,24 @@ const saveV8HtmlReport = async (reportData, v8ReportOptions) => {

// console.log(jsFiles);

const options = {
inline,
const htmlOptions = {
reportData,
jsFiles,
assetsPath,
inline: options.inline,
assetsPath: options.assetsPath,
outputDir,
htmlFile,

reportDataFile: 'coverage-data.js'
};

const htmlPath = await Util.saveHtmlReport(options);
const htmlPath = await Util.saveHtmlReport(htmlOptions);

return htmlPath;
};


const saveV8Report = async (v8list, options, v8ReportOptions) => {
const saveV8Report = async (v8list, options) => {
const defaultWatermarks = {
bytes: [50, 80]
};
Expand Down Expand Up @@ -244,22 +242,18 @@ const saveV8Report = async (v8list, options, v8ReportOptions) => {
};

const htmlOptions = {
name: v8ReportOptions.name,
name: options.name,
watermarks,
summary,
files: v8list
};

// init html dir and filename
const outputFile = path.resolve(options.outputDir, v8ReportOptions.outputFile);
v8ReportOptions.outputFile = outputFile;

const htmlPath = await saveV8HtmlReport(htmlOptions, v8ReportOptions);
const htmlPath = await saveV8HtmlReport(htmlOptions, options);

const report = {
type: 'v8',
htmlPath,
name: v8ReportOptions.name,
name: options.name,
watermarks,
summary,
files: summaryList
Expand Down

0 comments on commit 16b0fc0

Please sign in to comment.