diff --git a/lib/index.d.ts b/lib/index.d.ts index 5466df8c..452f0135 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -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; + } + + 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 -} - -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; + add: (coverageData: any[] | any) => Promise; // generate report - generate: () => Promise; + generate: () => Promise; // check if cache exists hasCache: () => boolean; @@ -162,6 +221,4 @@ export class CoverageReport { } -export default CoverageReport; - -export function createCoverageReport(options?: CoverageReportOptions): CoverageReport; \ No newline at end of file +export = CoverageReport; diff --git a/lib/istanbul/istanbul-summary.js b/lib/istanbul/istanbul-summary.js index b749b6ff..cf437c03 100644 --- a/lib/istanbul/istanbul-summary.js +++ b/lib/istanbul/istanbul-summary.js @@ -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() { diff --git a/lib/v8/v8.js b/lib/v8/v8.js index e459b5f3..9d128c22 100644 --- a/lib/v8/v8.js +++ b/lib/v8/v8.js @@ -275,15 +275,13 @@ const saveV8Report = async (v8list, options) => { return outputPath; }); - const summaryList = v8list.map((entry) => entry.summary); - const coverageResults = { type: 'v8', reportPath, name: options.name, watermarks, summary, - files: summaryList + files: v8list }; return coverageResults; diff --git a/package.json b/package.json index 40848a02..b4dca214 100644 --- a/package.json +++ b/package.json @@ -42,12 +42,12 @@ "url": "git+https://github.com/cenfun/monocart-coverage-reports.git" }, "dependencies": { - "console-grid": "~2.0.1", - "eight-colors": "~1.0.3", + "console-grid": "~2.1.0", + "eight-colors": "~1.2.1", "istanbul-lib-coverage": "~3.2.2", "istanbul-lib-report": "~3.0.1", "istanbul-reports": "~3.1.6", - "lz-utils": "~2.0.1", + "lz-utils": "~2.0.2", "monocart-code-viewer": "~1.0.13", "monocart-formatter": "~2.3.0", "turbogrid": "~3.0.12" diff --git a/test/package.json b/test/package.json index 17ab5b9c..48576035 100644 --- a/test/package.json +++ b/test/package.json @@ -9,7 +9,7 @@ "dependencies": {}, "devDependencies": { "@rollup/plugin-commonjs": "^25.0.7", - "@rollup/plugin-typescript": "^11.1.5", + "@rollup/plugin-typescript": "^11.1.6", "axios": "^1.6.5", "babel-loader": "^9.1.3", "babel-plugin-istanbul": "^6.1.1", @@ -18,7 +18,7 @@ "foreground-child": "^3.1.1", "github-markdown-css": "^5.5.0", "koa": "^2.15.0", - "koa-static-resolver": "^1.0.4", + "koa-static-resolver": "^1.0.5", "marked": "^11.1.1", "open": "^10.0.3", "playwright": "^1.40.1",