From d9a760e82f208cd377e241a312841f3e071bfca3 Mon Sep 17 00:00:00 2001 From: cenfun Date: Sun, 3 Dec 2023 10:29:52 +0800 Subject: [PATCH] update type --- lib/index.d.ts | 49 ++++++++++++++++++++++++++++++++++++++----------- lib/options.js | 4 ++-- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 8894954b..00380c62 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -3,27 +3,51 @@ export type IstanbulReportConfig = { options: any } +// https://playwright.dev/docs/api/class-coverage +export type CoverageEntry = { + url: string, + // css + text?: string, + ranges?: any[] + // js + scriptId?: string, + source?: string, + functions?: any[] +} + export type CoverageReportOptions = { + // report name (V8 only) name?: string, - outputFile?: string, - // Whether to convert to Istanbul report + // output dir and filename (filename V8 only) + outputFile?: string | (() => string), + + // logging levels: off, error, info, debug + logging?: string, + + // (Boolean) Whether to convert to Istanbul report from V8 list. Defaults to `html-spa` report. (V8 only) + // (String) Istanbul report name + // (Array) multiple reports. ["report-name", { name: "report-name", options: {} }, ...] toIstanbul?: boolean | string | string[] | IstanbulReportConfig[], - // A filter function to execute for each element in the V8 list. - entryFilter?: (entry: any) => boolean, + // (Boolean) Whether to create `lcov.info`. (for Sonar coverage) + lcov?: boolean, - // A filter function to execute for each element in the sources which unpacked from the source map. + // (Function) A filter function to execute for each element in the V8 list. (V8 only) + entryFilter?: (entry: CoverageEntry) => boolean, + + // (Function) A filter function to execute for each element in the sources which unpacked from the source map. (Sourcemap only) sourceFilter?: (sourcePath: string) => boolean, - sourcePath?: (sourcePath: string) => string, + // (Function) source path handler. (Istanbul only) + sourcePath?: (filePath: string) => string, + // (Function) source finder for Istanbul HTML report. (Istanbul only) sourceFinder?: (filePath: string) => string, - // Whether to create `lcov.info` - lcov?: boolean, - + // (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] | { statements?: [number, number], functions?: [number, number], @@ -32,10 +56,11 @@ export type CoverageReportOptions = { bytes?: [number, number] }, - // Whether inline all scripts to the single HTML file. + // (Boolean) Whether inline all scripts to the single HTML file. (V8 only) inline?: boolean, - logging?: string + // assets path if not inline. (V8 only) + assetsPath?: string }; export class CoverageReport { @@ -44,4 +69,6 @@ export class CoverageReport { generate: () => Promise; } +export default CoverageReport; + export function createCoverageReport(options?: CoverageReportOptions): CoverageReport; \ No newline at end of file diff --git a/lib/options.js b/lib/options.js index 3694fb64..811d2724 100644 --- a/lib/options.js +++ b/lib/options.js @@ -30,11 +30,11 @@ module.exports = { // sourceFilter: (sourcePath) => sourcePath.search(/src\/.+/) !== -1, sourceFilter: null, - // source path handler. (Istanbul only) + // (Function) source path handler. (Istanbul only) // sourcePath: (filePath) => `wwwroot/${filePath}`, sourcePath: null, - // (usually not used) source finder for Istanbul HTML report. (Istanbul only) + // (Function) source finder for Istanbul HTML report. (Istanbul only) // sourceFinder: (filePath) => `src/${filePath}`, sourceFinder: null,