playwright-deny-coverage 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +22 -0
- package/index.js +18 -20
- package/package.json +6 -2
package/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TestType } from "@playwright/test";
|
|
2
|
+
export declare function denyCoverage(opts: {
|
|
3
|
+
sourceFilter: (sourcePath: string) => boolean;
|
|
4
|
+
entryFilter: (entry: any) => boolean;
|
|
5
|
+
outputFile?: string;
|
|
6
|
+
threshold?: number;
|
|
7
|
+
}): (string | {
|
|
8
|
+
outputFile: string;
|
|
9
|
+
coverage: {
|
|
10
|
+
reports: string[][];
|
|
11
|
+
sourceFilter: (sourcePath: string) => boolean;
|
|
12
|
+
entryFilter: (entry: any) => boolean;
|
|
13
|
+
onEnd: (results: any) => void;
|
|
14
|
+
};
|
|
15
|
+
})[];
|
|
16
|
+
type CoverageFixtures = {
|
|
17
|
+
_autoCoverage: void;
|
|
18
|
+
};
|
|
19
|
+
export declare function extendTest(opts: {
|
|
20
|
+
filter: (entry: any) => boolean;
|
|
21
|
+
}): TestType<CoverageFixtures, {}>;
|
|
22
|
+
export {};
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
// index.ts
|
|
1
2
|
import { test } from "@playwright/test";
|
|
2
3
|
import { addCoverageReport } from "monocart-reporter";
|
|
3
|
-
|
|
4
|
-
export function denyCoverage(opts) {
|
|
4
|
+
function denyCoverage(opts) {
|
|
5
5
|
return [
|
|
6
6
|
"monocart-reporter",
|
|
7
7
|
{
|
|
@@ -12,51 +12,49 @@ export function denyCoverage(opts) {
|
|
|
12
12
|
entryFilter: opts.entryFilter,
|
|
13
13
|
onEnd: (results) => {
|
|
14
14
|
const { summary } = results;
|
|
15
|
-
|
|
16
15
|
const failures = [];
|
|
17
|
-
|
|
18
16
|
const threshold = opts.threshold ?? 100;
|
|
19
17
|
if (summary.lines.pct < threshold) {
|
|
20
18
|
failures.push(`lines ${summary.lines.pct}% < ${threshold}%`);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
if (failures.length) {
|
|
24
|
-
console.error(
|
|
21
|
+
console.error(`
|
|
22
|
+
|
|
23
|
+
Coverage threshold failed: ${failures.join(", ")}
|
|
24
|
+
|
|
25
|
+
`);
|
|
25
26
|
process.exit(1);
|
|
26
27
|
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
30
31
|
];
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
-
export function extendTest(opts) {
|
|
33
|
+
function extendTest(opts) {
|
|
34
34
|
return test.extend({
|
|
35
35
|
_autoCoverage: [
|
|
36
36
|
async ({ page, browserName }, use, testInfo) => {
|
|
37
|
-
// Playwright coverage works only in Chromium.
|
|
38
37
|
const coverage = browserName === "chromium";
|
|
39
|
-
|
|
40
38
|
if (coverage) {
|
|
41
39
|
await page.coverage.startJSCoverage({
|
|
42
40
|
resetOnNavigation: false,
|
|
43
|
-
reportAnonymousScripts: true
|
|
41
|
+
reportAnonymousScripts: true
|
|
44
42
|
});
|
|
45
43
|
}
|
|
46
|
-
|
|
47
44
|
await use();
|
|
48
|
-
|
|
49
45
|
if (coverage) {
|
|
50
46
|
const coverageList = await page.coverage.stopJSCoverage();
|
|
51
|
-
|
|
52
47
|
const filtered = coverageList.filter(opts.filter);
|
|
53
|
-
|
|
54
48
|
if (filtered.length > 0) {
|
|
55
49
|
await addCoverageReport(filtered, testInfo);
|
|
56
50
|
}
|
|
57
51
|
}
|
|
58
52
|
},
|
|
59
|
-
{ auto: true }
|
|
60
|
-
]
|
|
53
|
+
{ auto: true }
|
|
54
|
+
]
|
|
61
55
|
});
|
|
62
56
|
}
|
|
57
|
+
export {
|
|
58
|
+
denyCoverage,
|
|
59
|
+
extendTest
|
|
60
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playwright-deny-coverage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Deny coverage reporter for Playwright",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
7
8
|
"license": "(MIT OR Apache-2.0)",
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|
|
@@ -21,6 +22,9 @@
|
|
|
21
22
|
"monocart-reporter": "^2.10.1"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
|
-
"
|
|
25
|
+
"@types/node": "^20.12.13",
|
|
26
|
+
"esbuild": "^0.17.19",
|
|
27
|
+
"runish": "^0.1.0",
|
|
28
|
+
"typescript": "^5.3.3"
|
|
25
29
|
}
|
|
26
30
|
}
|