@testrelic/playwright-analytics 1.0.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/README.md +304 -0
- package/dist/cli.cjs +146 -0
- package/dist/fixture.cjs +291 -0
- package/dist/fixture.cjs.map +1 -0
- package/dist/fixture.d.cts +6 -0
- package/dist/fixture.d.ts +6 -0
- package/dist/fixture.js +265 -0
- package/dist/fixture.js.map +1 -0
- package/dist/index.cjs +773 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +100 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +745 -0
- package/dist/index.js.map +1 -0
- package/dist/merge.cjs +115 -0
- package/dist/merge.cjs.map +1 -0
- package/dist/merge.d.cts +12 -0
- package/dist/merge.d.ts +12 -0
- package/dist/merge.js +90 -0
- package/dist/merge.js.map +1 -0
- package/package.json +80 -0
- package/timeline-schema.json +190 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,773 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
SCHEMA_VERSION: () => SCHEMA_VERSION,
|
|
24
|
+
default: () => TestRelicReporter,
|
|
25
|
+
recordNavigation: () => recordNavigation
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/reporter.ts
|
|
30
|
+
var import_node_crypto = require("crypto");
|
|
31
|
+
var import_node_fs3 = require("fs");
|
|
32
|
+
var import_node_path2 = require("path");
|
|
33
|
+
|
|
34
|
+
// src/config.ts
|
|
35
|
+
var import_core = require("@testrelic/core");
|
|
36
|
+
var DEFAULT_REDACTION_PATTERNS = [
|
|
37
|
+
/AKIA[A-Z0-9]{16}/g,
|
|
38
|
+
/Bearer\s+[A-Za-z0-9\-._~+/]+=*/g,
|
|
39
|
+
/-----BEGIN\s+(RSA\s+)?PRIVATE\sKEY-----[\s\S]*?-----END/g,
|
|
40
|
+
/\/\/[^:]+:[^@]+@/g
|
|
41
|
+
];
|
|
42
|
+
function resolveConfig(options) {
|
|
43
|
+
if (options !== void 0 && !(0, import_core.isValidConfig)(options)) {
|
|
44
|
+
throw (0, import_core.createError)(import_core.ErrorCode.CONFIG_INVALID, "Invalid reporter configuration");
|
|
45
|
+
}
|
|
46
|
+
const target = /* @__PURE__ */ Object.create(null);
|
|
47
|
+
target.outputPath = options?.outputPath ?? "./test-results/analytics-timeline.json";
|
|
48
|
+
target.includeStackTrace = options?.includeStackTrace ?? false;
|
|
49
|
+
target.includeCodeSnippets = options?.includeCodeSnippets ?? true;
|
|
50
|
+
target.codeContextLines = options?.codeContextLines ?? 3;
|
|
51
|
+
target.includeNetworkStats = options?.includeNetworkStats ?? true;
|
|
52
|
+
target.navigationTypes = options?.navigationTypes ?? null;
|
|
53
|
+
target.redactPatterns = [
|
|
54
|
+
...DEFAULT_REDACTION_PATTERNS,
|
|
55
|
+
...options?.redactPatterns ?? []
|
|
56
|
+
];
|
|
57
|
+
target.testRunId = options?.testRunId ?? null;
|
|
58
|
+
target.metadata = options?.metadata ?? null;
|
|
59
|
+
const outputPath = target.outputPath;
|
|
60
|
+
target.openReport = options?.openReport ?? true;
|
|
61
|
+
target.htmlReportPath = options?.htmlReportPath ?? outputPath.replace(/\.json$/, ".html");
|
|
62
|
+
return Object.freeze(target);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/schema.ts
|
|
66
|
+
var SCHEMA_VERSION = "1.0.0";
|
|
67
|
+
|
|
68
|
+
// src/code-extractor.ts
|
|
69
|
+
var import_node_fs = require("fs");
|
|
70
|
+
function extractCodeSnippet(filePath, line, contextLines) {
|
|
71
|
+
try {
|
|
72
|
+
const content = (0, import_node_fs.readFileSync)(filePath, "utf-8");
|
|
73
|
+
const lines = content.split("\n");
|
|
74
|
+
if (line < 1 || line > lines.length) return null;
|
|
75
|
+
const startLine = Math.max(1, line - contextLines);
|
|
76
|
+
const endLine = Math.min(lines.length, line + contextLines);
|
|
77
|
+
const snippetLines = [];
|
|
78
|
+
for (let i = startLine; i <= endLine; i++) {
|
|
79
|
+
const marker = i === line ? ">" : " ";
|
|
80
|
+
const lineNum = String(i).padStart(String(endLine).length, " ");
|
|
81
|
+
snippetLines.push(`${marker} ${lineNum} | ${lines[i - 1]}`);
|
|
82
|
+
}
|
|
83
|
+
return snippetLines.join("\n");
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/redaction.ts
|
|
90
|
+
function createRedactor(patterns) {
|
|
91
|
+
return (text) => {
|
|
92
|
+
let result = text;
|
|
93
|
+
for (const pattern of patterns) {
|
|
94
|
+
if (typeof pattern === "string") {
|
|
95
|
+
const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
96
|
+
result = result.replace(new RegExp(escaped, "g"), "[REDACTED]");
|
|
97
|
+
} else {
|
|
98
|
+
const flags = pattern.flags.includes("g") ? pattern.flags : pattern.flags + "g";
|
|
99
|
+
const cloned = new RegExp(pattern.source, flags);
|
|
100
|
+
result = result.replace(cloned, "[REDACTED]");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/ci-detector.ts
|
|
108
|
+
function detectGitHubActions(env) {
|
|
109
|
+
if (env.GITHUB_ACTIONS !== "true") return null;
|
|
110
|
+
return {
|
|
111
|
+
provider: "github-actions",
|
|
112
|
+
buildId: env.GITHUB_RUN_ID ?? null,
|
|
113
|
+
commitSha: env.GITHUB_SHA ?? null,
|
|
114
|
+
branch: env.GITHUB_REF_NAME ?? null
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function detectGitLabCI(env) {
|
|
118
|
+
if (env.GITLAB_CI !== "true") return null;
|
|
119
|
+
return {
|
|
120
|
+
provider: "gitlab-ci",
|
|
121
|
+
buildId: env.CI_PIPELINE_ID ?? null,
|
|
122
|
+
commitSha: env.CI_COMMIT_SHA ?? null,
|
|
123
|
+
branch: env.CI_COMMIT_BRANCH ?? env.CI_COMMIT_REF_NAME ?? null
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function detectJenkins(env) {
|
|
127
|
+
if (!env.JENKINS_URL) return null;
|
|
128
|
+
let branch = env.GIT_BRANCH ?? null;
|
|
129
|
+
if (branch?.startsWith("origin/")) {
|
|
130
|
+
branch = branch.slice("origin/".length);
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
provider: "jenkins",
|
|
134
|
+
buildId: env.BUILD_ID ?? null,
|
|
135
|
+
commitSha: env.GIT_COMMIT ?? null,
|
|
136
|
+
branch
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function detectCircleCI(env) {
|
|
140
|
+
if (env.CIRCLECI !== "true") return null;
|
|
141
|
+
return {
|
|
142
|
+
provider: "circleci",
|
|
143
|
+
buildId: env.CIRCLE_BUILD_NUM ?? null,
|
|
144
|
+
commitSha: env.CIRCLE_SHA1 ?? null,
|
|
145
|
+
branch: env.CIRCLE_BRANCH ?? null
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
var detectors = [
|
|
149
|
+
detectGitHubActions,
|
|
150
|
+
detectGitLabCI,
|
|
151
|
+
detectJenkins,
|
|
152
|
+
detectCircleCI
|
|
153
|
+
];
|
|
154
|
+
function detectCI(env) {
|
|
155
|
+
const envVars = env ?? process.env;
|
|
156
|
+
for (const detect of detectors) {
|
|
157
|
+
const result = detect(envVars);
|
|
158
|
+
if (result) return result;
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/html-report.ts
|
|
164
|
+
var import_node_fs2 = require("fs");
|
|
165
|
+
var import_node_path = require("path");
|
|
166
|
+
|
|
167
|
+
// src/html-template.ts
|
|
168
|
+
var LOGO_SVG = `<svg width="32" height="40" viewBox="0 0 196 247" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
169
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M4.75 1.08009C2.034 2.66209 -0.130999 7.63009 0.610001 10.5821C0.969001 12.0121 3.021 15.2131 5.17 17.6971C14.375 28.3321 18 39.7791 18 58.2101V71.0001H12.434C1.16501 71.0001 0 73.4641 0 97.3051C0 106.858 0.298003 128.922 0.662003 146.337L1.323 178H33.606C65.786 178 65.897 178.007 68.544 180.284C72.228 183.453 72.244 189.21 68.579 192.877L65.957 195.5L33.479 195.801L1 196.103V204.551V213H24.577H48.154L51.077 215.923C55.007 219.853 55.007 224.147 51.077 228.077L48.154 231H26.469H4.783L5.41901 233.534C5.76901 234.927 7.143 238.527 8.472 241.534L10.89 247H40.945H71L71.006 241.75C71.017 230.748 76.027 221.606 84.697 216.767C97.854 209.424 114.086 213.895 121.323 226.857C123.659 231.041 124.418 233.833 124.789 239.607L125.263 247H155.187H185.11L187.528 241.534C188.857 238.527 190.231 234.927 190.581 233.534L191.217 231H169.531H147.846L144.923 228.077C142.928 226.082 142 224.152 142 222C142 219.848 142.928 217.918 144.923 215.923L147.846 213H171.423H195V204.551V196.103L162.521 195.801L130.043 195.5L127.421 192.877C123.991 189.445 123.835 183.869 127.074 180.421L129.349 178H162.013H194.677L195.338 146.337C195.702 128.922 196 106.858 196 97.3051C196 73.4641 194.835 71.0001 183.566 71.0001H178V58.2101C178 39.6501 181.397 28.7731 190.538 18.0651C195.631 12.0971 196.572 9.00809 194.511 5.02109C192.672 1.46509 190.197 9.12233e-05 186.028 9.12233e-05C179.761 9.12233e-05 168.713 14.8831 163.388 30.5001C160.975 37.5771 160.608 40.3751 160.213 54.7501L159.765 71.0001H150.732H141.7L142.286 53.2501C142.904 34.5511 144.727 24.3761 148.938 16.1211C151.823 10.4671 151.628 5.90109 148.364 2.63609C145 -0.726907 140.105 -0.887909 136.596 2.25009C133.481 5.03609 128.686 17.0811 126.507 27.5921C125.569 32.1191 124.617 43.0901 124.28 53.2501L123.69 71.0001H115.345H107V38.4231V5.84609L104.077 2.92309C102.082 0.928088 100.152 9.12233e-05 98 9.12233e-05C95.848 9.12233e-05 93.918 0.928088 91.923 2.92309L89 5.84609V38.4231V71.0001H80.655H72.31L71.72 53.2501C71.383 43.0901 70.431 32.1191 69.493 27.5921C67.314 17.0811 62.519 5.03609 59.404 2.25009C55.998 -0.795909 51.059 -0.710905 47.646 2.45209C44.221 5.62609 44.191 9.92109 47.539 17.4911C51.71 26.9241 53.007 34.4791 53.676 53.2501L54.31 71.0001H45.272H36.235L35.787 54.7501C35.392 40.3751 35.025 37.5771 32.612 30.5001C27.194 14.6091 16.228 -0.02891 9.787 0.03009C7.979 0.04709 5.712 0.519093 4.75 1.08009ZM42.687 108.974C33.431 112.591 20.036 125.024 18.408 131.512C17.476 135.223 20.677 140.453 28.253 147.599C37.495 156.319 44.191 159.471 53.5 159.485C59.317 159.494 61.645 158.953 67.274 156.289C77.634 151.385 88.987 139.161 88.996 132.9C89.004 127.304 76.787 114.707 66.745 109.956C59.16 106.368 50.285 106.006 42.687 108.974ZM129.255 109.904C119.151 114.768 106.996 127.33 107.004 132.9C107.013 139.108 118.562 151.475 128.939 156.389C134.338 158.945 136.744 159.496 142.521 159.498C152.526 159.501 160.369 155.502 169.771 145.605C180.444 134.368 180.278 130.975 168.486 119.388C160.043 111.094 152.727 107.595 143 107.201C136.364 106.933 134.78 107.244 129.255 109.904ZM48.5 125.922C46.3 126.969 43.152 128.945 41.505 130.314L38.511 132.802L40.504 135.005C41.601 136.216 44.434 138.342 46.8 139.728C52.577 143.114 57.36 142.466 64.009 137.395L68.978 133.606L66.756 131.24C60.944 125.054 54.357 123.135 48.5 125.922ZM138.386 125.063C136.674 125.571 133.375 127.677 131.057 129.743L126.841 133.5L131.901 137.343C138.65 142.468 143.407 143.124 149.2 139.728C151.566 138.342 154.351 136.269 155.389 135.122C157.684 132.587 156.742 131.097 150.58 127.511C145.438 124.519 142.329 123.895 138.386 125.063ZM91.923 162.923C89.043 165.804 89 166.008 89 176.973C89 184.805 89.435 188.941 90.47 190.941C92.356 194.589 96.918 196.273 101.03 194.84C105.82 193.17 107 189.638 107 176.973C107 166.008 106.957 165.804 104.077 162.923C102.082 160.928 100.152 160 98 160C95.848 160 93.918 160.928 91.923 162.923ZM94.5 232.155C91.026 234.055 90 236.229 90 241.691V247H98H106V242.082C106 235.732 105.37 234.242 101.928 232.463C98.591 230.737 97.197 230.679 94.5 232.155Z" fill="url(#paint0_linear_55_11)"/>
|
|
170
|
+
<defs><linearGradient id="paint0_linear_55_11" x1="98" y1="0.000244141" x2="98" y2="247" gradientUnits="userSpaceOnUse">
|
|
171
|
+
<stop stop-color="#03B79C"/><stop offset="0.504808" stop-color="#4EDAA4"/><stop offset="0.865285" stop-color="#84F3AA"/>
|
|
172
|
+
</linearGradient></defs></svg>`;
|
|
173
|
+
var CSS = `
|
|
174
|
+
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
|
|
175
|
+
body{font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
|
|
176
|
+
color:#171717;background:#fff;line-height:1.6;-webkit-font-smoothing:antialiased}
|
|
177
|
+
.container{max-width:1100px;margin:0 auto;padding:24px 20px}
|
|
178
|
+
/* Header */
|
|
179
|
+
.header{display:flex;align-items:center;gap:12px;margin-bottom:8px}
|
|
180
|
+
.header svg{flex-shrink:0}
|
|
181
|
+
.header h1{font-size:22px;font-weight:700;color:#171717}
|
|
182
|
+
.meta{display:flex;flex-wrap:wrap;gap:8px 20px;font-size:13px;color:#6b7280;margin-bottom:20px}
|
|
183
|
+
.meta-item{display:flex;align-items:center;gap:4px}
|
|
184
|
+
.meta-label{font-weight:600;color:#374151}
|
|
185
|
+
.run-id{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;
|
|
186
|
+
background:#f3f4f6;padding:2px 8px;border-radius:4px}
|
|
187
|
+
.ci-badge{display:inline-flex;align-items:center;gap:4px;background:#eff6ff;
|
|
188
|
+
color:#1d4ed8;padding:2px 8px;border-radius:4px;font-size:12px;font-weight:500}
|
|
189
|
+
.merged-badge{background:#fef3c7;color:#92400e;padding:2px 8px;border-radius:4px;
|
|
190
|
+
font-size:12px;font-weight:500}
|
|
191
|
+
/* Summary Cards */
|
|
192
|
+
.summary{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:12px;margin-bottom:28px}
|
|
193
|
+
.summary-card{border-radius:10px;padding:16px;text-align:center;border:1px solid #e5e7eb}
|
|
194
|
+
.summary-card .count{font-size:32px;font-weight:800;line-height:1.1}
|
|
195
|
+
.summary-card .label{font-size:13px;font-weight:500;color:#6b7280;margin-top:2px}
|
|
196
|
+
.card-passed{border-color:#bbf7d0;background:#f0fdf4}.card-passed .count{color:#16a34a}
|
|
197
|
+
.card-failed{border-color:#fecaca;background:#fef2f2}.card-failed .count{color:#dc2626}
|
|
198
|
+
.card-flaky{border-color:#fde68a;background:#fffbeb}.card-flaky .count{color:#d97706}
|
|
199
|
+
.card-skipped{border-color:#e5e7eb;background:#f9fafb}.card-skipped .count{color:#6b7280}
|
|
200
|
+
.card-total{border-color:#c7d2fe;background:#eef2ff}.card-total .count{color:#4f46e5}
|
|
201
|
+
/* Timeline */
|
|
202
|
+
.timeline{display:flex;flex-direction:column;gap:8px}
|
|
203
|
+
.timeline-entry{border:1px solid #e5e7eb;border-radius:10px;overflow:hidden;
|
|
204
|
+
border-left:4px solid #e5e7eb;transition:border-color .15s}
|
|
205
|
+
.timeline-entry:hover{border-color:#d1d5db}
|
|
206
|
+
.timeline-entry--has-failures{border-left-color:#ef4444}
|
|
207
|
+
.timeline-entry--has-failures:hover{border-color:#fca5a5}
|
|
208
|
+
.timeline-header{display:flex;align-items:center;gap:10px;padding:12px 16px;cursor:pointer;
|
|
209
|
+
user-select:none;background:#fafafa;transition:background .15s}
|
|
210
|
+
.timeline-header:hover{background:#f3f4f6}
|
|
211
|
+
.chevron{width:16px;height:16px;flex-shrink:0;transition:transform .2s;color:#9ca3af}
|
|
212
|
+
.timeline-entry.expanded .chevron{transform:rotate(90deg)}
|
|
213
|
+
.timeline-url{font-size:14px;font-weight:600;color:#171717;overflow:hidden;
|
|
214
|
+
text-overflow:ellipsis;white-space:nowrap;max-width:500px;min-width:0}
|
|
215
|
+
.nav-type-badge{font-size:11px;font-weight:600;padding:2px 8px;border-radius:9999px;
|
|
216
|
+
white-space:nowrap;text-transform:uppercase;letter-spacing:.02em;flex-shrink:0}
|
|
217
|
+
.badge-goto,.badge-navigation,.badge-page_load{background:#d1fae5;color:#065f46}
|
|
218
|
+
.badge-back,.badge-forward{background:#dbeafe;color:#1e40af}
|
|
219
|
+
.badge-spa_route,.badge-spa_replace,.badge-hash_change,.badge-popstate{background:#ede9fe;color:#5b21b6}
|
|
220
|
+
.badge-link_click,.badge-form_submit{background:#fce7f3;color:#9d174d}
|
|
221
|
+
.badge-redirect{background:#ffedd5;color:#9a3412}
|
|
222
|
+
.badge-refresh{background:#e0f2fe;color:#075985}
|
|
223
|
+
.badge-dummy,.badge-fallback,.badge-manual_record{background:#f3f4f6;color:#6b7280}
|
|
224
|
+
.timeline-info{display:flex;align-items:center;gap:8px;font-size:12px;color:#6b7280;
|
|
225
|
+
margin-left:auto;flex-shrink:0;white-space:nowrap}
|
|
226
|
+
.spec-file{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;
|
|
227
|
+
color:#6b7280;background:#f3f4f6;padding:1px 6px;border-radius:3px}
|
|
228
|
+
.timeline-content{display:none;padding:0 16px 16px;border-top:1px solid #f3f4f6}
|
|
229
|
+
.timeline-entry.expanded .timeline-content{display:block}
|
|
230
|
+
/* Test Cards */
|
|
231
|
+
.tests-section{margin-top:12px}
|
|
232
|
+
.spec-summary{font-size:12px;color:#6b7280;margin-bottom:8px;display:flex;gap:12px;flex-wrap:wrap}
|
|
233
|
+
.spec-summary span{font-weight:600}
|
|
234
|
+
.spec-passed{color:#16a34a}.spec-failed{color:#dc2626}.spec-flaky{color:#d97706}
|
|
235
|
+
.test-card{display:flex;align-items:flex-start;gap:8px;padding:8px 0;
|
|
236
|
+
border-bottom:1px solid #f3f4f6}
|
|
237
|
+
.test-card:last-child{border-bottom:none}
|
|
238
|
+
.status-badge{font-size:11px;font-weight:700;padding:2px 8px;border-radius:9999px;
|
|
239
|
+
flex-shrink:0;margin-top:2px;text-transform:uppercase;letter-spacing:.03em}
|
|
240
|
+
.status-passed{background:#d1fae5;color:#065f46}
|
|
241
|
+
.status-failed{background:#fecaca;color:#991b1b}
|
|
242
|
+
.status-flaky{background:#fde68a;color:#92400e}
|
|
243
|
+
.test-info{flex:1;min-width:0}
|
|
244
|
+
.test-title{font-size:13px;color:#171717;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
245
|
+
.test-meta{display:flex;gap:8px;align-items:center;margin-top:2px;font-size:11px;color:#9ca3af}
|
|
246
|
+
.retry-badge{background:#fef3c7;color:#92400e;padding:1px 5px;border-radius:3px;font-size:10px;font-weight:600}
|
|
247
|
+
.tag-badge{background:#eff6ff;color:#1d4ed8;padding:1px 5px;border-radius:3px;font-size:10px}
|
|
248
|
+
.test-duration{font-size:12px;color:#9ca3af;flex-shrink:0;margin-top:2px}
|
|
249
|
+
/* Failure Details */
|
|
250
|
+
.failure-toggle{font-size:12px;color:#03b79c;cursor:pointer;margin-top:4px;
|
|
251
|
+
border:none;background:none;padding:0;text-decoration:underline;font-family:inherit}
|
|
252
|
+
.failure-toggle:hover{color:#028a75}
|
|
253
|
+
.failure-details{display:none;margin-top:8px;border-radius:8px;overflow:hidden;
|
|
254
|
+
border:1px solid #e5e7eb}
|
|
255
|
+
.failure-details.show{display:block}
|
|
256
|
+
.failure-message{padding:12px;background:#171717;color:#f8f8f8;font-size:12px;
|
|
257
|
+
font-family:ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;
|
|
258
|
+
word-break:break-word;line-height:1.5;overflow-x:auto}
|
|
259
|
+
.code-snippet{background:#1e1e1e;padding:0;font-size:12px;
|
|
260
|
+
font-family:ui-monospace,SFMono-Regular,Menlo,monospace;overflow-x:auto}
|
|
261
|
+
.code-line{display:flex;padding:0 12px;line-height:1.7}
|
|
262
|
+
.code-line.highlight{background:rgba(239,68,68,.2)}
|
|
263
|
+
.line-num{color:#6b7280;min-width:40px;text-align:right;padding-right:12px;
|
|
264
|
+
user-select:none;flex-shrink:0}
|
|
265
|
+
.line-code{color:#d4d4d4;white-space:pre;overflow-x:auto}
|
|
266
|
+
.stack-toggle{font-size:11px;color:#6b7280;cursor:pointer;padding:8px 12px;
|
|
267
|
+
border:none;background:#f9fafb;width:100%;text-align:left;font-family:inherit;
|
|
268
|
+
border-top:1px solid #e5e7eb}
|
|
269
|
+
.stack-toggle:hover{background:#f3f4f6;color:#374151}
|
|
270
|
+
.stack-trace{display:none;padding:12px;background:#fafafa;font-size:11px;
|
|
271
|
+
font-family:ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;
|
|
272
|
+
word-break:break-word;color:#6b7280;border-top:1px solid #e5e7eb;max-height:300px;overflow-y:auto}
|
|
273
|
+
.stack-trace.show{display:block}
|
|
274
|
+
/* Network Panel */
|
|
275
|
+
.network-panel{margin-top:16px;border:1px solid #e5e7eb;border-radius:8px;overflow:hidden}
|
|
276
|
+
.network-header{font-size:12px;font-weight:600;color:#374151;padding:10px 12px;
|
|
277
|
+
background:#f9fafb;border-bottom:1px solid #e5e7eb;display:flex;align-items:center;gap:6px}
|
|
278
|
+
.network-summary{display:flex;gap:16px;padding:10px 12px;font-size:12px;flex-wrap:wrap}
|
|
279
|
+
.net-stat{display:flex;flex-direction:column;align-items:center;gap:1px}
|
|
280
|
+
.net-stat .val{font-weight:700;font-size:14px;color:#171717}
|
|
281
|
+
.net-stat .lbl{color:#9ca3af;font-size:11px}
|
|
282
|
+
.net-stat.has-failed .val{color:#dc2626}
|
|
283
|
+
.resource-breakdown{display:flex;gap:6px;padding:8px 12px;flex-wrap:wrap;border-top:1px solid #f3f4f6}
|
|
284
|
+
.resource-type{display:flex;align-items:center;gap:4px;font-size:11px;padding:3px 8px;
|
|
285
|
+
border-radius:4px;background:#f3f4f6;color:#374151}
|
|
286
|
+
.resource-type .rt-count{font-weight:700}
|
|
287
|
+
.resource-type--zero{opacity:.45}
|
|
288
|
+
/* Empty State */
|
|
289
|
+
.empty-state{text-align:center;padding:60px 20px;color:#9ca3af}
|
|
290
|
+
.empty-state svg{width:48px;height:48px;margin-bottom:12px;opacity:.4}
|
|
291
|
+
.empty-state p{font-size:15px;font-weight:500}
|
|
292
|
+
/* No-network */
|
|
293
|
+
.no-network{font-size:12px;color:#9ca3af;padding:10px 12px;font-style:italic}
|
|
294
|
+
/* Section title */
|
|
295
|
+
.section-title{font-size:16px;font-weight:700;color:#171717;margin-bottom:12px;
|
|
296
|
+
display:flex;align-items:center;gap:8px}
|
|
297
|
+
.section-title::before{content:'';width:4px;height:18px;background:#03b79c;border-radius:2px}
|
|
298
|
+
`;
|
|
299
|
+
var JS = `
|
|
300
|
+
(function(){
|
|
301
|
+
var data=JSON.parse(document.getElementById('report-data').textContent);
|
|
302
|
+
|
|
303
|
+
function esc(s){if(!s)return '';return s.replace(/&/g,'&').replace(/</g,'<')
|
|
304
|
+
.replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,''')}
|
|
305
|
+
function stripAnsi(s){return s?s.replace(/\\u001b\\[[0-9;]*m/g,'').replace(/\\x1b\\[[0-9;]*m/g,''):''}
|
|
306
|
+
function fmtDur(ms){if(ms<1000)return Math.round(ms)+'ms';
|
|
307
|
+
if(ms<60000)return (ms/1000).toFixed(1)+'s';
|
|
308
|
+
var m=Math.floor(ms/60000),s=Math.round((ms%60000)/1000);
|
|
309
|
+
return s>0?m+'m '+s+'s':m+'m'}
|
|
310
|
+
function fmtBytes(b){if(b===0)return '0 B';if(b<1024)return b+' B';
|
|
311
|
+
if(b<1048576)return (b/1024).toFixed(1)+' KB';return (b/1048576).toFixed(1)+' MB'}
|
|
312
|
+
function fmtTime(iso){try{return new Date(iso).toLocaleString()}catch(e){return iso}}
|
|
313
|
+
|
|
314
|
+
var app=document.getElementById('app');
|
|
315
|
+
|
|
316
|
+
// Header
|
|
317
|
+
var h='<div class="header">__LOGO_SVG__<h1>TestRelic Report</h1></div>';
|
|
318
|
+
h+='<div class="meta">';
|
|
319
|
+
h+='<div class="meta-item"><span class="meta-label">Run ID</span><span class="run-id">'+esc(data.testRunId)+'</span></div>';
|
|
320
|
+
h+='<div class="meta-item"><span class="meta-label">Started</span>'+fmtTime(data.startedAt)+'</div>';
|
|
321
|
+
h+='<div class="meta-item"><span class="meta-label">Completed</span>'+fmtTime(data.completedAt)+'</div>';
|
|
322
|
+
h+='<div class="meta-item"><span class="meta-label">Duration</span>'+fmtDur(data.totalDuration)+'</div>';
|
|
323
|
+
if(data.ci){
|
|
324
|
+
h+='<div class="meta-item"><span class="ci-badge">'+esc(data.ci.provider)+'</span></div>';
|
|
325
|
+
if(data.ci.branch)h+='<div class="meta-item"><span class="meta-label">Branch</span>'+esc(data.ci.branch)+'</div>';
|
|
326
|
+
if(data.ci.commitSha)h+='<div class="meta-item"><span class="meta-label">Commit</span><span class="run-id">'+esc(data.ci.commitSha.substring(0,8))+'</span></div>';
|
|
327
|
+
if(data.ci.buildId)h+='<div class="meta-item"><span class="meta-label">Build</span>'+esc(data.ci.buildId)+'</div>';
|
|
328
|
+
}
|
|
329
|
+
if(data.shardRunIds&&data.shardRunIds.length>0){
|
|
330
|
+
h+='<div class="meta-item"><span class="merged-badge">Merged Report ('+data.shardRunIds.length+' shards)</span></div>';
|
|
331
|
+
}
|
|
332
|
+
h+='</div>';
|
|
333
|
+
|
|
334
|
+
// Summary
|
|
335
|
+
var s=data.summary;
|
|
336
|
+
h+='<div class="summary">';
|
|
337
|
+
h+='<div class="summary-card card-total"><div class="count">'+s.total+'</div><div class="label">Total</div></div>';
|
|
338
|
+
h+='<div class="summary-card card-passed"><div class="count">'+s.passed+'</div><div class="label">Passed</div></div>';
|
|
339
|
+
h+='<div class="summary-card card-failed"><div class="count">'+s.failed+'</div><div class="label">Failed</div></div>';
|
|
340
|
+
h+='<div class="summary-card card-flaky"><div class="count">'+s.flaky+'</div><div class="label">Flaky</div></div>';
|
|
341
|
+
h+='<div class="summary-card card-skipped"><div class="count">'+s.skipped+'</div><div class="label">Skipped</div></div>';
|
|
342
|
+
h+='</div>';
|
|
343
|
+
|
|
344
|
+
// Timeline
|
|
345
|
+
h+='<div class="section-title">Navigation Timeline</div>';
|
|
346
|
+
if(data.timeline.length===0){
|
|
347
|
+
h+='<div class="empty-state">__LOGO_SVG__<p>No test data recorded</p></div>';
|
|
348
|
+
}else{
|
|
349
|
+
h+='<div class="timeline" id="timeline">';
|
|
350
|
+
for(var i=0;i<data.timeline.length;i++){
|
|
351
|
+
var e=data.timeline[i];
|
|
352
|
+
var hasFail=e.tests.some(function(t){return t.status==='failed'});
|
|
353
|
+
var cls='timeline-entry'+(hasFail?' timeline-entry--has-failures':'');
|
|
354
|
+
h+='<div class="'+cls+'" data-idx="'+i+'">';
|
|
355
|
+
h+='<div class="timeline-header" onclick="toggleEntry(this)">';
|
|
356
|
+
h+='<svg class="chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg>';
|
|
357
|
+
h+='<span class="timeline-url" title="'+esc(e.url)+'">'+esc(e.url)+'</span>';
|
|
358
|
+
h+='<span class="nav-type-badge badge-'+e.navigationType+'">'+esc(e.navigationType.replace(/_/g,' '))+'</span>';
|
|
359
|
+
h+='<div class="timeline-info">';
|
|
360
|
+
h+='<span class="spec-file">'+esc(e.specFile)+'</span>';
|
|
361
|
+
h+='<span>'+fmtTime(e.visitedAt)+'</span>';
|
|
362
|
+
h+='<span>'+fmtDur(e.duration)+'</span>';
|
|
363
|
+
h+='</div></div>';
|
|
364
|
+
h+='<div class="timeline-content">';
|
|
365
|
+
h+=renderTests(e.tests);
|
|
366
|
+
h+=renderNetwork(e.networkStats);
|
|
367
|
+
h+='</div></div>';
|
|
368
|
+
}
|
|
369
|
+
h+='</div>';
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
app.innerHTML=h;
|
|
373
|
+
|
|
374
|
+
function renderTests(tests){
|
|
375
|
+
if(!tests||tests.length===0)return '';
|
|
376
|
+
var out='<div class="tests-section">';
|
|
377
|
+
// Spec summary
|
|
378
|
+
var pc=0,fc=0,fkc=0;
|
|
379
|
+
tests.forEach(function(t){if(t.status==='passed')pc++;else if(t.status==='failed')fc++;else if(t.status==='flaky')fkc++});
|
|
380
|
+
out+='<div class="spec-summary">';
|
|
381
|
+
if(pc>0)out+='<span class="spec-passed">'+pc+' passed</span>';
|
|
382
|
+
if(fc>0)out+='<span class="spec-failed">'+fc+' failed</span>';
|
|
383
|
+
if(fkc>0)out+='<span class="spec-flaky">'+fkc+' flaky</span>';
|
|
384
|
+
out+='</div>';
|
|
385
|
+
for(var j=0;j<tests.length;j++){
|
|
386
|
+
var t=tests[j];
|
|
387
|
+
out+='<div class="test-card">';
|
|
388
|
+
out+='<span class="status-badge status-'+t.status+'">'+t.status+'</span>';
|
|
389
|
+
out+='<div class="test-info">';
|
|
390
|
+
out+='<div class="test-title" title="'+esc(t.title)+'">'+esc(t.title)+'</div>';
|
|
391
|
+
out+='<div class="test-meta">';
|
|
392
|
+
if(t.retryCount>0)out+='<span class="retry-badge">'+t.retryCount+' retries</span>';
|
|
393
|
+
if(t.tags)t.tags.forEach(function(tag){if(tag)out+='<span class="tag-badge">'+esc(tag)+'</span>'});
|
|
394
|
+
out+='</div>';
|
|
395
|
+
if((t.status==='failed'||t.status==='flaky')&&t.failure){
|
|
396
|
+
var fid='fail-'+Math.random().toString(36).substr(2,9);
|
|
397
|
+
out+='<button class="failure-toggle" onclick="toggleFail(\\''+fid+'\\')">Show details</button>';
|
|
398
|
+
out+='<div class="failure-details" id="'+fid+'">';
|
|
399
|
+
out+='<div class="failure-message">'+esc(stripAnsi(t.failure.message))+'</div>';
|
|
400
|
+
if(t.failure.code){
|
|
401
|
+
out+=renderCodeSnippet(t.failure.code,t.failure.line);
|
|
402
|
+
}
|
|
403
|
+
if(t.failure.line!==null){
|
|
404
|
+
out+='<div style="padding:4px 12px;font-size:11px;color:#9ca3af;background:#f9fafb">Line '+t.failure.line+'</div>';
|
|
405
|
+
}
|
|
406
|
+
if(t.failure.stack){
|
|
407
|
+
var sid='stack-'+Math.random().toString(36).substr(2,9);
|
|
408
|
+
out+='<button class="stack-toggle" onclick="toggleStack(\\''+sid+'\\')">Show stack trace</button>';
|
|
409
|
+
out+='<div class="stack-trace" id="'+sid+'">'+esc(stripAnsi(t.failure.stack))+'</div>';
|
|
410
|
+
}
|
|
411
|
+
out+='</div>';
|
|
412
|
+
} else if(t.status==='failed'&&!t.failure){
|
|
413
|
+
out+='<div style="margin-top:4px;font-size:12px;color:#9ca3af;font-style:italic">No diagnostic information available</div>';
|
|
414
|
+
}
|
|
415
|
+
out+='</div>';
|
|
416
|
+
out+='<span class="test-duration">'+fmtDur(t.duration)+'</span>';
|
|
417
|
+
out+='</div>';
|
|
418
|
+
}
|
|
419
|
+
out+='</div>';
|
|
420
|
+
return out;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function renderCodeSnippet(code,failLine){
|
|
424
|
+
var lines=code.split('\\n');
|
|
425
|
+
var out='<div class="code-snippet">';
|
|
426
|
+
for(var k=0;k<lines.length;k++){
|
|
427
|
+
var raw=lines[k];
|
|
428
|
+
var numMatch=raw.match(/^\\s*(>?\\s*)(\\d+)\\s*\\|/);
|
|
429
|
+
var lineNum=numMatch?numMatch[2]:'';
|
|
430
|
+
var isHighlight=raw.trimStart().startsWith('>');
|
|
431
|
+
var codePart=raw.replace(/^\\s*>?\\s*\\d+\\s*\\|/,'');
|
|
432
|
+
out+='<div class="code-line'+(isHighlight?' highlight':'')+'">';
|
|
433
|
+
out+='<span class="line-num">'+esc(lineNum)+'</span>';
|
|
434
|
+
out+='<span class="line-code">'+esc(codePart)+'</span>';
|
|
435
|
+
out+='</div>';
|
|
436
|
+
}
|
|
437
|
+
out+='</div>';
|
|
438
|
+
return out;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function renderNetwork(stats){
|
|
442
|
+
if(!stats)return '<div class="no-network">No network data captured</div>';
|
|
443
|
+
var out='<div class="network-panel">';
|
|
444
|
+
out+='<div class="network-header"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 12h-4l-3 9L9 3l-3 9H2"/></svg>Network</div>';
|
|
445
|
+
out+='<div class="network-summary">';
|
|
446
|
+
out+='<div class="net-stat"><span class="val">'+stats.totalRequests+'</span><span class="lbl">Requests</span></div>';
|
|
447
|
+
out+='<div class="net-stat'+(stats.failedRequests>0?' has-failed':'')+'"><span class="val">'+stats.failedRequests+'</span><span class="lbl">Failed</span></div>';
|
|
448
|
+
out+='<div class="net-stat"><span class="val">'+fmtBytes(stats.totalBytes)+'</span><span class="lbl">Transferred</span></div>';
|
|
449
|
+
out+='</div>';
|
|
450
|
+
if(stats.byType){
|
|
451
|
+
var types=[['XHR','xhr'],['Document','document'],['Script','script'],['Stylesheet','stylesheet'],['Image','image'],['Font','font'],['Other','other']];
|
|
452
|
+
out+='<div class="resource-breakdown">';
|
|
453
|
+
for(var ti=0;ti<types.length;ti++){
|
|
454
|
+
var cnt=stats.byType[types[ti][1]]||0;
|
|
455
|
+
out+='<div class="resource-type'+(cnt===0?' resource-type--zero':'')+'"><span class="rt-count">'+cnt+'</span> '+types[ti][0]+'</div>';
|
|
456
|
+
}
|
|
457
|
+
out+='</div>';
|
|
458
|
+
}
|
|
459
|
+
out+='</div>';
|
|
460
|
+
return out;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
})();
|
|
464
|
+
|
|
465
|
+
function toggleEntry(el){el.closest('.timeline-entry').classList.toggle('expanded')}
|
|
466
|
+
function toggleFail(id){document.getElementById(id).classList.toggle('show')}
|
|
467
|
+
function toggleStack(id){document.getElementById(id).classList.toggle('show')}
|
|
468
|
+
`;
|
|
469
|
+
function renderHtmlDocument(reportJson) {
|
|
470
|
+
const jsWithLogo = JS.replace(/__LOGO_SVG__/g, LOGO_SVG.replace(/'/g, "\\'").replace(/\n/g, ""));
|
|
471
|
+
return `<!-- TestRelic Report \u2014 self-contained, no external dependencies -->
|
|
472
|
+
<!DOCTYPE html>
|
|
473
|
+
<html lang="en">
|
|
474
|
+
<head>
|
|
475
|
+
<meta charset="UTF-8">
|
|
476
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
477
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data:;">
|
|
478
|
+
<title>TestRelic Report</title>
|
|
479
|
+
<style>${CSS}</style>
|
|
480
|
+
</head>
|
|
481
|
+
<body>
|
|
482
|
+
<div class="container" id="app"></div>
|
|
483
|
+
<script id="report-data" type="application/json">${reportJson}</script>
|
|
484
|
+
<script>${jsWithLogo}</script>
|
|
485
|
+
</body>
|
|
486
|
+
</html>`;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// src/browser-open.ts
|
|
490
|
+
var import_node_child_process = require("child_process");
|
|
491
|
+
function openInBrowser(filePath) {
|
|
492
|
+
try {
|
|
493
|
+
const platform = process.platform;
|
|
494
|
+
let command;
|
|
495
|
+
if (platform === "darwin") {
|
|
496
|
+
command = `open "${filePath}"`;
|
|
497
|
+
} else if (platform === "win32") {
|
|
498
|
+
command = `start "" "${filePath}"`;
|
|
499
|
+
} else {
|
|
500
|
+
command = `xdg-open "${filePath}"`;
|
|
501
|
+
}
|
|
502
|
+
(0, import_node_child_process.exec)(command, (err) => {
|
|
503
|
+
if (err) {
|
|
504
|
+
process.stderr.write(
|
|
505
|
+
`[testrelic] Failed to open browser: ${err.message}
|
|
506
|
+
`
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
} catch {
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// src/html-report.ts
|
|
515
|
+
function generateHtmlReport(report) {
|
|
516
|
+
const reportJson = JSON.stringify(report);
|
|
517
|
+
return renderHtmlDocument(reportJson);
|
|
518
|
+
}
|
|
519
|
+
function writeHtmlReport(report, config) {
|
|
520
|
+
try {
|
|
521
|
+
const html = generateHtmlReport(report);
|
|
522
|
+
const outputPath = config.htmlReportPath;
|
|
523
|
+
const dir = (0, import_node_path.dirname)(outputPath);
|
|
524
|
+
(0, import_node_fs2.mkdirSync)(dir, { recursive: true });
|
|
525
|
+
const tmpPath = outputPath + ".tmp";
|
|
526
|
+
(0, import_node_fs2.writeFileSync)(tmpPath, html, "utf-8");
|
|
527
|
+
(0, import_node_fs2.renameSync)(tmpPath, outputPath);
|
|
528
|
+
if (config.openReport && report.ci === null) {
|
|
529
|
+
const absolutePath = (0, import_node_path.resolve)(outputPath);
|
|
530
|
+
openInBrowser(absolutePath);
|
|
531
|
+
}
|
|
532
|
+
} catch (err) {
|
|
533
|
+
process.stderr.write(
|
|
534
|
+
`[testrelic] Failed to write HTML report: ${err instanceof Error ? err.message : String(err)}
|
|
535
|
+
`
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// src/reporter.ts
|
|
541
|
+
var TestRelicReporter = class {
|
|
542
|
+
constructor(options) {
|
|
543
|
+
this.rootDir = "";
|
|
544
|
+
this.startedAt = "";
|
|
545
|
+
this.testRunId = "";
|
|
546
|
+
this.collectedTests = [];
|
|
547
|
+
this.config = resolveConfig(options);
|
|
548
|
+
}
|
|
549
|
+
onBegin(config, _suite) {
|
|
550
|
+
try {
|
|
551
|
+
this.rootDir = config.rootDir;
|
|
552
|
+
this.startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
553
|
+
this.testRunId = this.config.testRunId ?? (0, import_node_crypto.randomUUID)();
|
|
554
|
+
} catch {
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
onTestEnd(test, result) {
|
|
558
|
+
try {
|
|
559
|
+
const lastResult = result;
|
|
560
|
+
const outcome = test.outcome();
|
|
561
|
+
let status;
|
|
562
|
+
if (outcome === "flaky") {
|
|
563
|
+
status = "flaky";
|
|
564
|
+
} else if (lastResult.status === "passed") {
|
|
565
|
+
status = "passed";
|
|
566
|
+
} else {
|
|
567
|
+
status = "failed";
|
|
568
|
+
}
|
|
569
|
+
if (outcome === "skipped") return;
|
|
570
|
+
const startedAt = lastResult.startTime.toISOString();
|
|
571
|
+
const completedAt = new Date(lastResult.startTime.getTime() + lastResult.duration).toISOString();
|
|
572
|
+
const tags = test.tags ? [...test.tags] : test.annotations.filter((a) => a.type === "tag").map((a) => a.description ?? "");
|
|
573
|
+
const navigations = test.annotations.filter((a) => a.type === "lambdatest-navigation" && a.description).map((a) => {
|
|
574
|
+
try {
|
|
575
|
+
return JSON.parse(a.description);
|
|
576
|
+
} catch {
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
}).filter((n) => n !== null);
|
|
580
|
+
let failure = null;
|
|
581
|
+
if (status === "failed" || status === "flaky") {
|
|
582
|
+
const errors = status === "flaky" ? test.results.find((r) => r.status !== "passed")?.errors ?? [] : lastResult.errors;
|
|
583
|
+
const firstError = errors[0];
|
|
584
|
+
if (firstError) {
|
|
585
|
+
const redact = createRedactor(this.config.redactPatterns);
|
|
586
|
+
const errorLine = firstError.location?.line ?? null;
|
|
587
|
+
let codeSnippet = null;
|
|
588
|
+
if (this.config.includeCodeSnippets && errorLine !== null && firstError.location?.file) {
|
|
589
|
+
codeSnippet = extractCodeSnippet(
|
|
590
|
+
firstError.location.file,
|
|
591
|
+
errorLine,
|
|
592
|
+
this.config.codeContextLines
|
|
593
|
+
);
|
|
594
|
+
if (codeSnippet) codeSnippet = redact(codeSnippet);
|
|
595
|
+
}
|
|
596
|
+
failure = {
|
|
597
|
+
message: redact(firstError.message ?? "Unknown error"),
|
|
598
|
+
line: errorLine,
|
|
599
|
+
code: codeSnippet,
|
|
600
|
+
stack: this.config.includeStackTrace ? firstError.stack ? redact(firstError.stack) : null : null
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
const titlePath = test.titlePath().filter(Boolean);
|
|
605
|
+
const specFile = (0, import_node_path2.relative)(this.rootDir || ".", test.location.file);
|
|
606
|
+
this.collectedTests.push({
|
|
607
|
+
titlePath,
|
|
608
|
+
title: titlePath.join(" > "),
|
|
609
|
+
status,
|
|
610
|
+
duration: lastResult.duration,
|
|
611
|
+
startedAt,
|
|
612
|
+
completedAt,
|
|
613
|
+
retryCount: test.results.length - 1,
|
|
614
|
+
tags,
|
|
615
|
+
failure,
|
|
616
|
+
specFile,
|
|
617
|
+
navigations
|
|
618
|
+
});
|
|
619
|
+
} catch {
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
onEnd(_result) {
|
|
623
|
+
try {
|
|
624
|
+
const completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
625
|
+
const startedAtTime = new Date(this.startedAt).getTime();
|
|
626
|
+
const completedAtTime = new Date(completedAt).getTime();
|
|
627
|
+
const totalDuration = completedAtTime - startedAtTime;
|
|
628
|
+
const timeline = this.buildTimeline();
|
|
629
|
+
const summary = this.buildSummary();
|
|
630
|
+
const report = {
|
|
631
|
+
schemaVersion: SCHEMA_VERSION,
|
|
632
|
+
testRunId: this.testRunId,
|
|
633
|
+
startedAt: this.startedAt,
|
|
634
|
+
completedAt,
|
|
635
|
+
totalDuration,
|
|
636
|
+
summary,
|
|
637
|
+
ci: detectCI(),
|
|
638
|
+
metadata: this.config.metadata,
|
|
639
|
+
timeline,
|
|
640
|
+
shardRunIds: null
|
|
641
|
+
};
|
|
642
|
+
this.writeReport(report);
|
|
643
|
+
writeHtmlReport(report, this.config);
|
|
644
|
+
} catch {
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
printsToStdio() {
|
|
648
|
+
return false;
|
|
649
|
+
}
|
|
650
|
+
buildTimeline() {
|
|
651
|
+
const entries = [];
|
|
652
|
+
for (const test of this.collectedTests) {
|
|
653
|
+
if (test.navigations.length === 0) {
|
|
654
|
+
entries.push({
|
|
655
|
+
url: "about:blank",
|
|
656
|
+
navigationType: "dummy",
|
|
657
|
+
visitedAt: test.startedAt,
|
|
658
|
+
duration: test.duration,
|
|
659
|
+
specFile: test.specFile,
|
|
660
|
+
domContentLoadedAt: null,
|
|
661
|
+
networkIdleAt: null,
|
|
662
|
+
networkStats: null,
|
|
663
|
+
tests: [this.toTestResult(test)]
|
|
664
|
+
});
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
for (let i = 0; i < test.navigations.length; i++) {
|
|
668
|
+
const nav = test.navigations[i];
|
|
669
|
+
const nextNav = test.navigations[i + 1];
|
|
670
|
+
if (this.config.navigationTypes !== null && !this.config.navigationTypes.includes(nav.navigationType)) {
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
const navTime = new Date(nav.timestamp).getTime();
|
|
674
|
+
const nextTime = nextNav ? new Date(nextNav.timestamp).getTime() : new Date(test.completedAt).getTime();
|
|
675
|
+
const duration = nextTime - navTime;
|
|
676
|
+
entries.push({
|
|
677
|
+
url: nav.url,
|
|
678
|
+
navigationType: nav.navigationType,
|
|
679
|
+
visitedAt: nav.timestamp,
|
|
680
|
+
duration: Math.max(0, duration),
|
|
681
|
+
specFile: test.specFile,
|
|
682
|
+
domContentLoadedAt: nav.domContentLoadedAt ?? null,
|
|
683
|
+
networkIdleAt: nav.networkIdleAt ?? null,
|
|
684
|
+
networkStats: nav.networkStats ?? null,
|
|
685
|
+
tests: [this.toTestResult(test)]
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
entries.sort((a, b) => new Date(a.visitedAt).getTime() - new Date(b.visitedAt).getTime());
|
|
690
|
+
return entries;
|
|
691
|
+
}
|
|
692
|
+
buildSummary() {
|
|
693
|
+
let passed = 0;
|
|
694
|
+
let failed = 0;
|
|
695
|
+
let flaky = 0;
|
|
696
|
+
let skipped = 0;
|
|
697
|
+
for (const test of this.collectedTests) {
|
|
698
|
+
switch (test.status) {
|
|
699
|
+
case "passed":
|
|
700
|
+
passed++;
|
|
701
|
+
break;
|
|
702
|
+
case "failed":
|
|
703
|
+
failed++;
|
|
704
|
+
break;
|
|
705
|
+
case "flaky":
|
|
706
|
+
flaky++;
|
|
707
|
+
break;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return {
|
|
711
|
+
total: this.collectedTests.length,
|
|
712
|
+
passed,
|
|
713
|
+
failed,
|
|
714
|
+
flaky,
|
|
715
|
+
skipped
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
toTestResult(test) {
|
|
719
|
+
return {
|
|
720
|
+
title: test.title,
|
|
721
|
+
status: test.status,
|
|
722
|
+
duration: test.duration,
|
|
723
|
+
startedAt: test.startedAt,
|
|
724
|
+
completedAt: test.completedAt,
|
|
725
|
+
retryCount: test.retryCount,
|
|
726
|
+
tags: test.tags,
|
|
727
|
+
failure: test.failure
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
writeReport(report) {
|
|
731
|
+
try {
|
|
732
|
+
const json = JSON.stringify(report, null, 2);
|
|
733
|
+
const outputPath = this.config.outputPath;
|
|
734
|
+
const dir = (0, import_node_path2.dirname)(outputPath);
|
|
735
|
+
(0, import_node_fs3.mkdirSync)(dir, { recursive: true });
|
|
736
|
+
const tmpPath = outputPath + ".tmp";
|
|
737
|
+
(0, import_node_fs3.writeFileSync)(tmpPath, json, "utf-8");
|
|
738
|
+
(0, import_node_fs3.renameSync)(tmpPath, outputPath);
|
|
739
|
+
} catch (err) {
|
|
740
|
+
process.stderr.write(
|
|
741
|
+
`[testrelic] Failed to write report: ${err instanceof Error ? err.message : String(err)}
|
|
742
|
+
`
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
// src/index.ts
|
|
749
|
+
var warned = false;
|
|
750
|
+
function recordNavigation(testInfo, url, navigationType = "manual_record") {
|
|
751
|
+
if (!testInfo || !testInfo.annotations) {
|
|
752
|
+
if (!warned) {
|
|
753
|
+
warned = true;
|
|
754
|
+
process.stderr.write("[testrelic] recordNavigation: reporter not active, navigation not recorded\n");
|
|
755
|
+
}
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
const annotation = {
|
|
759
|
+
url,
|
|
760
|
+
navigationType,
|
|
761
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
762
|
+
};
|
|
763
|
+
testInfo.annotations.push({
|
|
764
|
+
type: "lambdatest-navigation",
|
|
765
|
+
description: JSON.stringify(annotation)
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
769
|
+
0 && (module.exports = {
|
|
770
|
+
SCHEMA_VERSION,
|
|
771
|
+
recordNavigation
|
|
772
|
+
});
|
|
773
|
+
//# sourceMappingURL=index.cjs.map
|