@flakemetry/wdio-reporter 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +95 -2
- package/dist/index.cjs +640 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +157 -0
- package/dist/index.d.ts +158 -0
- package/dist/index.js +611 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
2
|
+
import { MAX_SPANS_PER_EXECUTION } from "@flakemetry/contracts";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
import { stripVTControlCharacters } from "node:util";
|
|
5
|
+
import { TestRunRecorder, buildIdempotencyKey, deliverRun, resolveRunContext } from "@flakemetry/sdk";
|
|
6
|
+
import WDIOReporterExport from "@wdio/reporter";
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
8
|
+
// src/mapping.ts
|
|
9
|
+
const STACK_FRAME = /^\s+at\s/;
|
|
10
|
+
const MAX_MESSAGE_LENGTH = 8e3;
|
|
11
|
+
const MAX_VARIANT_LENGTH = 100;
|
|
12
|
+
const MAX_IDEMPOTENCY_KEY_LENGTH = 128;
|
|
13
|
+
const NOT_RUN = [/^Test skipped due to failure in hook\b/, /^Not run because a beforeAll function failed\b/];
|
|
14
|
+
const stripAnsi = (value) => stripVTControlCharacters(value);
|
|
15
|
+
const errorOf = (errors, error) => errors?.find((candidate) => Boolean(candidate)) ?? error ?? void 0;
|
|
16
|
+
const neverRan = (error) => {
|
|
17
|
+
const message = stripAnsi(error?.message ?? "").trim();
|
|
18
|
+
return NOT_RUN.some((pattern) => pattern.test(message));
|
|
19
|
+
};
|
|
20
|
+
const summarizeError = (error, fallback) => {
|
|
21
|
+
const lines = stripAnsi(error?.message ?? "").split("\n");
|
|
22
|
+
const frame = lines.findIndex((line) => STACK_FRAME.test(line));
|
|
23
|
+
const message = (frame === -1 ? lines : lines.slice(0, frame)).join("\n").trim();
|
|
24
|
+
return {
|
|
25
|
+
type: error?.name ?? error?.type ?? null,
|
|
26
|
+
message: message.length > 0 ? message.slice(0, MAX_MESSAGE_LENGTH) : fallback,
|
|
27
|
+
stack: error?.stack ? stripAnsi(error.stack) : null
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const commandStatus = (result) => {
|
|
31
|
+
const record = result && typeof result === "object" ? result : {};
|
|
32
|
+
const thrown = record.error;
|
|
33
|
+
if (thrown) {
|
|
34
|
+
const detail = thrown;
|
|
35
|
+
return {
|
|
36
|
+
status: "error",
|
|
37
|
+
error: {
|
|
38
|
+
type: detail.name ?? null,
|
|
39
|
+
message: stripAnsi(detail.message ?? String(thrown)).split("\n")[0] || "command failed"
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const value = record.value;
|
|
44
|
+
if (value && typeof value === "object" && typeof value.error === "string") {
|
|
45
|
+
const detail = {
|
|
46
|
+
error: value.error,
|
|
47
|
+
message: typeof value.message === "string" ? value.message : void 0
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
status: "error",
|
|
51
|
+
error: {
|
|
52
|
+
type: detail.error,
|
|
53
|
+
message: stripAnsi(detail.message ?? detail.error).split("\n")[0] || detail.error
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
status: "ok",
|
|
59
|
+
error: null
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
const toFilePath = (raw) => {
|
|
63
|
+
if (!raw || raw === "unknown spec file") return void 0;
|
|
64
|
+
if (raw.startsWith("file://")) try {
|
|
65
|
+
return fileURLToPath(raw);
|
|
66
|
+
} catch {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
return raw;
|
|
70
|
+
};
|
|
71
|
+
const relativize = (rootDir, filePath) => {
|
|
72
|
+
if (!isAbsolute(filePath)) return filePath.split(sep).join("/");
|
|
73
|
+
const inside = relative(rootDir, filePath);
|
|
74
|
+
return (inside && !inside.startsWith("..") && !isAbsolute(inside) ? inside : filePath).split(sep).join("/");
|
|
75
|
+
};
|
|
76
|
+
const text = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
77
|
+
const unwrap = (capabilities) => {
|
|
78
|
+
const alwaysMatch = capabilities.alwaysMatch;
|
|
79
|
+
return alwaysMatch && typeof alwaysMatch === "object" ? {
|
|
80
|
+
...alwaysMatch,
|
|
81
|
+
...capabilities
|
|
82
|
+
} : capabilities;
|
|
83
|
+
};
|
|
84
|
+
const explicitVariant = (capabilities) => capabilities ? text(unwrap(capabilities)["flakemetry:variant"]) : void 0;
|
|
85
|
+
const capabilityLabel = (capabilities) => {
|
|
86
|
+
if (!capabilities) return void 0;
|
|
87
|
+
const caps = unwrap(capabilities);
|
|
88
|
+
const explicit = text(caps["flakemetry:variant"]);
|
|
89
|
+
if (explicit) return explicit;
|
|
90
|
+
const label = [text(caps.platformName), text(caps.browserName) ?? text(caps["appium:deviceName"]) ?? text(caps.deviceName)].filter(Boolean).join(" ");
|
|
91
|
+
return label.length > 0 ? label : void 0;
|
|
92
|
+
};
|
|
93
|
+
const capabilityIndex = (cid) => {
|
|
94
|
+
const index = Number.parseInt(cid ?? "", 10);
|
|
95
|
+
return Number.isInteger(index) && index >= 0 ? index : void 0;
|
|
96
|
+
};
|
|
97
|
+
const resolveVariant = ({ cid, requested, configured, multiremote }) => {
|
|
98
|
+
if (multiremote) return void 0;
|
|
99
|
+
const index = capabilityIndex(cid);
|
|
100
|
+
const own = index !== void 0 ? configured?.[index] : void 0;
|
|
101
|
+
const explicit = explicitVariant(requested) ?? explicitVariant(own);
|
|
102
|
+
if (explicit) return explicit.slice(0, MAX_VARIANT_LENGTH);
|
|
103
|
+
if (!configured || configured.length < 2 || index === void 0) return void 0;
|
|
104
|
+
const labels = configured.map((capabilities, position) => capabilityLabel(capabilities) ?? `capability ${position + 1}`);
|
|
105
|
+
const label = labels[index] ?? capabilityLabel(requested) ?? `capability ${index + 1}`;
|
|
106
|
+
return (labels.filter((candidate) => candidate === label).length > 1 ? `${label} (${index + 1})` : label).slice(0, MAX_VARIANT_LENGTH);
|
|
107
|
+
};
|
|
108
|
+
const shardOf = (shard) => {
|
|
109
|
+
if (!shard || typeof shard !== "object") return null;
|
|
110
|
+
const { current, total } = shard;
|
|
111
|
+
return typeof current === "number" && typeof total === "number" && total > 1 ? {
|
|
112
|
+
current,
|
|
113
|
+
total
|
|
114
|
+
} : null;
|
|
115
|
+
};
|
|
116
|
+
const workerOutputFile = (file, cid) => {
|
|
117
|
+
const extension = extname(file);
|
|
118
|
+
const name = basename(file, extension);
|
|
119
|
+
const worker = cid.replace(/[^\w.-]+/g, "-");
|
|
120
|
+
return join(dirname(file), `${name}-${worker}${extension}`);
|
|
121
|
+
};
|
|
122
|
+
const workerIdempotencyKey = (key, cid) => {
|
|
123
|
+
const suffix = `-w${cid.replace(/[^\w.-]+/g, "-")}`;
|
|
124
|
+
return `${key.slice(0, MAX_IDEMPOTENCY_KEY_LENGTH - suffix.length)}${suffix}`;
|
|
125
|
+
};
|
|
126
|
+
const runFailed = (tests) => tests.some((test) => test.status === "fail");
|
|
127
|
+
// src/collector.ts
|
|
128
|
+
const SUITE_SEPARATOR = " > ";
|
|
129
|
+
const NODE_MODULES = `${sep}node_modules${sep}`;
|
|
130
|
+
const usableFile = (raw) => {
|
|
131
|
+
const file = toFilePath(raw);
|
|
132
|
+
return file && !file.includes(NODE_MODULES) && !file.includes("/node_modules/") ? file : void 0;
|
|
133
|
+
};
|
|
134
|
+
var WdioCollector = class {
|
|
135
|
+
now;
|
|
136
|
+
suites = /* @__PURE__ */ new Map();
|
|
137
|
+
stack = [];
|
|
138
|
+
owners = [];
|
|
139
|
+
retrying = /* @__PURE__ */ new Map();
|
|
140
|
+
collected = [];
|
|
141
|
+
fallbackFile;
|
|
142
|
+
constructor(now = Date.now) {
|
|
143
|
+
this.now = now;
|
|
144
|
+
}
|
|
145
|
+
get size() {
|
|
146
|
+
return this.collected.length;
|
|
147
|
+
}
|
|
148
|
+
setSpecs(specs) {
|
|
149
|
+
this.fallbackFile = usableFile(specs?.[0]);
|
|
150
|
+
}
|
|
151
|
+
suiteStart(suite) {
|
|
152
|
+
this.suites.set(suite.uid, suite);
|
|
153
|
+
this.stack.push(suite.uid);
|
|
154
|
+
}
|
|
155
|
+
suiteEnd(suite) {
|
|
156
|
+
for (const owner of [...this.owners]) if (owner.type === "test" && owner.suiteUids.includes(suite.uid)) this.finalize(owner);
|
|
157
|
+
const index = this.stack.lastIndexOf(suite.uid);
|
|
158
|
+
if (index !== -1) this.stack.splice(index, 1);
|
|
159
|
+
}
|
|
160
|
+
hookStart(hook) {
|
|
161
|
+
this.owners.push({
|
|
162
|
+
type: "hook",
|
|
163
|
+
stats: hook,
|
|
164
|
+
...this.ownerBase(hook, hook.start)
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
hookEnd(hook) {
|
|
168
|
+
const owner = this.findOwner("hook", hook.uid);
|
|
169
|
+
if (!owner) return;
|
|
170
|
+
this.remove(owner);
|
|
171
|
+
this.closeOpen(owner);
|
|
172
|
+
const durationMs = this.durationOf(hook.duration, owner.startedAt);
|
|
173
|
+
const error = errorOf(hook.errors, hook.error);
|
|
174
|
+
if (Boolean(error) || hook.state === "failed") {
|
|
175
|
+
if (hook.retried || hook.failedTestUid) return;
|
|
176
|
+
this.collected.push({
|
|
177
|
+
file: owner.file,
|
|
178
|
+
test: {
|
|
179
|
+
suite: owner.suite.join(SUITE_SEPARATOR),
|
|
180
|
+
title: owner.title || "hook",
|
|
181
|
+
status: "fail",
|
|
182
|
+
attempt: 1,
|
|
183
|
+
retryOfIndex: null,
|
|
184
|
+
startedAt: owner.startedAt,
|
|
185
|
+
durationMs,
|
|
186
|
+
error: summarizeError(error, "hook failed"),
|
|
187
|
+
steps: owner.steps.length > 0 ? owner.steps : null
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const attempt = this.latestOwner(hook.contextId, "test");
|
|
193
|
+
if (!attempt) return;
|
|
194
|
+
this.addStep(attempt, attempt.steps, {
|
|
195
|
+
name: owner.title || "hook",
|
|
196
|
+
kind: "step",
|
|
197
|
+
startedAt: owner.startedAt,
|
|
198
|
+
durationMs,
|
|
199
|
+
status: "ok",
|
|
200
|
+
...owner.steps.length > 0 ? { children: owner.steps } : {}
|
|
201
|
+
});
|
|
202
|
+
attempt.spans += owner.spans;
|
|
203
|
+
}
|
|
204
|
+
testStart(test) {
|
|
205
|
+
if (this.findOwner("test", test.uid)) return;
|
|
206
|
+
this.open(test);
|
|
207
|
+
}
|
|
208
|
+
testPass(test) {
|
|
209
|
+
this.attemptFor(test).outcome = "pass";
|
|
210
|
+
}
|
|
211
|
+
testFail(test) {
|
|
212
|
+
const attempt = this.attemptFor(test);
|
|
213
|
+
const error = errorOf(test.errors, test.error);
|
|
214
|
+
attempt.outcome = neverRan(error) ? "skip" : "fail";
|
|
215
|
+
attempt.error = attempt.outcome === "fail" ? error : void 0;
|
|
216
|
+
}
|
|
217
|
+
testRetry(test) {
|
|
218
|
+
const attempt = this.attemptFor(test);
|
|
219
|
+
attempt.outcome = "fail";
|
|
220
|
+
attempt.error = errorOf(test.errors, test.error);
|
|
221
|
+
const index = this.finalize(attempt);
|
|
222
|
+
this.retrying.set(attempt.key, {
|
|
223
|
+
attempt: attempt.attempt,
|
|
224
|
+
firstIndex: attempt.retryOf ?? index
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
testSkip(test) {
|
|
228
|
+
this.attemptFor(test).outcome = "skip";
|
|
229
|
+
}
|
|
230
|
+
testEnd(test) {
|
|
231
|
+
const attempt = this.findOwner("test", test.uid);
|
|
232
|
+
if (attempt) this.finalize(attempt);
|
|
233
|
+
}
|
|
234
|
+
beforeCommand(command) {
|
|
235
|
+
const owner = this.latestOwner(command.contextId);
|
|
236
|
+
if (!owner) return;
|
|
237
|
+
const parent = owner.assertions.at(-1)?.step;
|
|
238
|
+
const started = this.now();
|
|
239
|
+
const attributes = {};
|
|
240
|
+
if (command.command) attributes["wdio.command"] = command.command;
|
|
241
|
+
if (command.method) attributes["http.request.method"] = command.method;
|
|
242
|
+
if (command.endpoint) attributes["url.path"] = command.endpoint;
|
|
243
|
+
const step = {
|
|
244
|
+
name: command.command || "command",
|
|
245
|
+
kind: "browser",
|
|
246
|
+
startedAt: new Date(started),
|
|
247
|
+
durationMs: 0,
|
|
248
|
+
status: "unset",
|
|
249
|
+
attributes
|
|
250
|
+
};
|
|
251
|
+
if (!this.addStep(owner, parent ? parent.children ??= [] : owner.steps, step)) return;
|
|
252
|
+
owner.commands.push({
|
|
253
|
+
key: this.commandKey(command),
|
|
254
|
+
step,
|
|
255
|
+
started
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
afterCommand(command) {
|
|
259
|
+
const owner = this.latestOwner(command.contextId);
|
|
260
|
+
if (!owner) return;
|
|
261
|
+
const key = this.commandKey(command);
|
|
262
|
+
const index = owner.commands.findIndex((open) => open.key === key);
|
|
263
|
+
if (index === -1) return;
|
|
264
|
+
const [open] = owner.commands.splice(index, 1);
|
|
265
|
+
if (!open) return;
|
|
266
|
+
const outcome = commandStatus(command.result);
|
|
267
|
+
open.step.durationMs = Math.max(0, this.now() - open.started);
|
|
268
|
+
open.step.status = outcome.status;
|
|
269
|
+
open.step.error = outcome.error;
|
|
270
|
+
}
|
|
271
|
+
beforeAssertion(assertion) {
|
|
272
|
+
const owner = this.latestOwner(assertion.contextId);
|
|
273
|
+
if (!owner) return;
|
|
274
|
+
const parent = owner.assertions.at(-1)?.step;
|
|
275
|
+
const started = this.now();
|
|
276
|
+
const step = {
|
|
277
|
+
name: `expect.${assertion.matcherName || "assertion"}`,
|
|
278
|
+
kind: "step",
|
|
279
|
+
startedAt: new Date(started),
|
|
280
|
+
durationMs: 0,
|
|
281
|
+
status: "unset"
|
|
282
|
+
};
|
|
283
|
+
if (!this.addStep(owner, parent ? parent.children ??= [] : owner.steps, step)) return;
|
|
284
|
+
owner.assertions.push({
|
|
285
|
+
step,
|
|
286
|
+
started
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
afterAssertion(assertion) {
|
|
290
|
+
const open = this.latestOwner(assertion.contextId)?.assertions.pop();
|
|
291
|
+
if (!open) return;
|
|
292
|
+
open.step.durationMs = Math.max(0, this.now() - open.started);
|
|
293
|
+
const pass = assertion.result?.pass;
|
|
294
|
+
if (typeof pass === "boolean") open.step.attributes = { "wdio.assertion.pass": pass };
|
|
295
|
+
}
|
|
296
|
+
finish({ rootDir, variant }) {
|
|
297
|
+
for (const owner of [...this.owners]) if (owner.type === "test") this.finalize(owner);
|
|
298
|
+
else this.remove(owner);
|
|
299
|
+
return this.collected.map(({ file, test }) => ({
|
|
300
|
+
...test,
|
|
301
|
+
filePath: file ? relativize(rootDir, file) : "unknown",
|
|
302
|
+
variant
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
ownerBase(stats, start) {
|
|
306
|
+
const { titles, uids } = this.locate(stats);
|
|
307
|
+
return {
|
|
308
|
+
uid: stats.uid,
|
|
309
|
+
contextId: stats.contextId,
|
|
310
|
+
title: stats.title,
|
|
311
|
+
suite: titles,
|
|
312
|
+
suiteUids: uids,
|
|
313
|
+
file: this.fileOf(stats.file, uids),
|
|
314
|
+
startedAt: this.dateOf(start),
|
|
315
|
+
steps: [],
|
|
316
|
+
spans: 0,
|
|
317
|
+
commands: [],
|
|
318
|
+
assertions: []
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
open(test) {
|
|
322
|
+
const base = this.ownerBase(test, test.start);
|
|
323
|
+
const key = [
|
|
324
|
+
base.file ?? "",
|
|
325
|
+
base.suite.join(SUITE_SEPARATOR),
|
|
326
|
+
test.title
|
|
327
|
+
].join("\0");
|
|
328
|
+
const stale = this.owners.find((owner) => owner.type === "test" && owner.key === key);
|
|
329
|
+
if (stale) {
|
|
330
|
+
this.remove(stale);
|
|
331
|
+
this.closeOpen(stale);
|
|
332
|
+
}
|
|
333
|
+
const previous = stale ? void 0 : this.retrying.get(key);
|
|
334
|
+
if (previous) this.retrying.delete(key);
|
|
335
|
+
const attempt = {
|
|
336
|
+
...base,
|
|
337
|
+
...stale ? {
|
|
338
|
+
startedAt: stale.startedAt,
|
|
339
|
+
steps: stale.steps,
|
|
340
|
+
spans: stale.spans
|
|
341
|
+
} : {},
|
|
342
|
+
type: "test",
|
|
343
|
+
stats: test,
|
|
344
|
+
key,
|
|
345
|
+
attempt: stale ? stale.attempt : previous ? previous.attempt + 1 : 1,
|
|
346
|
+
retryOf: stale ? stale.retryOf : previous ? previous.firstIndex : null
|
|
347
|
+
};
|
|
348
|
+
this.owners.push(attempt);
|
|
349
|
+
return attempt;
|
|
350
|
+
}
|
|
351
|
+
attemptFor(test) {
|
|
352
|
+
return this.findOwner("test", test.uid) ?? this.open(test);
|
|
353
|
+
}
|
|
354
|
+
finalize(attempt) {
|
|
355
|
+
this.remove(attempt);
|
|
356
|
+
this.closeOpen(attempt);
|
|
357
|
+
const status = attempt.outcome === "pass" ? attempt.attempt > 1 ? "flaky" : "pass" : attempt.outcome === "fail" ? "fail" : "skip";
|
|
358
|
+
this.collected.push({
|
|
359
|
+
file: attempt.file,
|
|
360
|
+
test: {
|
|
361
|
+
suite: attempt.suite.join(SUITE_SEPARATOR),
|
|
362
|
+
title: attempt.title || "untitled",
|
|
363
|
+
status,
|
|
364
|
+
attempt: attempt.attempt,
|
|
365
|
+
retryOfIndex: attempt.retryOf,
|
|
366
|
+
startedAt: attempt.startedAt,
|
|
367
|
+
durationMs: this.durationOf(attempt.stats.duration, attempt.startedAt),
|
|
368
|
+
error: status === "fail" ? summarizeError(attempt.error, "test failed") : null,
|
|
369
|
+
steps: attempt.steps.length > 0 ? attempt.steps : null
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
return this.collected.length - 1;
|
|
373
|
+
}
|
|
374
|
+
addStep(owner, siblings, step) {
|
|
375
|
+
if (owner.spans >= MAX_SPANS_PER_EXECUTION) return false;
|
|
376
|
+
siblings.push(step);
|
|
377
|
+
owner.spans += 1;
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
closeOpen(owner) {
|
|
381
|
+
const now = this.now();
|
|
382
|
+
for (const open of owner.commands) open.step.durationMs = Math.max(0, now - open.started);
|
|
383
|
+
for (const open of owner.assertions) open.step.durationMs = Math.max(0, now - open.started);
|
|
384
|
+
owner.commands = [];
|
|
385
|
+
owner.assertions = [];
|
|
386
|
+
}
|
|
387
|
+
commandKey(command) {
|
|
388
|
+
return `${command.command ?? ""} ${command.method ?? ""} ${command.endpoint ?? ""}`;
|
|
389
|
+
}
|
|
390
|
+
findOwner(type, uid) {
|
|
391
|
+
for (let index = this.owners.length - 1; index >= 0; index -= 1) {
|
|
392
|
+
const owner = this.owners[index];
|
|
393
|
+
if (owner && owner.type === type && owner.uid === uid) return owner;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
latestOwner(contextId, type) {
|
|
397
|
+
for (let index = this.owners.length - 1; index >= 0; index -= 1) {
|
|
398
|
+
const owner = this.owners[index];
|
|
399
|
+
if (!owner || type && owner.type !== type) continue;
|
|
400
|
+
if (contextId === void 0 || owner.contextId === contextId) return owner;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
remove(owner) {
|
|
404
|
+
const index = this.owners.indexOf(owner);
|
|
405
|
+
if (index !== -1) this.owners.splice(index, 1);
|
|
406
|
+
}
|
|
407
|
+
locate(stats) {
|
|
408
|
+
const anchor = stats.hookSuiteUid ?? stats.parentUid;
|
|
409
|
+
const uids = anchor === null ? [] : (anchor ? this.chain(anchor) : null) ?? [...this.stack];
|
|
410
|
+
return {
|
|
411
|
+
titles: uids.map((uid) => this.suites.get(uid)?.title ?? "").filter((title) => title.length > 0),
|
|
412
|
+
uids
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
chain(uid) {
|
|
416
|
+
const uids = [];
|
|
417
|
+
let current = uid;
|
|
418
|
+
while (current) {
|
|
419
|
+
const suite = this.suites.get(current);
|
|
420
|
+
if (!suite || suite.parentUid === void 0) return null;
|
|
421
|
+
uids.unshift(current);
|
|
422
|
+
current = suite.parentUid;
|
|
423
|
+
}
|
|
424
|
+
return uids;
|
|
425
|
+
}
|
|
426
|
+
fileOf(own, uids) {
|
|
427
|
+
const direct = usableFile(own);
|
|
428
|
+
if (direct) return direct;
|
|
429
|
+
for (let index = uids.length - 1; index >= 0; index -= 1) {
|
|
430
|
+
const file = usableFile(this.suites.get(uids[index] ?? "")?.file);
|
|
431
|
+
if (file) return file;
|
|
432
|
+
}
|
|
433
|
+
return this.fallbackFile;
|
|
434
|
+
}
|
|
435
|
+
dateOf(start) {
|
|
436
|
+
if (start instanceof Date && !Number.isNaN(start.getTime())) return start;
|
|
437
|
+
if (typeof start === "number" && Number.isFinite(start)) return new Date(start);
|
|
438
|
+
return new Date(this.now());
|
|
439
|
+
}
|
|
440
|
+
durationOf(duration, startedAt) {
|
|
441
|
+
if (typeof duration === "number" && Number.isFinite(duration)) return Math.max(0, Math.round(duration));
|
|
442
|
+
return Math.max(0, Math.round(this.now() - startedAt.getTime()));
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
// src/capabilities.ts
|
|
446
|
+
const DEFAULT_CONFIG_FILES = [
|
|
447
|
+
"wdio.conf.ts",
|
|
448
|
+
"wdio.conf.js",
|
|
449
|
+
"wdio.conf.mts",
|
|
450
|
+
"wdio.conf.mjs",
|
|
451
|
+
"wdio.conf.cts",
|
|
452
|
+
"wdio.conf.cjs"
|
|
453
|
+
];
|
|
454
|
+
const IMPLIED_EXTENSIONS = [
|
|
455
|
+
"",
|
|
456
|
+
".ts",
|
|
457
|
+
".js"
|
|
458
|
+
];
|
|
459
|
+
const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
460
|
+
const findConfigFile = (config, cwd, exists = existsSync) => {
|
|
461
|
+
const given = [config?.["config-path"], config?.configPath].find((value) => typeof value === "string" && value.length > 0);
|
|
462
|
+
return (given ? IMPLIED_EXTENSIONS.map((extension) => resolve(cwd, `${given}${extension}`)) : DEFAULT_CONFIG_FILES.map((name) => resolve(cwd, name))).find((candidate) => exists(candidate));
|
|
463
|
+
};
|
|
464
|
+
const loadConfiguredCapabilities = async (config, cwd, importModule = (specifier) => import(specifier), exists = existsSync) => {
|
|
465
|
+
try {
|
|
466
|
+
const file = findConfigFile(config, cwd, exists);
|
|
467
|
+
if (!file) return null;
|
|
468
|
+
const loaded = await importModule(pathToFileURL(file).href);
|
|
469
|
+
const capabilities = (loaded?.config ?? loaded?.default?.config)?.capabilities;
|
|
470
|
+
return Array.isArray(capabilities) ? capabilities.map((entry) => isRecord(entry) ? entry : {}) : null;
|
|
471
|
+
} catch {
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
// src/reporter.ts
|
|
476
|
+
const WDIOReporter = WDIOReporterExport.default ?? WDIOReporterExport;
|
|
477
|
+
const SILENT = { write: () => true };
|
|
478
|
+
const asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
479
|
+
const deliveryOptions = (options) => {
|
|
480
|
+
const { endpoint, token, outputFile, transport, bufferDir, sampleRate, rng } = options;
|
|
481
|
+
return {
|
|
482
|
+
endpoint,
|
|
483
|
+
token,
|
|
484
|
+
outputFile,
|
|
485
|
+
transport,
|
|
486
|
+
bufferDir,
|
|
487
|
+
sampleRate,
|
|
488
|
+
rng
|
|
489
|
+
};
|
|
490
|
+
};
|
|
491
|
+
var FlakemetryWdioReporter = class extends WDIOReporter {
|
|
492
|
+
delivery;
|
|
493
|
+
env;
|
|
494
|
+
collector;
|
|
495
|
+
configured = Promise.resolve(null);
|
|
496
|
+
startedAt;
|
|
497
|
+
delivering = false;
|
|
498
|
+
constructor(options = {}) {
|
|
499
|
+
super({
|
|
500
|
+
...options,
|
|
501
|
+
logFile: void 0,
|
|
502
|
+
outputDir: void 0,
|
|
503
|
+
writeStream: options.writeStream ?? SILENT
|
|
504
|
+
});
|
|
505
|
+
this.delivery = deliveryOptions(options);
|
|
506
|
+
this.env = process.env;
|
|
507
|
+
this.collector = new WdioCollector();
|
|
508
|
+
}
|
|
509
|
+
get isSynchronised() {
|
|
510
|
+
return !this.delivering;
|
|
511
|
+
}
|
|
512
|
+
onRunnerStart(runner) {
|
|
513
|
+
this.guard(() => {
|
|
514
|
+
this.startedAt = runner.start instanceof Date ? runner.start : /* @__PURE__ */ new Date();
|
|
515
|
+
this.collector.setSpecs(runner.specs);
|
|
516
|
+
this.configured = loadConfiguredCapabilities(asRecord(runner.config), process.cwd());
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
onSuiteStart(suite) {
|
|
520
|
+
this.guard(() => this.collector.suiteStart(suite));
|
|
521
|
+
}
|
|
522
|
+
onSuiteEnd(suite) {
|
|
523
|
+
this.guard(() => this.collector.suiteEnd(suite));
|
|
524
|
+
}
|
|
525
|
+
onHookStart(hook) {
|
|
526
|
+
this.guard(() => this.collector.hookStart(hook));
|
|
527
|
+
}
|
|
528
|
+
onHookEnd(hook) {
|
|
529
|
+
this.guard(() => this.collector.hookEnd(hook));
|
|
530
|
+
}
|
|
531
|
+
onTestStart(test) {
|
|
532
|
+
this.guard(() => this.collector.testStart(test));
|
|
533
|
+
}
|
|
534
|
+
onTestPass(test) {
|
|
535
|
+
this.guard(() => this.collector.testPass(test));
|
|
536
|
+
}
|
|
537
|
+
onTestFail(test) {
|
|
538
|
+
this.guard(() => this.collector.testFail(test));
|
|
539
|
+
}
|
|
540
|
+
onTestRetry(test) {
|
|
541
|
+
this.guard(() => this.collector.testRetry(test));
|
|
542
|
+
}
|
|
543
|
+
onTestSkip(test) {
|
|
544
|
+
this.guard(() => this.collector.testSkip(test));
|
|
545
|
+
}
|
|
546
|
+
onTestPending(test) {
|
|
547
|
+
this.guard(() => this.collector.testSkip(test));
|
|
548
|
+
}
|
|
549
|
+
onTestEnd(test) {
|
|
550
|
+
this.guard(() => this.collector.testEnd(test));
|
|
551
|
+
}
|
|
552
|
+
onBeforeCommand(command) {
|
|
553
|
+
this.guard(() => this.collector.beforeCommand(command));
|
|
554
|
+
}
|
|
555
|
+
onAfterCommand(command) {
|
|
556
|
+
this.guard(() => this.collector.afterCommand(command));
|
|
557
|
+
}
|
|
558
|
+
onBeforeAssertion(assertion) {
|
|
559
|
+
this.guard(() => this.collector.beforeAssertion(assertion));
|
|
560
|
+
}
|
|
561
|
+
onAfterAssertion(assertion) {
|
|
562
|
+
this.guard(() => this.collector.afterAssertion(assertion));
|
|
563
|
+
}
|
|
564
|
+
onRunnerEnd(runner) {
|
|
565
|
+
this.delivering = true;
|
|
566
|
+
this.deliver(runner).finally(() => {
|
|
567
|
+
this.delivering = false;
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
async deliver(runner) {
|
|
571
|
+
try {
|
|
572
|
+
const config = asRecord(runner.config) ?? {};
|
|
573
|
+
const rootDir = typeof config.rootDir === "string" ? config.rootDir : process.cwd();
|
|
574
|
+
const cid = runner.cid ?? this.env.WDIO_WORKER_ID ?? "0-0";
|
|
575
|
+
const variant = resolveVariant({
|
|
576
|
+
cid,
|
|
577
|
+
requested: asRecord(config.capabilities) ?? asRecord(runner.capabilities),
|
|
578
|
+
configured: await this.configured,
|
|
579
|
+
multiremote: Boolean(runner.isMultiremote ?? runner.isMultiRemote)
|
|
580
|
+
});
|
|
581
|
+
const tests = this.collector.finish({
|
|
582
|
+
rootDir,
|
|
583
|
+
variant
|
|
584
|
+
});
|
|
585
|
+
if (tests.length === 0) return;
|
|
586
|
+
const context = resolveRunContext(this.env, shardOf(config.shard));
|
|
587
|
+
const recorder = new TestRunRecorder(context);
|
|
588
|
+
recorder.startRun(this.startedAt ?? tests[0]?.startedAt ?? /* @__PURE__ */ new Date());
|
|
589
|
+
for (const test of tests) recorder.record(test);
|
|
590
|
+
recorder.finishRun(runFailed(tests) ? "failed" : "passed", runner.end instanceof Date ? runner.end : /* @__PURE__ */ new Date());
|
|
591
|
+
const outputFile = this.delivery.outputFile ?? this.env.FLAKEMETRY_OUTPUT_FILE;
|
|
592
|
+
const idempotencyKey = workerIdempotencyKey(buildIdempotencyKey(context, this.env), cid);
|
|
593
|
+
await deliverRun(recorder, idempotencyKey, {
|
|
594
|
+
...this.delivery,
|
|
595
|
+
outputFile: outputFile ? workerOutputFile(outputFile, cid) : void 0
|
|
596
|
+
}, this.env, rootDir);
|
|
597
|
+
} catch (error) {
|
|
598
|
+
process.stderr.write(`flakemetry: the run was not delivered (${error instanceof Error ? error.message : String(error)})\n`);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
guard(action) {
|
|
602
|
+
try {
|
|
603
|
+
action();
|
|
604
|
+
} catch (error) {
|
|
605
|
+
process.stderr.write(`flakemetry: an event was not recorded (${error instanceof Error ? error.message : String(error)})\n`);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
export { WdioCollector, capabilityLabel, FlakemetryWdioReporter as default, resolveVariant };
|
|
610
|
+
|
|
611
|
+
//# sourceMappingURL=index.js.map
|