@sentinelqa/playwright-reporter 0.1.47 → 0.1.50
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/dist/localReport.js +34 -11
- package/dist/quickDiagnosis.d.ts +68 -4
- package/dist/quickDiagnosis.js +813 -97
- package/dist/reporter.d.ts +1 -0
- package/dist/reporter.js +81 -20
- package/dist/runHistory.d.ts +4 -0
- package/dist/runHistory.js +113 -3
- package/dist/terminalSummary.d.ts +27 -1
- package/dist/terminalSummary.js +229 -40
- package/package.json +2 -2
package/dist/reporter.d.ts
CHANGED
package/dist/reporter.js
CHANGED
|
@@ -3,6 +3,7 @@ const node_1 = require("@sentinelqa/uploader/node");
|
|
|
3
3
|
const env_1 = require("./env");
|
|
4
4
|
const quickDiagnosis_1 = require("./quickDiagnosis");
|
|
5
5
|
const terminalSummary_1 = require("./terminalSummary");
|
|
6
|
+
const runHistory_1 = require("./runHistory");
|
|
6
7
|
const telemetry_1 = require("./telemetry");
|
|
7
8
|
const { sentinelCaptureFailureContextFromReporter } = require("@sentinelqa/uploader/playwright");
|
|
8
9
|
const colorize = (value, code) => {
|
|
@@ -13,14 +14,42 @@ const colorize = (value, code) => {
|
|
|
13
14
|
const green = (value) => colorize(value, "32");
|
|
14
15
|
const yellow = (value) => colorize(value, "33");
|
|
15
16
|
const dim = (value) => colorize(value, "2");
|
|
17
|
+
const readFinalFailedCount = (playwrightJsonPath) => {
|
|
18
|
+
try {
|
|
19
|
+
const parsed = JSON.parse(require("node:fs").readFileSync(playwrightJsonPath, "utf8"));
|
|
20
|
+
let failed = 0;
|
|
21
|
+
const walk = (node) => {
|
|
22
|
+
if (!node)
|
|
23
|
+
return;
|
|
24
|
+
for (const child of node.suites || [])
|
|
25
|
+
walk(child);
|
|
26
|
+
for (const child of node.specs || [])
|
|
27
|
+
walk(child);
|
|
28
|
+
for (const test of node.tests || []) {
|
|
29
|
+
const results = Array.isArray(test.results) ? test.results : [];
|
|
30
|
+
const finalStatus = results[results.length - 1]?.status || null;
|
|
31
|
+
if (finalStatus === "failed" || finalStatus === "timedOut" || finalStatus === "interrupted") {
|
|
32
|
+
failed += 1;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
walk(parsed);
|
|
37
|
+
return failed;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
16
43
|
class SentinelReporter {
|
|
17
44
|
constructor(options) {
|
|
18
45
|
this.failedCount = 0;
|
|
19
46
|
this.totalCount = 0;
|
|
47
|
+
this.startedAt = Date.now();
|
|
20
48
|
(0, env_1.loadSentinelEnv)();
|
|
21
49
|
this.options = options;
|
|
22
50
|
}
|
|
23
51
|
onBegin(config, suite) {
|
|
52
|
+
this.startedAt = Date.now();
|
|
24
53
|
(0, telemetry_1.emitReporterTelemetry)();
|
|
25
54
|
this.totalCount = typeof suite?.allTests === "function" ? suite.allTests().length : 0;
|
|
26
55
|
if (config?.projects?.length && !this.options.project) {
|
|
@@ -53,15 +82,16 @@ class SentinelReporter {
|
|
|
53
82
|
!hasCiEnv &&
|
|
54
83
|
!localUploadEnabled;
|
|
55
84
|
const quickDiagnosis = (0, quickDiagnosis_1.buildQuickDiagnosis)(this.options.playwrightJsonPath);
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
85
|
+
const finalFailedCount = readFinalFailedCount(this.options.playwrightJsonPath);
|
|
86
|
+
const effectiveFailedCount = typeof finalFailedCount === "number" ? finalFailedCount : this.failedCount;
|
|
87
|
+
const passingSummary = effectiveFailedCount === 0
|
|
88
|
+
? (0, terminalSummary_1.buildPassingRunSummary)(this.options.playwrightJsonPath, { observedRunDurationMs: Date.now() - this.startedAt })
|
|
89
|
+
: null;
|
|
90
|
+
const failedRunHistory = effectiveFailedCount > 0 ? (0, runHistory_1.buildFailedRunHistorySummary)(this.options.playwrightJsonPath) : null;
|
|
91
|
+
if (effectiveFailedCount > 0) {
|
|
92
|
+
(0, terminalSummary_1.recordReporterHistorySnapshot)(this.options.playwrightJsonPath);
|
|
64
93
|
}
|
|
94
|
+
console.log("");
|
|
65
95
|
if (passingSummary) {
|
|
66
96
|
console.log(green("Sentinel run summary"));
|
|
67
97
|
for (const line of passingSummary.lines) {
|
|
@@ -80,14 +110,13 @@ class SentinelReporter {
|
|
|
80
110
|
}
|
|
81
111
|
console.log("");
|
|
82
112
|
}
|
|
83
|
-
if (
|
|
84
|
-
await (0, telemetry_1.flushTelemetry)();
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (this.failedCount > 0) {
|
|
113
|
+
if (effectiveFailedCount > 0) {
|
|
88
114
|
(0, telemetry_1.emitFailedRunTelemetry)();
|
|
89
115
|
}
|
|
90
116
|
await (0, telemetry_1.flushTelemetry)();
|
|
117
|
+
if (effectiveFailedCount === 0) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
91
120
|
if (hasWorkspaceToken && !hasCiEnv && !localUploadEnabled) {
|
|
92
121
|
console.log([
|
|
93
122
|
"Sentinel: Upload skipped.",
|
|
@@ -104,12 +133,18 @@ class SentinelReporter {
|
|
|
104
133
|
console.log(green("✔ Artifacts collected"));
|
|
105
134
|
}
|
|
106
135
|
console.log("");
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
136
|
+
if (hasWorkspaceToken) {
|
|
137
|
+
console.log("Uploading hosted debugging report to Sentinel...");
|
|
138
|
+
}
|
|
139
|
+
else if (usingImplicitLocalPublicMode) {
|
|
140
|
+
console.log("Creating free hosted debug report with Sentinel...");
|
|
141
|
+
console.log(dim("No API key detected. Using the free public report flow for this local run."));
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
console.log("Creating free hosted debug report with Sentinel...");
|
|
110
145
|
}
|
|
111
146
|
console.log("");
|
|
112
|
-
const upload = await (0, node_1.runSentinelUpload)({
|
|
147
|
+
const upload = (await (0, node_1.runSentinelUpload)({
|
|
113
148
|
playwrightJsonPath: this.options.playwrightJsonPath,
|
|
114
149
|
playwrightReportDir: this.options.playwrightReportDir,
|
|
115
150
|
testResultsDir: this.options.testResultsDir,
|
|
@@ -120,19 +155,45 @@ class SentinelReporter {
|
|
|
120
155
|
SENTINEL_REPORTER_SILENT: "1",
|
|
121
156
|
SENTINEL_UPLOAD_LOCAL: usingImplicitLocalPublicMode ? "1" : process.env.SENTINEL_UPLOAD_LOCAL
|
|
122
157
|
}
|
|
123
|
-
});
|
|
158
|
+
}));
|
|
124
159
|
if (upload.exitCode !== 0) {
|
|
125
160
|
throw new Error(`Sentinel upload failed with exit code ${upload.exitCode}`);
|
|
126
161
|
}
|
|
162
|
+
const backendReady = upload.diagnosis?.status === "ready" && Boolean(upload.diagnosis?.lines?.length);
|
|
163
|
+
const diagnosis = backendReady ? upload.diagnosis : quickDiagnosis;
|
|
164
|
+
if (diagnosis?.lines.length) {
|
|
165
|
+
console.log("");
|
|
166
|
+
console.log(yellow("Sentinel diagnosis"));
|
|
167
|
+
for (const line of diagnosis.lines) {
|
|
168
|
+
console.log(` ${dim(line)}`);
|
|
169
|
+
}
|
|
170
|
+
if (diagnosis.footer?.length) {
|
|
171
|
+
console.log("");
|
|
172
|
+
for (const line of diagnosis.footer) {
|
|
173
|
+
console.log(` ${dim(line)}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const historyLines = failedRunHistory?.lines || [];
|
|
178
|
+
const normalizedHistory = backendReady
|
|
179
|
+
? historyLines.filter((line) => !line.includes("Seen before:"))
|
|
180
|
+
: historyLines;
|
|
181
|
+
if (normalizedHistory.length) {
|
|
182
|
+
console.log("");
|
|
183
|
+
console.log(yellow("Run context"));
|
|
184
|
+
for (const line of normalizedHistory) {
|
|
185
|
+
console.log(` ${dim(line)}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
127
188
|
console.log("");
|
|
128
|
-
console.log("
|
|
189
|
+
console.log("View full debug report");
|
|
129
190
|
console.log(` ${upload.shareRunUrl || upload.internalRunUrl}`);
|
|
130
191
|
if (upload.shareLabel) {
|
|
131
192
|
console.log(` ${dim(upload.shareLabel)}`);
|
|
132
193
|
}
|
|
133
194
|
if (!hasWorkspaceToken) {
|
|
134
195
|
console.log("");
|
|
135
|
-
console.log("
|
|
196
|
+
console.log("Create a free workspace to keep reports private, compare runs, and unlock deeper AI debugging");
|
|
136
197
|
console.log(` ${dim("https://sentinelqa.com/register")}`);
|
|
137
198
|
}
|
|
138
199
|
}
|
package/dist/runHistory.d.ts
CHANGED
|
@@ -3,5 +3,9 @@ type RunDiffSummary = {
|
|
|
3
3
|
fixedTests: number;
|
|
4
4
|
stillFailing: number;
|
|
5
5
|
};
|
|
6
|
+
export type FailedRunHistorySummary = {
|
|
7
|
+
lines: string[];
|
|
8
|
+
};
|
|
6
9
|
export declare const buildRunDiffSummary: (playwrightJsonPath: string) => RunDiffSummary | null;
|
|
10
|
+
export declare const buildFailedRunHistorySummary: (playwrightJsonPath: string) => FailedRunHistorySummary | null;
|
|
7
11
|
export {};
|
package/dist/runHistory.js
CHANGED
|
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.buildRunDiffSummary = void 0;
|
|
6
|
+
exports.buildFailedRunHistorySummary = exports.buildRunDiffSummary = void 0;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const quickDiagnosis_1 = require("./quickDiagnosis");
|
|
10
10
|
const SENTINEL_HISTORY_DIR = node_path_1.default.join(".sentinel", "history");
|
|
11
|
+
const REPORTER_HISTORY_DIR = node_path_1.default.join(".sentinel", "reporter-history");
|
|
11
12
|
const ensureDir = (dirPath) => {
|
|
12
13
|
if (!node_fs_1.default.existsSync(dirPath)) {
|
|
13
14
|
node_fs_1.default.mkdirSync(dirPath, { recursive: true });
|
|
@@ -76,6 +77,16 @@ const normalizeFailures = (snapshot) => {
|
|
|
76
77
|
}
|
|
77
78
|
return [];
|
|
78
79
|
};
|
|
80
|
+
const readJson = (filePath) => {
|
|
81
|
+
if (!node_fs_1.default.existsSync(filePath))
|
|
82
|
+
return null;
|
|
83
|
+
try {
|
|
84
|
+
return JSON.parse(node_fs_1.default.readFileSync(filePath, "utf8"));
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
79
90
|
const readSnapshot = (filePath) => {
|
|
80
91
|
if (!node_fs_1.default.existsSync(filePath))
|
|
81
92
|
return null;
|
|
@@ -86,6 +97,58 @@ const readSnapshot = (filePath) => {
|
|
|
86
97
|
return null;
|
|
87
98
|
}
|
|
88
99
|
};
|
|
100
|
+
const listSnapshots = (branch) => {
|
|
101
|
+
const historyDir = node_path_1.default.resolve(process.cwd(), SENTINEL_HISTORY_DIR);
|
|
102
|
+
if (!node_fs_1.default.existsSync(historyDir))
|
|
103
|
+
return [];
|
|
104
|
+
return node_fs_1.default
|
|
105
|
+
.readdirSync(historyDir)
|
|
106
|
+
.filter((file) => file.endsWith(".json"))
|
|
107
|
+
.map((file) => readSnapshot(node_path_1.default.join(historyDir, file)))
|
|
108
|
+
.filter((value) => Boolean(value))
|
|
109
|
+
.map((snapshot) => ({
|
|
110
|
+
generatedAt: typeof snapshot.generatedAt === "string" ? snapshot.generatedAt : new Date(0).toISOString(),
|
|
111
|
+
branch: typeof snapshot.branch === "string" ? snapshot.branch : branch,
|
|
112
|
+
gitSha: typeof snapshot.gitSha === "string" ? snapshot.gitSha : "unknown",
|
|
113
|
+
failures: normalizeFailures(snapshot)
|
|
114
|
+
}))
|
|
115
|
+
.filter((snapshot) => snapshot.branch === branch)
|
|
116
|
+
.sort((a, b) => b.generatedAt.localeCompare(a.generatedAt));
|
|
117
|
+
};
|
|
118
|
+
const isMeaningfulReporterSnapshot = (snapshot) => {
|
|
119
|
+
if (!snapshot)
|
|
120
|
+
return false;
|
|
121
|
+
if (snapshot.totalTests <= 0)
|
|
122
|
+
return false;
|
|
123
|
+
if ((snapshot.passedCount || 0) === 0 && (snapshot.failedCount || 0) === 0)
|
|
124
|
+
return false;
|
|
125
|
+
return true;
|
|
126
|
+
};
|
|
127
|
+
const listReporterSnapshots = (branch) => {
|
|
128
|
+
const historyDir = node_path_1.default.resolve(process.cwd(), REPORTER_HISTORY_DIR);
|
|
129
|
+
if (!node_fs_1.default.existsSync(historyDir))
|
|
130
|
+
return [];
|
|
131
|
+
return node_fs_1.default
|
|
132
|
+
.readdirSync(historyDir)
|
|
133
|
+
.filter((file) => file.endsWith(".json"))
|
|
134
|
+
.map((file) => readJson(node_path_1.default.join(historyDir, file)))
|
|
135
|
+
.filter((value) => Boolean(value))
|
|
136
|
+
.filter((snapshot) => snapshot.branch === branch)
|
|
137
|
+
.filter((snapshot) => isMeaningfulReporterSnapshot(snapshot))
|
|
138
|
+
.sort((a, b) => b.generatedAt.localeCompare(a.generatedAt));
|
|
139
|
+
};
|
|
140
|
+
const normalizeReporterFailures = (snapshot) => {
|
|
141
|
+
if (!snapshot)
|
|
142
|
+
return [];
|
|
143
|
+
return (snapshot.tests || [])
|
|
144
|
+
.filter((test) => test && test.status === "failed")
|
|
145
|
+
.map((test) => ({
|
|
146
|
+
id: typeof test.title === "string" ? test.title : test.matchKey,
|
|
147
|
+
matchKey: typeof test.matchKey === "string" ? test.matchKey : (typeof test.title === "string" ? test.title : "unknown"),
|
|
148
|
+
title: typeof test.title === "string" ? test.title : test.matchKey,
|
|
149
|
+
status: "failed"
|
|
150
|
+
}));
|
|
151
|
+
};
|
|
89
152
|
const writeSnapshot = (snapshot) => {
|
|
90
153
|
ensureDir(node_path_1.default.resolve(process.cwd(), ".sentinel"));
|
|
91
154
|
ensureDir(node_path_1.default.resolve(process.cwd(), SENTINEL_HISTORY_DIR));
|
|
@@ -96,6 +159,7 @@ const writeSnapshot = (snapshot) => {
|
|
|
96
159
|
node_fs_1.default.writeFileSync(node_path_1.default.resolve(process.cwd(), pointerPath), JSON.stringify({ path: historyPath, ...snapshot }, null, 2), "utf8");
|
|
97
160
|
}
|
|
98
161
|
};
|
|
162
|
+
const matchesFailure = (left, right) => left.id === right.id || left.matchKey === right.matchKey;
|
|
99
163
|
const buildRunDiffSummary = (playwrightJsonPath) => {
|
|
100
164
|
const snapshot = buildSnapshot(playwrightJsonPath);
|
|
101
165
|
const previous = readSnapshot(node_path_1.default.resolve(process.cwd(), ".sentinel", `latest-${snapshot.branch}.json`)) ||
|
|
@@ -105,12 +169,58 @@ const buildRunDiffSummary = (playwrightJsonPath) => {
|
|
|
105
169
|
const currentFailureMatchKeys = new Set(snapshot.failures.map((test) => test.matchKey));
|
|
106
170
|
const diff = previous && previous.generatedAt !== snapshot.generatedAt
|
|
107
171
|
? {
|
|
108
|
-
newFailures: snapshot.failures.filter((test) => !previousFailures.some((prev) => prev
|
|
172
|
+
newFailures: snapshot.failures.filter((test) => !previousFailures.some((prev) => matchesFailure(prev, test))).length,
|
|
109
173
|
fixedTests: previousFailures.filter((test) => !currentFailureIds.has(test.id) && !currentFailureMatchKeys.has(test.matchKey)).length,
|
|
110
|
-
stillFailing: snapshot.failures.filter((test) => previousFailures.some((prev) => prev
|
|
174
|
+
stillFailing: snapshot.failures.filter((test) => previousFailures.some((prev) => matchesFailure(prev, test))).length
|
|
111
175
|
}
|
|
112
176
|
: null;
|
|
113
177
|
writeSnapshot(snapshot);
|
|
114
178
|
return diff;
|
|
115
179
|
};
|
|
116
180
|
exports.buildRunDiffSummary = buildRunDiffSummary;
|
|
181
|
+
const buildFailedRunHistorySummary = (playwrightJsonPath) => {
|
|
182
|
+
const snapshot = buildSnapshot(playwrightJsonPath);
|
|
183
|
+
if (snapshot.failures.length === 0)
|
|
184
|
+
return null;
|
|
185
|
+
const reporterSnapshots = listReporterSnapshots(snapshot.branch);
|
|
186
|
+
const previousRun = reporterSnapshots[0] || null;
|
|
187
|
+
const previousFailures = normalizeReporterFailures(previousRun);
|
|
188
|
+
let passStreakBeforeFailure = 0;
|
|
189
|
+
for (const previous of reporterSnapshots) {
|
|
190
|
+
if ((previous.failedCount || 0) === 0) {
|
|
191
|
+
passStreakBeforeFailure += 1;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
const newFailures = snapshot.failures.filter((failure) => !previousFailures.some((prev) => matchesFailure(prev, failure))).length;
|
|
197
|
+
const fixedTests = previousFailures.filter((failure) => !snapshot.failures.some((current) => matchesFailure(current, failure))).length;
|
|
198
|
+
const stillFailing = snapshot.failures.filter((failure) => previousFailures.some((prev) => matchesFailure(prev, failure))).length;
|
|
199
|
+
const failingReporterRuns = reporterSnapshots.filter((run) => (run.failedCount || 0) > 0);
|
|
200
|
+
const recurringFailures = snapshot.failures
|
|
201
|
+
.map((failure) => ({
|
|
202
|
+
failure,
|
|
203
|
+
occurrences: failingReporterRuns.filter((run) => normalizeReporterFailures(run).some((prev) => matchesFailure(prev, failure))).length
|
|
204
|
+
}))
|
|
205
|
+
.sort((a, b) => b.occurrences - a.occurrences);
|
|
206
|
+
const topRecurring = recurringFailures.find((item) => item.occurrences > 0) || null;
|
|
207
|
+
writeSnapshot(snapshot);
|
|
208
|
+
const lines = [];
|
|
209
|
+
if (passStreakBeforeFailure > 0) {
|
|
210
|
+
lines.push(`- First failure after ${passStreakBeforeFailure} passing runs`);
|
|
211
|
+
}
|
|
212
|
+
if (previousRun && (newFailures > 0 || fixedTests > 0 || stillFailing > 0)) {
|
|
213
|
+
const previousWasGreen = (previousRun.failedCount || 0) === 0;
|
|
214
|
+
if (previousWasGreen) {
|
|
215
|
+
lines.push(`- The immediately previous run was green. Compared to that previous run: ${newFailures} newly failing in this run, ${stillFailing} still failing, ${fixedTests} no longer failing`);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
lines.push(`- Compared to the immediately previous run: ${newFailures} newly failing in this run, ${stillFailing} still failing, ${fixedTests} no longer failing`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (topRecurring) {
|
|
222
|
+
lines.push(`- Recurring across ${topRecurring.occurrences + 1} recorded failed runs in local history (${topRecurring.failure.title})`);
|
|
223
|
+
}
|
|
224
|
+
return lines.length ? { lines } : null;
|
|
225
|
+
};
|
|
226
|
+
exports.buildFailedRunHistorySummary = buildFailedRunHistorySummary;
|
|
@@ -1,5 +1,31 @@
|
|
|
1
|
+
type HistoryTest = {
|
|
2
|
+
matchKey: string;
|
|
3
|
+
title: string;
|
|
4
|
+
status: string;
|
|
5
|
+
durationMs: number;
|
|
6
|
+
retries: number;
|
|
7
|
+
timeoutMs: number | null;
|
|
8
|
+
};
|
|
9
|
+
type HistorySnapshot = {
|
|
10
|
+
generatedAt: string;
|
|
11
|
+
branch: string;
|
|
12
|
+
gitSha: string;
|
|
13
|
+
wallDurationMs: number | null;
|
|
14
|
+
totalTests: number;
|
|
15
|
+
passedCount: number;
|
|
16
|
+
failedCount: number;
|
|
17
|
+
skippedCount: number;
|
|
18
|
+
retryPassedCount: number;
|
|
19
|
+
failures: string[];
|
|
20
|
+
tests: HistoryTest[];
|
|
21
|
+
};
|
|
1
22
|
export type PassingRunSummary = {
|
|
2
23
|
lines: string[];
|
|
3
24
|
risks: string[];
|
|
4
25
|
};
|
|
5
|
-
|
|
26
|
+
type PassingRunSummaryOptions = {
|
|
27
|
+
observedRunDurationMs?: number | null;
|
|
28
|
+
};
|
|
29
|
+
export declare const recordReporterHistorySnapshot: (playwrightJsonPath: string) => HistorySnapshot;
|
|
30
|
+
export declare const buildPassingRunSummary: (playwrightJsonPath: string, options?: PassingRunSummaryOptions) => PassingRunSummary | null;
|
|
31
|
+
export {};
|