Skip to content

Commit

Permalink
more types
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jan 11, 2024
1 parent 4c90222 commit 7d54060
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 50 deletions.
36 changes: 18 additions & 18 deletions lib/default/options.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports = {

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

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

// (String) v8 or html for istanbul by default
// (Array) multiple reports with options
// {string} v8 or html for istanbul by default
// {array} multiple reports with options
// v8 report or istanbul supported reports
// reports: [
// ['v8'],
Expand All @@ -18,19 +18,19 @@ module.exports = {
// ],
reports: '',

// (String) Report name. Defaults to "Coverage Report".
// {string} Report name. Defaults to "Coverage Report".
name: 'Coverage Report',

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

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

// [V8 only](String) Assets path if not inline. Defaults to "./assets"
// (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.
// (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 @@ -39,30 +39,30 @@ module.exports = {
// },
entryFilter: null,

// [V8 only](Function) A filter function to execute for each element in the sources which unpacked from the source map.
// (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,

// [V8 only](Boolean) Enable/Disable ignoring uncovered codes with the special comments: /* v8 ignore next/next N/start/stop */
// (V8 only) {boolean} Enable/Disable ignoring uncovered codes with the special comments: v8 ignore next/next N/start/stop
v8Ignore: true,

// [Istanbul only] defaultSummarizer, sourceFinder
// (Istanbul only) defaultSummarizer, sourceFinder

// (Boolean) Generate lcov.info file, same as lcovonly report. Defaults to false.
// {boolean} Generate lcov.info file, same as lcovonly report. Defaults to false.
lcov: false,

// (Function) Source path handler.
// {function} Source path handler.
// sourcePath: (filePath) => `wwwroot/${filePath}`,
sourcePath: null,

// (String|Function) Specify the report path, especially when there are multiple reports. Defaults to outputDir/index.html.
// {string|function} Specify the report path, especially when there are multiple reports. Defaults to outputDir/index.html.
reportPath: 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] }.
// {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],

// (Function) onEnd hook
// {function} onEnd hook
// onEnd: async (reportData) => {}
onEnd: null
};
75 changes: 44 additions & 31 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
declare namespace CoverageReport {
// https://playwright.dev/docs/api/class-coverage

export interface V8CoverageEntry {
url: string;
// css
/** css only */
text?: string;
/** css only */
ranges?: any[];
// js
/** js only */
scriptId?: string;
/** js only */
source?: string;
/** js only */
functions?: any[];
}

export type Watermarks = [number, number] | {
statements?: [number, number];
functions?: [number, number];
branches?: [number, number];
lines?: [number, number];
/** V8 only */
bytes?: [number, number];
/** Istanbul only */
statements?: [number, number];
}

export type ReportDescription =
Expand Down Expand Up @@ -102,21 +107,23 @@ declare namespace CoverageReport {
}

export interface LinesSummary extends MetricsSummary {
// v8 only
/** V8 only */
blank?: number;
/** V8 only */
comment?: number;
}

export interface CoverageSummary {
functions: MetricsSummary;
branches: MetricsSummary;
lines: LinesSummary;
// v8 only
/** V8 only */
bytes?: MetricsSummary;
// istanbul only
/** Istanbul only */
statements?: MetricsSummary;
}

/** V8 only */
export interface CoverageRange {
start: number;
end: number;
Expand All @@ -127,13 +134,19 @@ declare namespace CoverageReport {
export interface CoverageFile {
sourcePath: string;
summary: CoverageSummary;
// v8 only
/** V8 only */
url?: string;
/** V8 only */
id?: string;
/** V8 only */
type?: string;
/** V8 only */
source?: string;
/** V8 only */
distFile?: string;
/** V8 only */
js?: boolean;
/** V8 only */
data?: {
bytes: CoverageRange[];
functions: CoverageRange[];
Expand All @@ -152,52 +165,52 @@ declare namespace CoverageReport {

export interface CoverageReportOptions {

// (String) logging levels: off, error, info, debug
/** {string} logging levels: off, error, info, debug */
logging?: string;

// (String) output dir
/** {string} output dir */
outputDir?: string;

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

// (String) Report name. Defaults to "Coverage Report".
/** {string} Report name. Defaults to "Coverage Report". */
name?: string;

// [V8 only](String) Output [sub dir/]filename. Defaults to "index.html"
/** (V8 only) {string} Output [sub dir/]filename. Defaults to "index.html" */
outputFile?: string;
// [V8 only](Boolean) Inline all scripts to the single HTML file. Defaults to false.
/** (V8 only) {boolean} Inline all scripts to the single HTML file. Defaults to false. */
inline?: boolean;
// [V8 only](String) Assets path if not inline. Defaults to "./assets"
/** (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.
/** (V8 only) {function} A filter function to execute for each element in the V8 list. */
entryFilter?: (entry: V8CoverageEntry) => boolean;

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

// [V8 only](Boolean) Enable/Disable ignoring uncovered codes with the special comments: /* v8 ignore next/next N/start/stop */
/** (V8 only) {boolean} Enable/Disable ignoring uncovered codes with the special comments: v8 ignore next/next N/start/stop */
v8Ignore?: boolean;

// [Istanbul only] defaultSummarizer, sourceFinder
/** (Istanbul only) defaultSummarizer, sourceFinder */

// (Boolean) Generate lcov.info file, same as lcovonly report. Defaults to false.
/** {boolean} Generate lcov.info file, same as lcovonly report. Defaults to false. */
lcov?: boolean;

// (Function) Source path handler.
/** {function} Source path handler. */
sourcePath?: (filePath: string) => string;

// (String|Function) Specify the report path, especially when there are multiple reports. Defaults to outputDir/index.html.
/** {string|function} Specify the report path, especially when there are multiple reports. Defaults to outputDir/index.html. */
reportPath?: 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] }.
/** {array} watermarks for low/medium/high. Defaults to [50, 80]
* {object} { statements:[50,80], functions:[50,80], branches:[50,80], lines:[50,80] }, V8: { bytes:[50,80] } */
watermarks?: Watermarks;

// (Function) onEnd hook
/** {function} onEnd hook */
onEnd?: (reportData: CoverageResults) => Promise<void>;
}

Expand All @@ -207,16 +220,16 @@ declare namespace CoverageReport {
declare class CoverageReport {
constructor(options?: CoverageReport.CoverageReportOptions);

// add coverage data: (Array) V8 format, (Object) Istanbul format
/** add coverage data: {array} V8 format, {object} Istanbul format */
add: (coverageData: any[] | any) => Promise<CoverageReport.AddedResults>;

// generate report
/** generate report */
generate: () => Promise<CoverageReport.CoverageResults>;

// check if cache exists
/** check if cache exists */
hasCache: () => boolean;

// clean cache
/** clean previous cache, return `false` if no cache */
cleanCache: () => boolean;

}
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CoverageReport {
this.fixedOptions = true;
}

// add coverage data: (Array) V8 format, (Object) Istanbul format
// add coverage data: {array} V8 format, {object} Istanbul format
async add(data) {

this.initOptions();
Expand Down

0 comments on commit 7d54060

Please sign in to comment.