@sentinelqa/playwright-reporter 0.1.7
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/LICENSE +21 -0
- package/README.md +132 -0
- package/dist/env.d.ts +1 -0
- package/dist/env.js +45 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +135 -0
- package/dist/localReport.d.ts +25 -0
- package/dist/localReport.js +652 -0
- package/dist/reporter.d.ts +21 -0
- package/dist/reporter.js +92 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) SentinelQA
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Sentinel Playwright Reporter
|
|
2
|
+
|
|
3
|
+
A Playwright reporter that collects traces, screenshots, videos, and logs into a single debugging report.
|
|
4
|
+
|
|
5
|
+
Designed to make CI failures easier to diagnose.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -D @sentinelqa/playwright-reporter
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## What you get
|
|
16
|
+
|
|
17
|
+
✔ Collects traces
|
|
18
|
+
✔ Captures screenshots on failure
|
|
19
|
+
✔ Captures videos
|
|
20
|
+
✔ Aggregates logs
|
|
21
|
+
✔ Creates a debugging report
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { defineConfig } from "@playwright/test";
|
|
27
|
+
import { withSentinel } from "@sentinelqa/playwright-reporter";
|
|
28
|
+
|
|
29
|
+
export default withSentinel(
|
|
30
|
+
defineConfig({
|
|
31
|
+
reporter: [["line"]],
|
|
32
|
+
outputDir: "test-results",
|
|
33
|
+
use: {
|
|
34
|
+
trace: "retain-on-failure",
|
|
35
|
+
screenshot: "only-on-failure",
|
|
36
|
+
video: "retain-on-failure"
|
|
37
|
+
}
|
|
38
|
+
}),
|
|
39
|
+
{
|
|
40
|
+
project: "my-app"
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then run your normal command:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx playwright test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The reporter generates:
|
|
52
|
+
|
|
53
|
+
- `./sentinel-report/index.html`
|
|
54
|
+
- `./sentinel-debug.html` as a convenience redirect
|
|
55
|
+
|
|
56
|
+
## Modes
|
|
57
|
+
|
|
58
|
+
### Local Mode
|
|
59
|
+
|
|
60
|
+
Generates debugging reports locally.
|
|
61
|
+
|
|
62
|
+
No Sentinel key is required. The reporter still collects Playwright artifacts and builds the local debug page.
|
|
63
|
+
|
|
64
|
+
### Cloud Mode
|
|
65
|
+
|
|
66
|
+
Uploads CI runs to Sentinel for team debugging and AI analysis.
|
|
67
|
+
|
|
68
|
+
If `SENTINEL_TOKEN` is set, the reporter uploads to Sentinel instead of generating the local HTML report.
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
SENTINEL_TOKEN=your_project_ingest_token
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Flow
|
|
75
|
+
|
|
76
|
+
```text
|
|
77
|
+
Playwright CI
|
|
78
|
+
↓
|
|
79
|
+
Sentinel Reporter
|
|
80
|
+
↓
|
|
81
|
+
Artifacts Collected
|
|
82
|
+
↓
|
|
83
|
+
Local Debug Page OR Sentinel Cloud
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Terminal output
|
|
87
|
+
|
|
88
|
+
Local mode prints one summary per run:
|
|
89
|
+
|
|
90
|
+
```text
|
|
91
|
+
✔ Artifacts collected
|
|
92
|
+
✔ Sentinel debugging report generated
|
|
93
|
+
|
|
94
|
+
Report location:
|
|
95
|
+
./sentinel-report/index.html
|
|
96
|
+
|
|
97
|
+
Optional:
|
|
98
|
+
Upload runs to Sentinel Cloud for:
|
|
99
|
+
• CI history
|
|
100
|
+
• shareable run links
|
|
101
|
+
• AI failure summaries
|
|
102
|
+
|
|
103
|
+
Learn more: https://sentinelqa.com
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Optional: Sentinel Cloud
|
|
107
|
+
|
|
108
|
+
If you want to persist CI runs and share debugging links with your team,
|
|
109
|
+
you can connect the reporter to Sentinel Cloud.
|
|
110
|
+
|
|
111
|
+
Sentinel provides:
|
|
112
|
+
|
|
113
|
+
- Hosted debugging dashboards
|
|
114
|
+
- CI run history
|
|
115
|
+
- AI-generated failure summaries
|
|
116
|
+
- Flaky test detection
|
|
117
|
+
- Shareable run links
|
|
118
|
+
|
|
119
|
+
Create a free account at [sentinelqa.com](https://sentinelqa.com).
|
|
120
|
+
|
|
121
|
+
Free plan includes:
|
|
122
|
+
|
|
123
|
+
- 100 CI runs per month
|
|
124
|
+
- 50 AI failure summaries
|
|
125
|
+
|
|
126
|
+
For larger teams, Sentinel also offers Pro and Business plans with higher run limits, longer retention, and advanced collaboration controls.
|
|
127
|
+
|
|
128
|
+
## Notes
|
|
129
|
+
|
|
130
|
+
- Existing Playwright JSON and HTML reporter paths are preserved when already configured.
|
|
131
|
+
- The reporter injects JSON and HTML reporters only when they are missing.
|
|
132
|
+
- The local report footer links back to Sentinel Playwright Reporter.
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const loadSentinelEnv: () => void;
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadSentinelEnv = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const parseLine = (line) => {
|
|
10
|
+
const trimmed = line.trim();
|
|
11
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
12
|
+
return null;
|
|
13
|
+
const eqIndex = trimmed.indexOf("=");
|
|
14
|
+
if (eqIndex === -1)
|
|
15
|
+
return null;
|
|
16
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
17
|
+
if (!key)
|
|
18
|
+
return null;
|
|
19
|
+
let value = trimmed.slice(eqIndex + 1).trim();
|
|
20
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
21
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
22
|
+
value = value.slice(1, -1);
|
|
23
|
+
}
|
|
24
|
+
return { key, value };
|
|
25
|
+
};
|
|
26
|
+
const loadSentinelEnv = () => {
|
|
27
|
+
const candidates = [".env", ".env.local"];
|
|
28
|
+
for (const candidate of candidates) {
|
|
29
|
+
const fullPath = path_1.default.resolve(process.cwd(), candidate);
|
|
30
|
+
if (!fs_1.default.existsSync(fullPath))
|
|
31
|
+
continue;
|
|
32
|
+
if (!fs_1.default.statSync(fullPath).isFile())
|
|
33
|
+
continue;
|
|
34
|
+
const raw = fs_1.default.readFileSync(fullPath, "utf8");
|
|
35
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
36
|
+
const parsed = parseLine(line);
|
|
37
|
+
if (!parsed)
|
|
38
|
+
continue;
|
|
39
|
+
if (typeof process.env[parsed.key] === "undefined") {
|
|
40
|
+
process.env[parsed.key] = parsed.value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.loadSentinelEnv = loadSentinelEnv;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type ReporterEntry = string | [string] | [string, Record<string, unknown>];
|
|
2
|
+
type PlaywrightUseOptions = {
|
|
3
|
+
trace?: string;
|
|
4
|
+
screenshot?: string;
|
|
5
|
+
video?: string;
|
|
6
|
+
};
|
|
7
|
+
type PlaywrightConfig = {
|
|
8
|
+
reporter?: ReporterEntry | ReporterEntry[];
|
|
9
|
+
outputDir?: string;
|
|
10
|
+
use?: PlaywrightUseOptions;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
export type SentinelResolvedPaths = {
|
|
14
|
+
playwrightJsonPath: string;
|
|
15
|
+
playwrightReportDir: string;
|
|
16
|
+
testResultsDir: string;
|
|
17
|
+
artifactDirs: string[];
|
|
18
|
+
};
|
|
19
|
+
export type SentinelPlaywrightOptions = {
|
|
20
|
+
project?: string;
|
|
21
|
+
playwrightJsonPath?: string;
|
|
22
|
+
playwrightReportDir?: string;
|
|
23
|
+
testResultsDir?: string;
|
|
24
|
+
artifactDirs?: string[];
|
|
25
|
+
verbose?: boolean;
|
|
26
|
+
localReportDir?: string;
|
|
27
|
+
localReportFileName?: string;
|
|
28
|
+
localRedirectFileName?: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function withSentinel(config: PlaywrightConfig, options?: SentinelPlaywrightOptions): PlaywrightConfig;
|
|
31
|
+
export declare function resolveSentinelPaths(config: PlaywrightConfig, options?: SentinelPlaywrightOptions): SentinelResolvedPaths;
|
|
32
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.withSentinel = withSentinel;
|
|
7
|
+
exports.resolveSentinelPaths = resolveSentinelPaths;
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const DEFAULT_REPORT_DIR = "playwright-report";
|
|
10
|
+
const DEFAULT_TEST_RESULTS_DIR = "test-results";
|
|
11
|
+
const cloneEntry = (entry) => {
|
|
12
|
+
if (!Array.isArray(entry))
|
|
13
|
+
return entry;
|
|
14
|
+
const [name, options] = entry;
|
|
15
|
+
return options ? [name, { ...options }] : [name];
|
|
16
|
+
};
|
|
17
|
+
const normalizeReporter = (reporter) => {
|
|
18
|
+
if (!reporter)
|
|
19
|
+
return [];
|
|
20
|
+
if (!Array.isArray(reporter))
|
|
21
|
+
return [cloneEntry(reporter)];
|
|
22
|
+
if (reporter.length === 0)
|
|
23
|
+
return [];
|
|
24
|
+
const maybeTuple = typeof reporter[0] === "string" &&
|
|
25
|
+
(reporter.length === 1 ||
|
|
26
|
+
(reporter.length === 2 &&
|
|
27
|
+
!Array.isArray(reporter[1]) &&
|
|
28
|
+
typeof reporter[1] === "object"));
|
|
29
|
+
if (maybeTuple) {
|
|
30
|
+
return [cloneEntry(reporter)];
|
|
31
|
+
}
|
|
32
|
+
return reporter.map(cloneEntry);
|
|
33
|
+
};
|
|
34
|
+
const getReporterName = (entry) => {
|
|
35
|
+
return Array.isArray(entry) ? entry[0] : entry;
|
|
36
|
+
};
|
|
37
|
+
const getReporterOptions = (entry) => {
|
|
38
|
+
if (!entry || !Array.isArray(entry))
|
|
39
|
+
return {};
|
|
40
|
+
return entry[1] || {};
|
|
41
|
+
};
|
|
42
|
+
const normalizePath = (value) => {
|
|
43
|
+
return value.replace(/\\/g, "/");
|
|
44
|
+
};
|
|
45
|
+
const setReporterOptions = (reporters, name, options) => {
|
|
46
|
+
const index = reporters.findIndex((entry) => getReporterName(entry) === name);
|
|
47
|
+
if (index === -1) {
|
|
48
|
+
reporters.push([name, options]);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const existing = reporters[index];
|
|
52
|
+
if (Array.isArray(existing)) {
|
|
53
|
+
reporters[index] = [name, { ...(existing[1] || {}), ...options }];
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
reporters[index] = [name, options];
|
|
57
|
+
};
|
|
58
|
+
function withSentinel(config, options = {}) {
|
|
59
|
+
const nextConfig = {
|
|
60
|
+
...config,
|
|
61
|
+
use: {
|
|
62
|
+
...config.use,
|
|
63
|
+
trace: config.use?.trace || "retain-on-failure",
|
|
64
|
+
screenshot: config.use?.screenshot || "only-on-failure",
|
|
65
|
+
video: config.use?.video || "retain-on-failure"
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const reporters = normalizeReporter(config.reporter);
|
|
69
|
+
const existingJsonReporter = reporters.find((entry) => getReporterName(entry) === "json");
|
|
70
|
+
const existingHtmlReporter = reporters.find((entry) => getReporterName(entry) === "html");
|
|
71
|
+
const existingJsonOutputFile = getReporterOptions(existingJsonReporter).outputFile;
|
|
72
|
+
const existingHtmlOutputFolder = getReporterOptions(existingHtmlReporter).outputFolder;
|
|
73
|
+
const testResultsDir = options.testResultsDir || config.outputDir || DEFAULT_TEST_RESULTS_DIR;
|
|
74
|
+
const playwrightReportDir = options.playwrightReportDir ||
|
|
75
|
+
(typeof existingHtmlOutputFolder === "string"
|
|
76
|
+
? existingHtmlOutputFolder
|
|
77
|
+
: DEFAULT_REPORT_DIR);
|
|
78
|
+
const playwrightJsonPath = options.playwrightJsonPath ||
|
|
79
|
+
(typeof existingJsonOutputFile === "string"
|
|
80
|
+
? existingJsonOutputFile
|
|
81
|
+
: path_1.default.join(playwrightReportDir, "report.json"));
|
|
82
|
+
const artifactDirs = Array.from(new Set((options.artifactDirs || [])
|
|
83
|
+
.filter(Boolean)
|
|
84
|
+
.map((entry) => normalizePath(entry))));
|
|
85
|
+
nextConfig.outputDir = testResultsDir;
|
|
86
|
+
setReporterOptions(reporters, "json", { outputFile: playwrightJsonPath });
|
|
87
|
+
setReporterOptions(reporters, "html", {
|
|
88
|
+
outputFolder: playwrightReportDir,
|
|
89
|
+
open: "never"
|
|
90
|
+
});
|
|
91
|
+
const sentinelReporterPath = require.resolve("./reporter");
|
|
92
|
+
const sentinelReporterOptions = {
|
|
93
|
+
project: options.project || null,
|
|
94
|
+
playwrightJsonPath,
|
|
95
|
+
playwrightReportDir,
|
|
96
|
+
testResultsDir,
|
|
97
|
+
artifactDirs,
|
|
98
|
+
verbose: options.verbose ?? false,
|
|
99
|
+
localReportDir: options.localReportDir,
|
|
100
|
+
localReportFileName: options.localReportFileName,
|
|
101
|
+
localRedirectFileName: options.localRedirectFileName
|
|
102
|
+
};
|
|
103
|
+
const sentinelIndex = reporters.findIndex((entry) => getReporterName(entry) === sentinelReporterPath);
|
|
104
|
+
if (sentinelIndex !== -1) {
|
|
105
|
+
reporters.splice(sentinelIndex, 1);
|
|
106
|
+
}
|
|
107
|
+
reporters.push([sentinelReporterPath, sentinelReporterOptions]);
|
|
108
|
+
nextConfig.reporter = reporters;
|
|
109
|
+
return nextConfig;
|
|
110
|
+
}
|
|
111
|
+
function resolveSentinelPaths(config, options = {}) {
|
|
112
|
+
const reporters = normalizeReporter(config.reporter);
|
|
113
|
+
const existingJsonReporter = reporters.find((entry) => getReporterName(entry) === "json");
|
|
114
|
+
const existingHtmlReporter = reporters.find((entry) => getReporterName(entry) === "html");
|
|
115
|
+
const existingJsonOutputFile = getReporterOptions(existingJsonReporter).outputFile;
|
|
116
|
+
const existingHtmlOutputFolder = getReporterOptions(existingHtmlReporter).outputFolder;
|
|
117
|
+
const testResultsDir = options.testResultsDir || config.outputDir || DEFAULT_TEST_RESULTS_DIR;
|
|
118
|
+
const playwrightReportDir = options.playwrightReportDir ||
|
|
119
|
+
(typeof existingHtmlOutputFolder === "string"
|
|
120
|
+
? existingHtmlOutputFolder
|
|
121
|
+
: DEFAULT_REPORT_DIR);
|
|
122
|
+
const playwrightJsonPath = options.playwrightJsonPath ||
|
|
123
|
+
(typeof existingJsonOutputFile === "string"
|
|
124
|
+
? existingJsonOutputFile
|
|
125
|
+
: path_1.default.join(playwrightReportDir, "report.json"));
|
|
126
|
+
const artifactDirs = Array.from(new Set((options.artifactDirs || [])
|
|
127
|
+
.filter(Boolean)
|
|
128
|
+
.map((entry) => normalizePath(entry))));
|
|
129
|
+
return {
|
|
130
|
+
playwrightJsonPath: normalizePath(playwrightJsonPath),
|
|
131
|
+
playwrightReportDir: normalizePath(playwrightReportDir),
|
|
132
|
+
testResultsDir: normalizePath(testResultsDir),
|
|
133
|
+
artifactDirs
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type ReporterSourcePaths = {
|
|
2
|
+
playwrightJsonPath: string;
|
|
3
|
+
playwrightReportDir: string;
|
|
4
|
+
testResultsDir: string;
|
|
5
|
+
artifactDirs: string[];
|
|
6
|
+
};
|
|
7
|
+
type LocalReportOptions = ReporterSourcePaths & {
|
|
8
|
+
reportDir?: string;
|
|
9
|
+
reportFileName?: string;
|
|
10
|
+
redirectFileName?: string;
|
|
11
|
+
};
|
|
12
|
+
type LocalReportSummary = {
|
|
13
|
+
total: number;
|
|
14
|
+
failed: number;
|
|
15
|
+
passed: number;
|
|
16
|
+
skipped: number;
|
|
17
|
+
};
|
|
18
|
+
type LocalReportResult = {
|
|
19
|
+
htmlPath: string;
|
|
20
|
+
redirectPath: string;
|
|
21
|
+
artifactCount: number;
|
|
22
|
+
summary: LocalReportSummary;
|
|
23
|
+
};
|
|
24
|
+
export declare function generateLocalDebugReport(options: LocalReportOptions): LocalReportResult;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateLocalDebugReport = generateLocalDebugReport;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
+
const DEFAULT_REPORT_DIR = "sentinel-report";
|
|
11
|
+
const DEFAULT_REPORT_FILE = "index.html";
|
|
12
|
+
const DEFAULT_REDIRECT_FILE = "sentinel-debug.html";
|
|
13
|
+
const SENTINEL_URL = "https://sentinelqa.com";
|
|
14
|
+
const ARTIFACT_EXTENSIONS = {
|
|
15
|
+
trace: [".zip"],
|
|
16
|
+
screenshot: [".png", ".jpg", ".jpeg", ".webp", ".gif"],
|
|
17
|
+
video: [".webm", ".mp4", ".mov"],
|
|
18
|
+
log: [".log", ".txt", ".jsonl"],
|
|
19
|
+
network: [".har"],
|
|
20
|
+
report: [".html", ".json"],
|
|
21
|
+
attachment: []
|
|
22
|
+
};
|
|
23
|
+
const escapeHtml = (value) => value
|
|
24
|
+
.replace(/&/g, "&")
|
|
25
|
+
.replace(/</g, "<")
|
|
26
|
+
.replace(/>/g, ">")
|
|
27
|
+
.replace(/"/g, """)
|
|
28
|
+
.replace(/'/g, "'");
|
|
29
|
+
const ensureDir = (dirPath) => {
|
|
30
|
+
fs_1.default.mkdirSync(dirPath, { recursive: true });
|
|
31
|
+
};
|
|
32
|
+
const safeSlug = (value) => {
|
|
33
|
+
return (value
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
36
|
+
.replace(/^-+|-+$/g, "")
|
|
37
|
+
.slice(0, 64) || "artifact");
|
|
38
|
+
};
|
|
39
|
+
const formatDuration = (durationMs) => {
|
|
40
|
+
if (!Number.isFinite(durationMs) || durationMs <= 0)
|
|
41
|
+
return "0 ms";
|
|
42
|
+
if (durationMs < 1000)
|
|
43
|
+
return `${Math.round(durationMs)} ms`;
|
|
44
|
+
return `${(durationMs / 1000).toFixed(durationMs >= 10000 ? 0 : 1)} s`;
|
|
45
|
+
};
|
|
46
|
+
const relativeFromCwd = (targetPath) => {
|
|
47
|
+
const relative = path_1.default.relative(process.cwd(), targetPath).replace(/\\/g, "/");
|
|
48
|
+
if (!relative || relative === "")
|
|
49
|
+
return ".";
|
|
50
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
51
|
+
};
|
|
52
|
+
const isRelevantArtifact = (filePath) => {
|
|
53
|
+
const lower = path_1.default.basename(filePath).toLowerCase();
|
|
54
|
+
if (lower === "index.html" || lower === "report.json")
|
|
55
|
+
return true;
|
|
56
|
+
return Object.values(ARTIFACT_EXTENSIONS)
|
|
57
|
+
.flat()
|
|
58
|
+
.some((ext) => lower.endsWith(ext));
|
|
59
|
+
};
|
|
60
|
+
const classifyArtifact = (filePath) => {
|
|
61
|
+
const lower = path_1.default.basename(filePath).toLowerCase();
|
|
62
|
+
if (lower.includes("trace") && lower.endsWith(".zip"))
|
|
63
|
+
return "trace";
|
|
64
|
+
if (ARTIFACT_EXTENSIONS.screenshot.some((ext) => lower.endsWith(ext))) {
|
|
65
|
+
return "screenshot";
|
|
66
|
+
}
|
|
67
|
+
if (ARTIFACT_EXTENSIONS.video.some((ext) => lower.endsWith(ext))) {
|
|
68
|
+
return "video";
|
|
69
|
+
}
|
|
70
|
+
if (ARTIFACT_EXTENSIONS.log.some((ext) => lower.endsWith(ext))) {
|
|
71
|
+
return "log";
|
|
72
|
+
}
|
|
73
|
+
if (ARTIFACT_EXTENSIONS.network.some((ext) => lower.endsWith(ext))) {
|
|
74
|
+
return "network";
|
|
75
|
+
}
|
|
76
|
+
if (ARTIFACT_EXTENSIONS.report.some((ext) => lower.endsWith(ext))) {
|
|
77
|
+
return "report";
|
|
78
|
+
}
|
|
79
|
+
if (lower.endsWith(".zip"))
|
|
80
|
+
return "trace";
|
|
81
|
+
return "attachment";
|
|
82
|
+
};
|
|
83
|
+
const listFilesRecursive = (dirPath) => {
|
|
84
|
+
if (!fs_1.default.existsSync(dirPath) || !fs_1.default.statSync(dirPath).isDirectory())
|
|
85
|
+
return [];
|
|
86
|
+
const results = [];
|
|
87
|
+
for (const entry of fs_1.default.readdirSync(dirPath, { withFileTypes: true })) {
|
|
88
|
+
const fullPath = path_1.default.join(dirPath, entry.name);
|
|
89
|
+
if (entry.isDirectory()) {
|
|
90
|
+
results.push(...listFilesRecursive(fullPath));
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (entry.isFile() && isRelevantArtifact(fullPath)) {
|
|
94
|
+
results.push(fullPath);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return results;
|
|
98
|
+
};
|
|
99
|
+
const dedupePaths = (paths) => {
|
|
100
|
+
return Array.from(new Set(paths.map((entry) => path_1.default.resolve(entry))));
|
|
101
|
+
};
|
|
102
|
+
const resolveExistingFile = (candidate, baseDirs) => {
|
|
103
|
+
if (!candidate)
|
|
104
|
+
return null;
|
|
105
|
+
const attempts = path_1.default.isAbsolute(candidate)
|
|
106
|
+
? [candidate]
|
|
107
|
+
: baseDirs.map((baseDir) => path_1.default.resolve(baseDir, candidate));
|
|
108
|
+
for (const attempt of attempts) {
|
|
109
|
+
if (!fs_1.default.existsSync(attempt))
|
|
110
|
+
continue;
|
|
111
|
+
const stat = fs_1.default.statSync(attempt);
|
|
112
|
+
if (stat.isFile())
|
|
113
|
+
return attempt;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
};
|
|
117
|
+
const copyArtifact = (sourcePath, kind, reportDir, usedRelativePaths, testId) => {
|
|
118
|
+
const hash = crypto_1.default
|
|
119
|
+
.createHash("sha1")
|
|
120
|
+
.update(sourcePath)
|
|
121
|
+
.digest("hex")
|
|
122
|
+
.slice(0, 10);
|
|
123
|
+
const sourceName = path_1.default.basename(sourcePath);
|
|
124
|
+
const candidateName = `${safeSlug(path_1.default.parse(sourceName).name)}-${hash}${path_1.default.extname(sourceName)}`;
|
|
125
|
+
let relativePath = path_1.default.join("artifacts", candidateName).replace(/\\/g, "/");
|
|
126
|
+
if (usedRelativePaths.has(relativePath)) {
|
|
127
|
+
relativePath = path_1.default
|
|
128
|
+
.join("artifacts", `${safeSlug(path_1.default.parse(sourceName).name)}-${hash}-1${path_1.default.extname(sourceName)}`)
|
|
129
|
+
.replace(/\\/g, "/");
|
|
130
|
+
}
|
|
131
|
+
usedRelativePaths.add(relativePath);
|
|
132
|
+
const destination = path_1.default.join(reportDir, relativePath);
|
|
133
|
+
ensureDir(path_1.default.dirname(destination));
|
|
134
|
+
fs_1.default.copyFileSync(sourcePath, destination);
|
|
135
|
+
return {
|
|
136
|
+
sourcePath,
|
|
137
|
+
fileName: path_1.default.basename(destination),
|
|
138
|
+
relativePath,
|
|
139
|
+
kind,
|
|
140
|
+
label: sourceName,
|
|
141
|
+
testId
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
const flattenTests = (node, parentTitles = []) => {
|
|
145
|
+
const nextTitles = node?.title ? [...parentTitles, node.title] : parentTitles;
|
|
146
|
+
const currentTests = Array.isArray(node?.tests)
|
|
147
|
+
? node.tests.map((test) => {
|
|
148
|
+
const titlePath = [...nextTitles, test.title].filter(Boolean);
|
|
149
|
+
const results = Array.isArray(test.results) ? test.results : [];
|
|
150
|
+
const lastResult = results.length > 0 ? results[results.length - 1] : null;
|
|
151
|
+
const errors = results.flatMap((result) => Array.isArray(result?.errors)
|
|
152
|
+
? result.errors
|
|
153
|
+
.map((error) => error?.message || error?.stack || String(error || ""))
|
|
154
|
+
.filter(Boolean)
|
|
155
|
+
: []);
|
|
156
|
+
const duration = results.reduce((total, result) => total + (Number(result?.duration) || 0), 0);
|
|
157
|
+
const id = [
|
|
158
|
+
test.location?.file || "unknown",
|
|
159
|
+
test.projectName || "default",
|
|
160
|
+
titlePath.join(" > ")
|
|
161
|
+
].join("::");
|
|
162
|
+
return {
|
|
163
|
+
id,
|
|
164
|
+
title: test.title || "Untitled test",
|
|
165
|
+
titlePath,
|
|
166
|
+
file: test.location?.file || null,
|
|
167
|
+
projectName: test.projectName || null,
|
|
168
|
+
status: test.status || lastResult?.status || "unknown",
|
|
169
|
+
duration,
|
|
170
|
+
errors,
|
|
171
|
+
artifacts: []
|
|
172
|
+
};
|
|
173
|
+
})
|
|
174
|
+
: [];
|
|
175
|
+
const childTests = Array.isArray(node?.suites)
|
|
176
|
+
? node.suites.flatMap((suite) => flattenTests(suite, nextTitles))
|
|
177
|
+
: [];
|
|
178
|
+
return [...currentTests, ...childTests];
|
|
179
|
+
};
|
|
180
|
+
const summarizeTests = (tests) => {
|
|
181
|
+
return tests.reduce((summary, test) => {
|
|
182
|
+
summary.total += 1;
|
|
183
|
+
if (test.status === "passed")
|
|
184
|
+
summary.passed += 1;
|
|
185
|
+
else if (test.status === "skipped")
|
|
186
|
+
summary.skipped += 1;
|
|
187
|
+
else if (["failed", "timedOut", "interrupted"].includes(test.status)) {
|
|
188
|
+
summary.failed += 1;
|
|
189
|
+
}
|
|
190
|
+
return summary;
|
|
191
|
+
}, { total: 0, failed: 0, passed: 0, skipped: 0 });
|
|
192
|
+
};
|
|
193
|
+
const renderArtifact = (artifact) => {
|
|
194
|
+
const href = escapeHtml(artifact.relativePath);
|
|
195
|
+
const label = escapeHtml(artifact.label);
|
|
196
|
+
if (artifact.kind === "screenshot") {
|
|
197
|
+
return `
|
|
198
|
+
<div class="artifact-card">
|
|
199
|
+
<div class="artifact-meta">
|
|
200
|
+
<span class="artifact-kind">Screenshot</span>
|
|
201
|
+
<a href="${href}" target="_blank" rel="noreferrer">${label}</a>
|
|
202
|
+
</div>
|
|
203
|
+
<img src="${href}" alt="${label}" loading="lazy" />
|
|
204
|
+
</div>
|
|
205
|
+
`;
|
|
206
|
+
}
|
|
207
|
+
if (artifact.kind === "video") {
|
|
208
|
+
return `
|
|
209
|
+
<div class="artifact-card">
|
|
210
|
+
<div class="artifact-meta">
|
|
211
|
+
<span class="artifact-kind">Video</span>
|
|
212
|
+
<a href="${href}" target="_blank" rel="noreferrer">${label}</a>
|
|
213
|
+
</div>
|
|
214
|
+
<video controls preload="metadata" src="${href}"></video>
|
|
215
|
+
</div>
|
|
216
|
+
`;
|
|
217
|
+
}
|
|
218
|
+
return `
|
|
219
|
+
<div class="artifact-link">
|
|
220
|
+
<span class="artifact-kind">${escapeHtml(artifact.kind)}</span>
|
|
221
|
+
<a href="${href}" target="_blank" rel="noreferrer">${label}</a>
|
|
222
|
+
</div>
|
|
223
|
+
`;
|
|
224
|
+
};
|
|
225
|
+
const renderTestCard = (test) => {
|
|
226
|
+
const statusClass = test.status === "passed" ? "status-passed" : "status-failed";
|
|
227
|
+
const fileLine = test.file ? `<div class="meta-item">${escapeHtml(test.file)}</div>` : "";
|
|
228
|
+
const projectLine = test.projectName
|
|
229
|
+
? `<div class="meta-item">Project: ${escapeHtml(test.projectName)}</div>`
|
|
230
|
+
: "";
|
|
231
|
+
const errorBlock = test.errors.length > 0
|
|
232
|
+
? `<pre>${escapeHtml(test.errors.join("\n\n"))}</pre>`
|
|
233
|
+
: `<pre>No error message was attached to this result.</pre>`;
|
|
234
|
+
const artifactMarkup = test.artifacts.length > 0
|
|
235
|
+
? test.artifacts.map((artifact) => renderArtifact(artifact)).join("\n")
|
|
236
|
+
: `<div class="empty-state">No test-linked artifacts were detected for this result.</div>`;
|
|
237
|
+
return `
|
|
238
|
+
<section class="test-card">
|
|
239
|
+
<div class="test-head">
|
|
240
|
+
<div>
|
|
241
|
+
<div class="status-pill ${statusClass}">${escapeHtml(test.status)}</div>
|
|
242
|
+
<h3>${escapeHtml(test.titlePath.join(" > ") || test.title)}</h3>
|
|
243
|
+
</div>
|
|
244
|
+
<div class="meta-stack">
|
|
245
|
+
${fileLine}
|
|
246
|
+
${projectLine}
|
|
247
|
+
<div class="meta-item">Duration: ${escapeHtml(formatDuration(test.duration))}</div>
|
|
248
|
+
</div>
|
|
249
|
+
</div>
|
|
250
|
+
<div class="panel">
|
|
251
|
+
<h4>Error</h4>
|
|
252
|
+
${errorBlock}
|
|
253
|
+
</div>
|
|
254
|
+
<div class="panel">
|
|
255
|
+
<h4>Artifacts</h4>
|
|
256
|
+
<div class="artifact-grid">
|
|
257
|
+
${artifactMarkup}
|
|
258
|
+
</div>
|
|
259
|
+
</div>
|
|
260
|
+
</section>
|
|
261
|
+
`;
|
|
262
|
+
};
|
|
263
|
+
const renderAdditionalArtifacts = (artifacts) => {
|
|
264
|
+
if (artifacts.length === 0) {
|
|
265
|
+
return `<div class="empty-state">No additional Playwright artifacts were detected.</div>`;
|
|
266
|
+
}
|
|
267
|
+
return `
|
|
268
|
+
<div class="artifact-list">
|
|
269
|
+
${artifacts
|
|
270
|
+
.map((artifact) => `
|
|
271
|
+
<div class="artifact-link">
|
|
272
|
+
<span class="artifact-kind">${escapeHtml(artifact.kind)}</span>
|
|
273
|
+
<a href="${escapeHtml(artifact.relativePath)}" target="_blank" rel="noreferrer">
|
|
274
|
+
${escapeHtml(artifact.label)}
|
|
275
|
+
</a>
|
|
276
|
+
</div>
|
|
277
|
+
`)
|
|
278
|
+
.join("\n")}
|
|
279
|
+
</div>
|
|
280
|
+
`;
|
|
281
|
+
};
|
|
282
|
+
const buildHtml = (tests, summary, extraArtifacts) => {
|
|
283
|
+
const failedTests = tests.filter((test) => ["failed", "timedOut", "interrupted"].includes(test.status));
|
|
284
|
+
const generatedAt = new Date().toLocaleString();
|
|
285
|
+
return `<!doctype html>
|
|
286
|
+
<html lang="en">
|
|
287
|
+
<head>
|
|
288
|
+
<meta charset="utf-8" />
|
|
289
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
290
|
+
<title>Sentinel Playwright Reporter</title>
|
|
291
|
+
<style>
|
|
292
|
+
:root {
|
|
293
|
+
color-scheme: dark;
|
|
294
|
+
--bg: #0d1117;
|
|
295
|
+
--panel: #161b22;
|
|
296
|
+
--panel-border: #273042;
|
|
297
|
+
--text: #f5f7fb;
|
|
298
|
+
--muted: #98a2b3;
|
|
299
|
+
--accent: #7dd3fc;
|
|
300
|
+
--accent-soft: rgba(125, 211, 252, 0.14);
|
|
301
|
+
--danger: #fb7185;
|
|
302
|
+
--success: #4ade80;
|
|
303
|
+
}
|
|
304
|
+
* { box-sizing: border-box; }
|
|
305
|
+
body {
|
|
306
|
+
margin: 0;
|
|
307
|
+
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
308
|
+
background:
|
|
309
|
+
radial-gradient(circle at top left, rgba(125, 211, 252, 0.12), transparent 30%),
|
|
310
|
+
linear-gradient(180deg, #0b1020 0%, var(--bg) 42%, #090d14 100%);
|
|
311
|
+
color: var(--text);
|
|
312
|
+
}
|
|
313
|
+
a { color: var(--accent); text-decoration: none; }
|
|
314
|
+
a:hover { text-decoration: underline; }
|
|
315
|
+
.page {
|
|
316
|
+
max-width: 1200px;
|
|
317
|
+
margin: 0 auto;
|
|
318
|
+
padding: 40px 20px 80px;
|
|
319
|
+
}
|
|
320
|
+
.hero {
|
|
321
|
+
padding: 28px;
|
|
322
|
+
border: 1px solid var(--panel-border);
|
|
323
|
+
border-radius: 24px;
|
|
324
|
+
background: rgba(13, 17, 23, 0.88);
|
|
325
|
+
backdrop-filter: blur(12px);
|
|
326
|
+
}
|
|
327
|
+
.eyebrow {
|
|
328
|
+
color: var(--accent);
|
|
329
|
+
text-transform: uppercase;
|
|
330
|
+
letter-spacing: 0.18em;
|
|
331
|
+
font-size: 12px;
|
|
332
|
+
margin-bottom: 12px;
|
|
333
|
+
}
|
|
334
|
+
h1, h2, h3, h4 { margin: 0; }
|
|
335
|
+
h1 { font-size: clamp(32px, 5vw, 52px); line-height: 1; }
|
|
336
|
+
.hero p {
|
|
337
|
+
margin: 14px 0 0;
|
|
338
|
+
color: var(--muted);
|
|
339
|
+
max-width: 760px;
|
|
340
|
+
font-size: 16px;
|
|
341
|
+
line-height: 1.6;
|
|
342
|
+
}
|
|
343
|
+
.summary-grid, .mode-grid {
|
|
344
|
+
display: grid;
|
|
345
|
+
gap: 16px;
|
|
346
|
+
margin-top: 24px;
|
|
347
|
+
}
|
|
348
|
+
.summary-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
|
|
349
|
+
.mode-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
|
|
350
|
+
.summary-card, .mode-card, .section-shell, .test-card {
|
|
351
|
+
border: 1px solid var(--panel-border);
|
|
352
|
+
border-radius: 20px;
|
|
353
|
+
background: var(--panel);
|
|
354
|
+
}
|
|
355
|
+
.summary-card, .mode-card {
|
|
356
|
+
padding: 18px;
|
|
357
|
+
}
|
|
358
|
+
.summary-label {
|
|
359
|
+
display: block;
|
|
360
|
+
color: var(--muted);
|
|
361
|
+
font-size: 12px;
|
|
362
|
+
text-transform: uppercase;
|
|
363
|
+
letter-spacing: 0.14em;
|
|
364
|
+
}
|
|
365
|
+
.summary-value {
|
|
366
|
+
display: block;
|
|
367
|
+
margin-top: 10px;
|
|
368
|
+
font-size: 34px;
|
|
369
|
+
font-weight: 700;
|
|
370
|
+
}
|
|
371
|
+
.section-shell {
|
|
372
|
+
padding: 24px;
|
|
373
|
+
margin-top: 24px;
|
|
374
|
+
}
|
|
375
|
+
.section-shell p {
|
|
376
|
+
margin: 8px 0 0;
|
|
377
|
+
color: var(--muted);
|
|
378
|
+
line-height: 1.6;
|
|
379
|
+
}
|
|
380
|
+
.diagram {
|
|
381
|
+
margin-top: 18px;
|
|
382
|
+
padding: 18px;
|
|
383
|
+
border-radius: 16px;
|
|
384
|
+
background: rgba(125, 211, 252, 0.06);
|
|
385
|
+
border: 1px dashed rgba(125, 211, 252, 0.3);
|
|
386
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
387
|
+
white-space: pre-line;
|
|
388
|
+
color: #d7e2f0;
|
|
389
|
+
}
|
|
390
|
+
.mode-card h3 { font-size: 18px; }
|
|
391
|
+
.mode-card p { color: var(--muted); line-height: 1.6; }
|
|
392
|
+
.test-card {
|
|
393
|
+
padding: 20px;
|
|
394
|
+
margin-top: 18px;
|
|
395
|
+
}
|
|
396
|
+
.test-head {
|
|
397
|
+
display: flex;
|
|
398
|
+
justify-content: space-between;
|
|
399
|
+
gap: 20px;
|
|
400
|
+
align-items: flex-start;
|
|
401
|
+
}
|
|
402
|
+
.status-pill {
|
|
403
|
+
display: inline-flex;
|
|
404
|
+
align-items: center;
|
|
405
|
+
padding: 6px 10px;
|
|
406
|
+
border-radius: 999px;
|
|
407
|
+
font-size: 12px;
|
|
408
|
+
letter-spacing: 0.08em;
|
|
409
|
+
text-transform: uppercase;
|
|
410
|
+
margin-bottom: 12px;
|
|
411
|
+
}
|
|
412
|
+
.status-passed { background: rgba(74, 222, 128, 0.12); color: var(--success); }
|
|
413
|
+
.status-failed { background: rgba(251, 113, 133, 0.12); color: var(--danger); }
|
|
414
|
+
.meta-stack {
|
|
415
|
+
min-width: 220px;
|
|
416
|
+
display: grid;
|
|
417
|
+
gap: 6px;
|
|
418
|
+
color: var(--muted);
|
|
419
|
+
font-size: 14px;
|
|
420
|
+
}
|
|
421
|
+
.panel {
|
|
422
|
+
margin-top: 18px;
|
|
423
|
+
padding: 16px;
|
|
424
|
+
background: rgba(13, 17, 23, 0.74);
|
|
425
|
+
border: 1px solid rgba(39, 48, 66, 0.9);
|
|
426
|
+
border-radius: 16px;
|
|
427
|
+
}
|
|
428
|
+
pre {
|
|
429
|
+
white-space: pre-wrap;
|
|
430
|
+
overflow-wrap: anywhere;
|
|
431
|
+
margin: 12px 0 0;
|
|
432
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
433
|
+
font-size: 13px;
|
|
434
|
+
color: #d5dde8;
|
|
435
|
+
}
|
|
436
|
+
.artifact-grid {
|
|
437
|
+
display: grid;
|
|
438
|
+
gap: 14px;
|
|
439
|
+
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
|
440
|
+
margin-top: 12px;
|
|
441
|
+
}
|
|
442
|
+
.artifact-card, .artifact-link {
|
|
443
|
+
border: 1px solid rgba(39, 48, 66, 0.9);
|
|
444
|
+
border-radius: 14px;
|
|
445
|
+
background: rgba(9, 13, 20, 0.9);
|
|
446
|
+
padding: 12px;
|
|
447
|
+
}
|
|
448
|
+
.artifact-card img, .artifact-card video {
|
|
449
|
+
width: 100%;
|
|
450
|
+
border-radius: 10px;
|
|
451
|
+
margin-top: 12px;
|
|
452
|
+
background: #05070b;
|
|
453
|
+
}
|
|
454
|
+
.artifact-meta {
|
|
455
|
+
display: flex;
|
|
456
|
+
justify-content: space-between;
|
|
457
|
+
gap: 12px;
|
|
458
|
+
align-items: center;
|
|
459
|
+
}
|
|
460
|
+
.artifact-kind {
|
|
461
|
+
display: inline-flex;
|
|
462
|
+
align-items: center;
|
|
463
|
+
width: fit-content;
|
|
464
|
+
padding: 4px 8px;
|
|
465
|
+
border-radius: 999px;
|
|
466
|
+
background: var(--accent-soft);
|
|
467
|
+
color: var(--accent);
|
|
468
|
+
font-size: 11px;
|
|
469
|
+
text-transform: uppercase;
|
|
470
|
+
letter-spacing: 0.08em;
|
|
471
|
+
}
|
|
472
|
+
.artifact-list {
|
|
473
|
+
display: grid;
|
|
474
|
+
gap: 12px;
|
|
475
|
+
margin-top: 16px;
|
|
476
|
+
}
|
|
477
|
+
.empty-state {
|
|
478
|
+
color: var(--muted);
|
|
479
|
+
border: 1px dashed rgba(39, 48, 66, 0.9);
|
|
480
|
+
border-radius: 14px;
|
|
481
|
+
padding: 16px;
|
|
482
|
+
}
|
|
483
|
+
footer {
|
|
484
|
+
margin-top: 28px;
|
|
485
|
+
color: var(--muted);
|
|
486
|
+
font-size: 14px;
|
|
487
|
+
}
|
|
488
|
+
@media (max-width: 720px) {
|
|
489
|
+
.test-head { flex-direction: column; }
|
|
490
|
+
.meta-stack { min-width: 0; }
|
|
491
|
+
}
|
|
492
|
+
</style>
|
|
493
|
+
</head>
|
|
494
|
+
<body>
|
|
495
|
+
<div class="page">
|
|
496
|
+
<header class="hero">
|
|
497
|
+
<div class="eyebrow">Playwright Reporter for CI Debugging</div>
|
|
498
|
+
<h1>Sentinel Playwright Reporter</h1>
|
|
499
|
+
<p>
|
|
500
|
+
A Playwright reporter that collects traces, screenshots, videos, and logs into
|
|
501
|
+
a single debugging report. Designed to make CI failures easier to diagnose.
|
|
502
|
+
</p>
|
|
503
|
+
<div class="summary-grid">
|
|
504
|
+
<div class="summary-card">
|
|
505
|
+
<span class="summary-label">Tests</span>
|
|
506
|
+
<span class="summary-value">${summary.total}</span>
|
|
507
|
+
</div>
|
|
508
|
+
<div class="summary-card">
|
|
509
|
+
<span class="summary-label">Failed</span>
|
|
510
|
+
<span class="summary-value">${summary.failed}</span>
|
|
511
|
+
</div>
|
|
512
|
+
<div class="summary-card">
|
|
513
|
+
<span class="summary-label">Passed</span>
|
|
514
|
+
<span class="summary-value">${summary.passed}</span>
|
|
515
|
+
</div>
|
|
516
|
+
<div class="summary-card">
|
|
517
|
+
<span class="summary-label">Generated</span>
|
|
518
|
+
<span class="summary-value" style="font-size: 22px;">${escapeHtml(generatedAt)}</span>
|
|
519
|
+
</div>
|
|
520
|
+
</div>
|
|
521
|
+
</header>
|
|
522
|
+
|
|
523
|
+
<section class="section-shell">
|
|
524
|
+
<h2>Modes</h2>
|
|
525
|
+
<div class="mode-grid">
|
|
526
|
+
<div class="mode-card">
|
|
527
|
+
<h3>Local Mode</h3>
|
|
528
|
+
<p>Generates debugging reports locally with traces, screenshots, videos, and logs copied into this report folder.</p>
|
|
529
|
+
</div>
|
|
530
|
+
<div class="mode-card">
|
|
531
|
+
<h3>Cloud Mode</h3>
|
|
532
|
+
<p>Uploads CI runs to Sentinel for team debugging, CI history, shareable links, and AI-generated failure summaries.</p>
|
|
533
|
+
</div>
|
|
534
|
+
</div>
|
|
535
|
+
</section>
|
|
536
|
+
|
|
537
|
+
<section class="section-shell">
|
|
538
|
+
<h2>Flow</h2>
|
|
539
|
+
<p>This reporter keeps the setup local-first and only adds Sentinel Cloud when a token is configured.</p>
|
|
540
|
+
<div class="diagram">Playwright CI
|
|
541
|
+
↓
|
|
542
|
+
Sentinel Reporter
|
|
543
|
+
↓
|
|
544
|
+
Artifacts Collected
|
|
545
|
+
↓
|
|
546
|
+
Local Debug Page OR Sentinel Cloud</div>
|
|
547
|
+
</section>
|
|
548
|
+
|
|
549
|
+
<section class="section-shell">
|
|
550
|
+
<h2>Failed Tests</h2>
|
|
551
|
+
${failedTests.length > 0
|
|
552
|
+
? failedTests.map((test) => renderTestCard(test)).join("\n")
|
|
553
|
+
: `<div class="empty-state">No failed tests were found in this run. The local report still includes collected artifacts below.</div>`}
|
|
554
|
+
</section>
|
|
555
|
+
|
|
556
|
+
<section class="section-shell">
|
|
557
|
+
<h2>Additional Artifacts</h2>
|
|
558
|
+
<p>Artifacts collected from Playwright output folders that were not directly attached to a single test.</p>
|
|
559
|
+
${renderAdditionalArtifacts(extraArtifacts)}
|
|
560
|
+
</section>
|
|
561
|
+
|
|
562
|
+
<footer>
|
|
563
|
+
Generated by <a href="${SENTINEL_URL}" target="_blank" rel="noreferrer">Sentinel Playwright Reporter</a>.
|
|
564
|
+
</footer>
|
|
565
|
+
</div>
|
|
566
|
+
</body>
|
|
567
|
+
</html>`;
|
|
568
|
+
};
|
|
569
|
+
function generateLocalDebugReport(options) {
|
|
570
|
+
const reportDir = path_1.default.resolve(process.cwd(), options.reportDir || DEFAULT_REPORT_DIR);
|
|
571
|
+
const reportFileName = options.reportFileName || DEFAULT_REPORT_FILE;
|
|
572
|
+
const redirectFileName = options.redirectFileName || DEFAULT_REDIRECT_FILE;
|
|
573
|
+
const reportHtmlPath = path_1.default.join(reportDir, reportFileName);
|
|
574
|
+
const redirectPath = path_1.default.resolve(process.cwd(), redirectFileName);
|
|
575
|
+
const usedRelativePaths = new Set();
|
|
576
|
+
ensureDir(reportDir);
|
|
577
|
+
const sourceDirs = dedupePaths([
|
|
578
|
+
options.testResultsDir,
|
|
579
|
+
options.playwrightReportDir,
|
|
580
|
+
...(options.artifactDirs || [])
|
|
581
|
+
].filter(Boolean));
|
|
582
|
+
const baseDirs = dedupePaths([
|
|
583
|
+
process.cwd(),
|
|
584
|
+
path_1.default.dirname(options.playwrightJsonPath),
|
|
585
|
+
...sourceDirs
|
|
586
|
+
]);
|
|
587
|
+
const reportJsonRaw = fs_1.default.readFileSync(options.playwrightJsonPath, "utf8");
|
|
588
|
+
const reportJson = JSON.parse(reportJsonRaw);
|
|
589
|
+
const tests = flattenTests({ suites: reportJson?.suites || [] });
|
|
590
|
+
const testsById = new Map(tests.map((test) => [test.id, test]));
|
|
591
|
+
const claimedSourcePaths = new Set();
|
|
592
|
+
const attachArtifactToTest = (sourcePath, testId) => {
|
|
593
|
+
const resolved = path_1.default.resolve(sourcePath);
|
|
594
|
+
if (claimedSourcePaths.has(resolved))
|
|
595
|
+
return;
|
|
596
|
+
const artifact = copyArtifact(resolved, classifyArtifact(resolved), reportDir, usedRelativePaths, testId);
|
|
597
|
+
claimedSourcePaths.add(resolved);
|
|
598
|
+
if (testId && testsById.has(testId)) {
|
|
599
|
+
testsById.get(testId).artifacts.push(artifact);
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
const walkSuites = (node, parentTitles = []) => {
|
|
604
|
+
const nextTitles = node?.title ? [...parentTitles, node.title] : parentTitles;
|
|
605
|
+
if (Array.isArray(node?.tests)) {
|
|
606
|
+
for (const test of node.tests) {
|
|
607
|
+
const titlePath = [...nextTitles, test.title].filter(Boolean);
|
|
608
|
+
const testId = [
|
|
609
|
+
test.location?.file || "unknown",
|
|
610
|
+
test.projectName || "default",
|
|
611
|
+
titlePath.join(" > ")
|
|
612
|
+
].join("::");
|
|
613
|
+
const resultList = Array.isArray(test.results) ? test.results : [];
|
|
614
|
+
for (const result of resultList) {
|
|
615
|
+
const attachments = Array.isArray(result?.attachments) ? result.attachments : [];
|
|
616
|
+
for (const attachment of attachments) {
|
|
617
|
+
const resolvedPath = resolveExistingFile(attachment?.path, baseDirs);
|
|
618
|
+
if (!resolvedPath)
|
|
619
|
+
continue;
|
|
620
|
+
attachArtifactToTest(resolvedPath, testId);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
if (Array.isArray(node?.suites)) {
|
|
626
|
+
for (const suite of node.suites)
|
|
627
|
+
walkSuites(suite, nextTitles);
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
walkSuites({ suites: reportJson?.suites || [] });
|
|
631
|
+
const extraArtifacts = [];
|
|
632
|
+
for (const sourceDir of sourceDirs) {
|
|
633
|
+
for (const filePath of listFilesRecursive(sourceDir)) {
|
|
634
|
+
const resolved = path_1.default.resolve(filePath);
|
|
635
|
+
if (claimedSourcePaths.has(resolved))
|
|
636
|
+
continue;
|
|
637
|
+
const artifact = copyArtifact(resolved, classifyArtifact(resolved), reportDir, usedRelativePaths, null);
|
|
638
|
+
claimedSourcePaths.add(resolved);
|
|
639
|
+
extraArtifacts.push(artifact);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
const summary = summarizeTests(tests);
|
|
643
|
+
const html = buildHtml(tests, summary, extraArtifacts);
|
|
644
|
+
fs_1.default.writeFileSync(reportHtmlPath, html, "utf8");
|
|
645
|
+
fs_1.default.writeFileSync(redirectPath, `<!doctype html><html lang="en"><head><meta charset="utf-8" /><meta http-equiv="refresh" content="0; url=${relativeFromCwd(reportHtmlPath)}" /><title>Sentinel Playwright Reporter</title></head><body><p>Open <a href="${relativeFromCwd(reportHtmlPath)}">${relativeFromCwd(reportHtmlPath)}</a>.</p></body></html>`, "utf8");
|
|
646
|
+
return {
|
|
647
|
+
htmlPath: reportHtmlPath,
|
|
648
|
+
redirectPath,
|
|
649
|
+
artifactCount: claimedSourcePaths.size,
|
|
650
|
+
summary
|
|
651
|
+
};
|
|
652
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type ReporterOptions = {
|
|
2
|
+
project?: string | null;
|
|
3
|
+
playwrightJsonPath: string;
|
|
4
|
+
playwrightReportDir: string;
|
|
5
|
+
testResultsDir: string;
|
|
6
|
+
artifactDirs?: string[];
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
localReportDir?: string;
|
|
9
|
+
localReportFileName?: string;
|
|
10
|
+
localRedirectFileName?: string;
|
|
11
|
+
};
|
|
12
|
+
declare class SentinelReporter {
|
|
13
|
+
private failedCount;
|
|
14
|
+
private totalCount;
|
|
15
|
+
private options;
|
|
16
|
+
constructor(options: ReporterOptions);
|
|
17
|
+
onBegin(config: any, suite: any): void;
|
|
18
|
+
onTestEnd(_test: any, result: any): void;
|
|
19
|
+
onEnd(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export = SentinelReporter;
|
package/dist/reporter.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const path_1 = __importDefault(require("path"));
|
|
6
|
+
const node_1 = require("@sentinelqa/uploader/node");
|
|
7
|
+
const env_1 = require("./env");
|
|
8
|
+
const localReport_1 = require("./localReport");
|
|
9
|
+
const pluralize = (count, singular, plural) => {
|
|
10
|
+
return count === 1 ? singular : plural;
|
|
11
|
+
};
|
|
12
|
+
class SentinelReporter {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.failedCount = 0;
|
|
15
|
+
this.totalCount = 0;
|
|
16
|
+
(0, env_1.loadSentinelEnv)();
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
onBegin(config, suite) {
|
|
20
|
+
this.totalCount = typeof suite?.allTests === "function" ? suite.allTests().length : 0;
|
|
21
|
+
if (config?.projects?.length && !this.options.project) {
|
|
22
|
+
this.options.project = config.projects[0]?.name || null;
|
|
23
|
+
}
|
|
24
|
+
if (this.options.verbose === true) {
|
|
25
|
+
console.log("Sentinel detected Playwright artifact paths:");
|
|
26
|
+
console.log(`- JSON report: ${this.options.playwrightJsonPath}`);
|
|
27
|
+
console.log(`- HTML report: ${this.options.playwrightReportDir}`);
|
|
28
|
+
console.log(`- Test results: ${this.options.testResultsDir}`);
|
|
29
|
+
for (const dir of this.options.artifactDirs || []) {
|
|
30
|
+
console.log(`- Extra artifacts: ${dir}`);
|
|
31
|
+
}
|
|
32
|
+
console.log("");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
onTestEnd(_test, result) {
|
|
36
|
+
if (!result)
|
|
37
|
+
return;
|
|
38
|
+
if (["failed", "timedOut", "interrupted"].includes(result.status)) {
|
|
39
|
+
this.failedCount += 1;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async onEnd() {
|
|
43
|
+
if (!process.env.SENTINEL_TOKEN) {
|
|
44
|
+
const localReport = (0, localReport_1.generateLocalDebugReport)({
|
|
45
|
+
playwrightJsonPath: this.options.playwrightJsonPath,
|
|
46
|
+
playwrightReportDir: this.options.playwrightReportDir,
|
|
47
|
+
testResultsDir: this.options.testResultsDir,
|
|
48
|
+
artifactDirs: this.options.artifactDirs || [],
|
|
49
|
+
reportDir: this.options.localReportDir,
|
|
50
|
+
reportFileName: this.options.localReportFileName,
|
|
51
|
+
redirectFileName: this.options.localRedirectFileName
|
|
52
|
+
});
|
|
53
|
+
console.log("");
|
|
54
|
+
console.log("✔ Artifacts collected");
|
|
55
|
+
console.log("✔ Sentinel debugging report generated");
|
|
56
|
+
console.log("");
|
|
57
|
+
console.log("Report location:");
|
|
58
|
+
const relativeReportPath = path_1.default
|
|
59
|
+
.relative(process.cwd(), localReport.htmlPath)
|
|
60
|
+
.replace(/\\/g, "/");
|
|
61
|
+
console.log(relativeReportPath.startsWith(".") ? relativeReportPath : `./${relativeReportPath}`);
|
|
62
|
+
console.log("");
|
|
63
|
+
console.log("Optional:");
|
|
64
|
+
console.log("Upload runs to Sentinel Cloud for:");
|
|
65
|
+
console.log("• CI history");
|
|
66
|
+
console.log("• shareable run links");
|
|
67
|
+
console.log("• AI failure summaries");
|
|
68
|
+
console.log("");
|
|
69
|
+
console.log("Learn more: https://sentinelqa.com");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
console.log("");
|
|
73
|
+
console.log("Uploading failure artifacts to Sentinel...");
|
|
74
|
+
console.log("");
|
|
75
|
+
const exitCode = await (0, node_1.runSentinelUpload)({
|
|
76
|
+
playwrightJsonPath: this.options.playwrightJsonPath,
|
|
77
|
+
playwrightReportDir: this.options.playwrightReportDir,
|
|
78
|
+
testResultsDir: this.options.testResultsDir,
|
|
79
|
+
artifactDirs: this.options.artifactDirs || [],
|
|
80
|
+
suppressSummaryJson: true,
|
|
81
|
+
env: {
|
|
82
|
+
SENTINEL_REPORTER_PROJECT: this.options.project || undefined
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
if (exitCode !== 0) {
|
|
86
|
+
throw new Error(`Sentinel upload failed with exit code ${exitCode}`);
|
|
87
|
+
}
|
|
88
|
+
console.log("");
|
|
89
|
+
console.log("✔ Uploaded run to Sentinel");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
module.exports = SentinelReporter;
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sentinelqa/playwright-reporter",
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Playwright reporter for CI debugging with optional Sentinel cloud dashboards",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/sentinelqa/sentinel"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"sentinelqa",
|
|
13
|
+
"playwright",
|
|
14
|
+
"ci",
|
|
15
|
+
"debugging",
|
|
16
|
+
"reporter"
|
|
17
|
+
],
|
|
18
|
+
"type": "commonjs",
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./dist/index.js",
|
|
31
|
+
"./reporter": "./dist/reporter.js"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@playwright/test": ">=1.40.0"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@sentinelqa/uploader": "^0.1.23"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"publish:dry": "npm run build && npm pack --dry-run"
|
|
42
|
+
}
|
|
43
|
+
}
|