Skip to content

Commit

Permalink
fix summary format
Browse files Browse the repository at this point in the history
added types
  • Loading branch information
cenfun committed Jan 10, 2024
1 parent 34bcda7 commit 4ce84ac
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 162 deletions.
361 changes: 209 additions & 152 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,158 +1,217 @@
declare namespace CoverageReport {
// https://playwright.dev/docs/api/class-coverage
export type V8CoverageEntry = {
url: string;
// css
text?: string;
ranges?: any[];
// js
scriptId?: string;
source?: string;
functions?: any[];
}

export type Watermarks = [number, number] | {
statements?: [number, number];
functions?: [number, number];
branches?: [number, number];
lines?: [number, number];
bytes?: [number, number];
}

export type ReportDescription =
['v8'] | ["v8", {
outputFile?: string;
inline?: boolean;
assetsPath?: string;
metrics?: Array<"bytes" | "functions" | "branches" | "lines">;
}] |
['v8-json'] | ["v8-json", {
outputFile?: string;
}] |
['console-summary'] | ['console-summary', {
metrics?: Array<"bytes" | "functions" | "branches" | "lines" | "statements">;
}] |
['clover'] | ['clover', {
file?: string;
}] |
['cobertura'] | ['cobertura', {
file?: string;
timestamp?: string;
projectRoot?: string;
}] |
['html'] | ['html', {
subdir?: string;
verbose?: boolean;
linkMapper?: any;
skipEmpty?: boolean;
}] |
['html-spa'] | ['html-spa', {
subdir?: string;
verbose?: boolean;
linkMapper?: any;
skipEmpty?: boolean;
metricsToShow?: Array<"lines" | "branches" | "functions" | "statements">;
}] |
['json'] | ['json', {
file?: string;
}] |
['json-summary'] | ['json-summary', {
file?: string;
}] |
['lcov'] | ['lcov', {
file?: string;
projectRoot?: string;
}] |
['lcovonly'] | ['lcovonly', {
file?: string;
projectRoot?: string;
}] |
['none'] |
['teamcity'] | ['teamcity', {
file?: string;
blockName?: string;
}] |
['text'] | ['text', {
file?: string;
maxCols?: number;
skipEmpty?: boolean;
skipFull?: boolean;
}] |
['text-lcov'] | ['text-lcov', {
projectRoot?: string;
}] |
['text-summary'] | ['text-summary', {
file?: string;
}];

export type AddedResults = {
id: string;
path: string;
type: "v8" | "istanbul";
data: any;
} | undefined;


export interface MetricsSummary {
covered: number;
uncovered?: number;
total: number;
pct: number | "";
status: "low" | "medium" | "high" | "unknown";
}

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

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

export interface CoverageRange {
start: number;
end: number;
count: number;
ignored?: boolean;
none?: boolean;
}
export interface CoverageFile {
sourcePath: string;
summary: CoverageSummary;
// v8 only
url?: string;
id?: string;
type?: string;
source?: string;
distFile?: string;
js?: boolean;
data?: {
bytes: CoverageRange[];
functions: CoverageRange[];
branches: CoverageRange[];
}
}

export type CoverageResults = {
type: "v8" | "istanbul";
reportPath: string;
name: string;
watermarks: Watermarks;
summary: CoverageSummary;
files: CoverageFile[];
} | undefined;

export type CoverageReportOptions = {

// (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[];

// (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) 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;

// [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 */
v8Ignore?: boolean;

// [Istanbul only] defaultSummarizer, sourceFinder

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

// (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.
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] }.
watermarks?: Watermarks;

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

export function createCoverageReport(options?: CoverageReportOptions): CoverageReport;

// https://playwright.dev/docs/api/class-coverage
export type V8CoverageEntry = {
url: string,
// css
text?: string,
ranges?: any[]
// js
scriptId?: string,
source?: string,
functions?: any[]
}

export type Watermarks = [number, number] | {
statements?: [number, number],
functions?: [number, number],
branches?: [number, number],
lines?: [number, number],
bytes?: [number, number]
}

export type ReportDescription =
['v8'] | ["v8", {
outputFile?: string,
inline?: boolean,
assetsPath?: string,
metrics?: Array<"bytes" | "functions" | "branches" | "lines">
}] |
['v8-json'] | ["v8-json", {
outputFile?: string
}] |
['console-summary'] | ['console-summary', {
metrics?: Array<"bytes" | "functions" | "branches" | "lines" | "statements">
}] |
['clover'] | ['clover', {
file?: string
}] |
['cobertura'] | ['cobertura', {
file?: string,
timestamp?: string,
projectRoot?: string
}] |
['html'] | ['html', {
subdir?: string,
verbose?: boolean,
linkMapper?: any,
skipEmpty?: boolean
}] |
['html-spa'] | ['html-spa', {
subdir?: string,
verbose?: boolean,
linkMapper?: any,
skipEmpty?: boolean,
metricsToShow?: Array<"lines" | "branches" | "functions" | "statements">
}] |
['json'] | ['json', {
file?: string
}] |
['json-summary'] | ['json-summary', {
file?: string
}] |
['lcov'] | ['lcov', {
file?: string,
projectRoot?: string
}] |
['lcovonly'] | ['lcovonly', {
file?: string,
projectRoot?: string
}] |
['none'] |
['teamcity'] | ['teamcity', {
file?: string,
blockName?: string
}] |
['text'] | ['text', {
file?: string,
maxCols?: number,
skipEmpty?: boolean,
skipFull?: boolean
}] |
['text-lcov'] | ['text-lcov', {
projectRoot?: string
}] |
['text-summary'] | ['text-summary', {
file?: string
}];

export type CoverageResults = {
type: "v8" | "istanbul",
reportPath: string,
name: string,
watermarks: Watermarks,
summary: any,
files: any
}

export type CoverageReportOptions = {

// (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[],

// (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) 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,

// [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 */
v8Ignore?: boolean,

// [Istanbul only] defaultSummarizer, sourceFinder

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

// (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.
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] }.
watermarks?: Watermarks,

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

export class CoverageReport {
constructor(options?: CoverageReportOptions);
declare class CoverageReport {
constructor(options?: CoverageReport.CoverageReportOptions);

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

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

// check if cache exists
hasCache: () => boolean;
Expand All @@ -162,6 +221,4 @@ export class CoverageReport {

}

export default CoverageReport;

export function createCoverageReport(options?: CoverageReportOptions): CoverageReport;
export = CoverageReport;
7 changes: 5 additions & 2 deletions lib/istanbul/istanbul-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ class IstanbulSummary extends ReportBase {
onDetail(node) {
const fileSummary = node.getCoverageSummary().data;
this.addStatus(fileSummary);
fileSummary.name = node.getRelativeName();
this.files.push(fileSummary);
const sourcePath = node.getQualifiedName();
this.files.push({
sourcePath,
summary: fileSummary
});
}

onEnd() {
Expand Down
Loading

0 comments on commit 4ce84ac

Please sign in to comment.