Skip to content

Commit

Permalink
update options
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Dec 6, 2023
1 parent 7f3e4e2 commit c9bb4a7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
```js
const CoverageReport = require('monocart-coverage-reports');
const options = {
outputFile: "coverage-reports/2023-11-24/index.html",
name: "My Coverage Report 2023-11-24"
outputDir: './coverage-reports',
reports: "v8"
}
const coverageReport = new CoverageReport(options);
await coverageReport.add(coverageData1);
Expand Down
3 changes: 2 additions & 1 deletion lib/converter/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ const unpackSourceMap = async (item, state, options) => {

// keep original urls
const fileUrls = {};
initSourceMapSourcePath(sourceMap, fileUrls, options.sourcePath);
const sourcePathHandler = options.sourcePath;
initSourceMapSourcePath(sourceMap, fileUrls, sourcePathHandler);

// decode mappings for each original file
const time_start_decode = Date.now();
Expand Down
8 changes: 2 additions & 6 deletions lib/default/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@ const defaultOptions = {
// },
entryFilter: null,

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

// (Function) source path handler. (Istanbul only)
// (Function) source path handler.
// sourcePath: (filePath) => `wwwroot/${filePath}`,
sourcePath: null,

// (Function) source finder for Istanbul HTML report. (Istanbul only)
// sourceFinder: (filePath) => `src/${filePath}`,
sourceFinder: null,

// (Array) watermarks for low/medium/high. Defaults to [50, 80]
// (Object) Istanbul: { statements:[50,80], functions:[50,80], branches:[50,80], lines:[50,80] }, V8: { bytes:[50,80] }.
watermarks: [50, 80]
Expand Down
15 changes: 4 additions & 11 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export type IstanbulReportConfig = {
name: string,
options: any
}

// https://playwright.dev/docs/api/class-coverage
export type CoverageEntry = {
export type V8CoverageEntry = {
url: string,
// css
text?: string,
Expand Down Expand Up @@ -48,17 +44,14 @@ export type CoverageReportOptions = {
reports?: string | ReportDescription[],

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

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

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

// (Function) source finder for Istanbul HTML report. (Istanbul only)
sourceFinder?: (filePath: string) => string,

// (Array) watermarks for low/medium/high. Defaults to [50, 80]
// (Object) Istanbul: { statements:[50,80], functions:[50,80], branches:[50,80], lines:[50,80] }, V8: { bytes:[50,80] }.
watermarks?: [number, number] | {
Expand Down
21 changes: 10 additions & 11 deletions lib/istanbul/istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,19 @@ const saveIstanbulReports = (coverageData, fileSources, options) => {
branches: [50, 80],
lines: [50, 80]
};
const istanbulOptions = {
watermarks: Util.resolveWatermarks(defaultWatermarks, options.watermarks),
defaultSummarizer: options.defaultSummarizer
};
const watermarks = Util.resolveWatermarks(defaultWatermarks, options.watermarks);

// https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report

// defaultSummarizer and sourceFinder can be passed from options
const contextOptions = {
coverageMap,
watermarks,
dir: options.outputDir,
// The summarizer to default to (may be overridden by some reports)
// values can be nested/flat/pkg. Defaults to 'pkg'
defaultSummarizer: 'nested',
defaultSummarizer: options.defaultSummarizer || 'nested',

... istanbulOptions,

dir: options.outputDir,
sourceFinder: (filePath) => {

// console.log(`find file source: ${filePath}`);
Expand All @@ -82,8 +81,7 @@ const saveIstanbulReports = (coverageData, fileSources, options) => {
// console.log('Not found source file:', filePath);

return `Not found source file: ${filePath}`;
},
coverageMap
}
};

// create a context for report generation
Expand Down Expand Up @@ -132,8 +130,9 @@ const initIstanbulData = (istanbulData, options) => {
}

const fileSources = options.fileSources || {};
const sourcePathHandler = options.sourcePath;

const coverageData = initIstanbulSourcePath(istanbulData, fileSources, options.sourcePath);
const coverageData = initIstanbulSourcePath(istanbulData, fileSources, sourcePathHandler);

return {
fileSources,
Expand Down

0 comments on commit c9bb4a7

Please sign in to comment.