@wdio/reporter 9.0.0-alpha.78 → 9.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/build/index.cjs +752 -0
- package/build/index.d.ts +1 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +709 -257
- package/build/stats/runner.d.ts +1 -1
- package/build/stats/runner.d.ts.map +1 -1
- package/build/utils.d.ts +1 -2
- package/build/utils.d.ts.map +1 -1
- package/package.json +10 -14
- package/build/constants.js +0 -23
- package/build/stats/hook.js +0 -30
- package/build/stats/runnable.js +0 -29
- package/build/stats/runner.js +0 -31
- package/build/stats/suite.js +0 -37
- package/build/stats/test.js +0 -108
- package/build/supportsColor.js +0 -146
- package/build/types.js +0 -1
- package/build/utils.js +0 -93
- package/cjs/constants.js +0 -26
- package/cjs/index.js +0 -271
- package/cjs/package.json +0 -5
- package/cjs/stats/hook.js +0 -36
- package/cjs/stats/runnable.js +0 -32
- package/cjs/stats/runner.js +0 -37
- package/cjs/stats/suite.js +0 -43
- package/cjs/stats/test.js +0 -114
- package/cjs/supportsColor.js +0 -153
- package/cjs/types.js +0 -2
- package/cjs/utils.js +0 -105
- package/tsconfig.cjs.json +0 -10
- /package/{LICENSE-MIT → LICENSE} +0 -0
package/build/index.cjs
ADDED
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
const __importMetaUrl = require('url').pathToFileURL(__filename).href;
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var src_exports = {};
|
|
33
|
+
__export(src_exports, {
|
|
34
|
+
HookStats: () => HookStats,
|
|
35
|
+
RunnerStats: () => RunnerStats,
|
|
36
|
+
SuiteStats: () => SuiteStats,
|
|
37
|
+
TestStats: () => TestStats,
|
|
38
|
+
default: () => WDIOReporter
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(src_exports);
|
|
41
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
42
|
+
var import_node_events = require("node:events");
|
|
43
|
+
|
|
44
|
+
// src/supportsColor.ts
|
|
45
|
+
var import_node_process = __toESM(require("node:process"), 1);
|
|
46
|
+
var import_node_os = __toESM(require("node:os"), 1);
|
|
47
|
+
var import_node_tty = __toESM(require("node:tty"), 1);
|
|
48
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
|
|
49
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
50
|
+
const position = argv.indexOf(prefix + flag);
|
|
51
|
+
const terminatorPosition = argv.indexOf("--");
|
|
52
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
53
|
+
}
|
|
54
|
+
var { env } = import_node_process.default;
|
|
55
|
+
var flagForceColor;
|
|
56
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
57
|
+
flagForceColor = 0;
|
|
58
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
59
|
+
flagForceColor = 1;
|
|
60
|
+
}
|
|
61
|
+
function envForceColor() {
|
|
62
|
+
if ("FORCE_COLOR" in env) {
|
|
63
|
+
if (env.FORCE_COLOR === "true") {
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
66
|
+
if (env.FORCE_COLOR === "false") {
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function translateLevel(level) {
|
|
73
|
+
if (level === 0) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
level,
|
|
78
|
+
hasBasic: true,
|
|
79
|
+
has256: level >= 2,
|
|
80
|
+
has16m: level >= 3
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
84
|
+
const noFlagForceColor = envForceColor();
|
|
85
|
+
if (noFlagForceColor !== void 0) {
|
|
86
|
+
flagForceColor = noFlagForceColor;
|
|
87
|
+
}
|
|
88
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
89
|
+
if (forceColor === 0) {
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
if (sniffFlags) {
|
|
93
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
94
|
+
return 3;
|
|
95
|
+
}
|
|
96
|
+
if (hasFlag("color=256")) {
|
|
97
|
+
return 2;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
if (haveStream && !streamIsTTY && forceColor === void 0) {
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
const min = forceColor || 0;
|
|
107
|
+
if (env.TERM === "dumb") {
|
|
108
|
+
return min;
|
|
109
|
+
}
|
|
110
|
+
if (import_node_process.default.platform === "win32") {
|
|
111
|
+
const osRelease = import_node_os.default.release().split(".");
|
|
112
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
113
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
114
|
+
}
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
117
|
+
if ("CI" in env) {
|
|
118
|
+
if ("GITHUB_ACTIONS" in env || "GITEA_ACTIONS" in env) {
|
|
119
|
+
return 3;
|
|
120
|
+
}
|
|
121
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
return min;
|
|
125
|
+
}
|
|
126
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
127
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
128
|
+
}
|
|
129
|
+
if (env.COLORTERM === "truecolor") {
|
|
130
|
+
return 3;
|
|
131
|
+
}
|
|
132
|
+
if (env.TERM === "xterm-kitty") {
|
|
133
|
+
return 3;
|
|
134
|
+
}
|
|
135
|
+
if ("TERM_PROGRAM" in env) {
|
|
136
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
137
|
+
switch (env.TERM_PROGRAM) {
|
|
138
|
+
case "iTerm.app": {
|
|
139
|
+
return version >= 3 ? 3 : 2;
|
|
140
|
+
}
|
|
141
|
+
case "Apple_Terminal": {
|
|
142
|
+
return 2;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (env.TERM && /-256(color)?$/i.test(env.TERM)) {
|
|
147
|
+
return 2;
|
|
148
|
+
}
|
|
149
|
+
if (env.TERM && /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
150
|
+
return 1;
|
|
151
|
+
}
|
|
152
|
+
if ("COLORTERM" in env) {
|
|
153
|
+
return 1;
|
|
154
|
+
}
|
|
155
|
+
return min;
|
|
156
|
+
}
|
|
157
|
+
function createSupportsColor(stream, options = {}) {
|
|
158
|
+
const level = _supportsColor(stream, {
|
|
159
|
+
streamIsTTY: stream && stream.isTTY,
|
|
160
|
+
...options
|
|
161
|
+
});
|
|
162
|
+
return translateLevel(level);
|
|
163
|
+
}
|
|
164
|
+
var supportsColor = {
|
|
165
|
+
stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }),
|
|
166
|
+
stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) })
|
|
167
|
+
};
|
|
168
|
+
var supportsColor_default = supportsColor;
|
|
169
|
+
|
|
170
|
+
// src/constants.ts
|
|
171
|
+
var COLORS = {
|
|
172
|
+
pass: 90,
|
|
173
|
+
fail: 31,
|
|
174
|
+
"bright pass": 92,
|
|
175
|
+
"bright fail": 91,
|
|
176
|
+
"bright yellow": 93,
|
|
177
|
+
pending: 36,
|
|
178
|
+
suite: 0,
|
|
179
|
+
"error title": 0,
|
|
180
|
+
"error message": 31,
|
|
181
|
+
"error stack": 90,
|
|
182
|
+
checkmark: 32,
|
|
183
|
+
fast: 90,
|
|
184
|
+
medium: 33,
|
|
185
|
+
slow: 31,
|
|
186
|
+
green: 32,
|
|
187
|
+
light: 90,
|
|
188
|
+
"diff gutter": 90,
|
|
189
|
+
"diff added": 32,
|
|
190
|
+
"diff removed": 31,
|
|
191
|
+
"diff added inline": "30;42",
|
|
192
|
+
"diff removed inline": "30;41"
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// src/utils.ts
|
|
196
|
+
function sanitizeString(str) {
|
|
197
|
+
if (!str) {
|
|
198
|
+
return "";
|
|
199
|
+
}
|
|
200
|
+
return String(str).replace(/^.*\/([^/]+)\/?$/, "$1").replace(/\./g, "_").replace(/\s/g, "").toLowerCase();
|
|
201
|
+
}
|
|
202
|
+
function sanitizeCaps(caps) {
|
|
203
|
+
if (!caps) {
|
|
204
|
+
return "";
|
|
205
|
+
}
|
|
206
|
+
let result;
|
|
207
|
+
result = caps["appium:deviceName"] || caps.deviceName ? [
|
|
208
|
+
sanitizeString(caps.platformName),
|
|
209
|
+
// @ts-expect-error outdated JSONWP capabilities
|
|
210
|
+
sanitizeString(caps["appium:deviceName"] || caps.deviceName),
|
|
211
|
+
sanitizeString(caps["appium:platformVersion"]),
|
|
212
|
+
sanitizeString(caps["appium:app"])
|
|
213
|
+
] : [
|
|
214
|
+
sanitizeString(caps.browserName),
|
|
215
|
+
// @ts-expect-error outdated JSONWP capabilities
|
|
216
|
+
sanitizeString(caps.version || caps.browserVersion),
|
|
217
|
+
// @ts-expect-error outdated JSONWP capabilities
|
|
218
|
+
sanitizeString(caps.platform || caps.platformName),
|
|
219
|
+
sanitizeString(caps["appium:app"])
|
|
220
|
+
];
|
|
221
|
+
result = result.filter((n) => n !== void 0 && n !== "");
|
|
222
|
+
return result.join(".");
|
|
223
|
+
}
|
|
224
|
+
function getErrorsFromEvent(e) {
|
|
225
|
+
if (e.errors) {
|
|
226
|
+
return e.errors;
|
|
227
|
+
}
|
|
228
|
+
if (e.error) {
|
|
229
|
+
return [e.error];
|
|
230
|
+
}
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
function pad(str, len) {
|
|
234
|
+
return Array(len - str.length + 1).join(" ") + str;
|
|
235
|
+
}
|
|
236
|
+
function color(type, content) {
|
|
237
|
+
if (!supportsColor_default.stdout) {
|
|
238
|
+
return String(content);
|
|
239
|
+
}
|
|
240
|
+
return `\x1B[${COLORS[type]}m${content}\x1B[0m`;
|
|
241
|
+
}
|
|
242
|
+
function colorLines(name, str) {
|
|
243
|
+
return str.split("\n").map((str2) => color(name, str2)).join("\n");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// src/stats/runnable.ts
|
|
247
|
+
var RunnableStats = class {
|
|
248
|
+
constructor(type) {
|
|
249
|
+
this.type = type;
|
|
250
|
+
}
|
|
251
|
+
start = /* @__PURE__ */ new Date();
|
|
252
|
+
end;
|
|
253
|
+
_duration = 0;
|
|
254
|
+
complete() {
|
|
255
|
+
this.end = /* @__PURE__ */ new Date();
|
|
256
|
+
this._duration = this.end.getTime() - this.start.getTime();
|
|
257
|
+
}
|
|
258
|
+
get duration() {
|
|
259
|
+
if (this.end) {
|
|
260
|
+
return this._duration;
|
|
261
|
+
}
|
|
262
|
+
return (/* @__PURE__ */ new Date()).getTime() - this.start.getTime();
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* ToDo: we should always rely on uid
|
|
266
|
+
*/
|
|
267
|
+
static getIdentifier(runner) {
|
|
268
|
+
return runner.uid || runner.title;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// src/stats/suite.ts
|
|
273
|
+
var SuiteStats = class extends RunnableStats {
|
|
274
|
+
uid;
|
|
275
|
+
cid;
|
|
276
|
+
file;
|
|
277
|
+
title;
|
|
278
|
+
fullTitle;
|
|
279
|
+
tags;
|
|
280
|
+
tests = [];
|
|
281
|
+
hooks = [];
|
|
282
|
+
suites = [];
|
|
283
|
+
parent;
|
|
284
|
+
/**
|
|
285
|
+
* an array of hooks and tests stored in order as they happen
|
|
286
|
+
*/
|
|
287
|
+
hooksAndTests = [];
|
|
288
|
+
description;
|
|
289
|
+
rule;
|
|
290
|
+
constructor(suite) {
|
|
291
|
+
super(suite.type || "suite");
|
|
292
|
+
this.uid = RunnableStats.getIdentifier(suite);
|
|
293
|
+
this.cid = suite.cid;
|
|
294
|
+
this.file = suite.file;
|
|
295
|
+
this.title = suite.title;
|
|
296
|
+
this.fullTitle = suite.fullTitle;
|
|
297
|
+
this.tags = suite.tags;
|
|
298
|
+
this.parent = suite.parent;
|
|
299
|
+
this.description = suite.description;
|
|
300
|
+
this.rule = suite.rule;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// src/stats/hook.ts
|
|
305
|
+
var HookStats = class extends RunnableStats {
|
|
306
|
+
uid;
|
|
307
|
+
cid;
|
|
308
|
+
title;
|
|
309
|
+
parent;
|
|
310
|
+
// Mocha only
|
|
311
|
+
body;
|
|
312
|
+
errors;
|
|
313
|
+
error;
|
|
314
|
+
state;
|
|
315
|
+
currentTest;
|
|
316
|
+
constructor(runner) {
|
|
317
|
+
super("hook");
|
|
318
|
+
this.uid = RunnableStats.getIdentifier(runner);
|
|
319
|
+
this.cid = runner.cid;
|
|
320
|
+
this.title = runner.title;
|
|
321
|
+
this.parent = runner.parent;
|
|
322
|
+
this.currentTest = runner.currentTest;
|
|
323
|
+
this.body = runner.body;
|
|
324
|
+
}
|
|
325
|
+
complete(errors) {
|
|
326
|
+
this.errors = errors;
|
|
327
|
+
if (errors && errors.length) {
|
|
328
|
+
this.error = errors[0];
|
|
329
|
+
this.state = "failed";
|
|
330
|
+
}
|
|
331
|
+
super.complete();
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// src/stats/test.ts
|
|
336
|
+
var import_node_util = require("node:util");
|
|
337
|
+
var import_diff = require("diff");
|
|
338
|
+
var import_object_inspect = __toESM(require("object-inspect"), 1);
|
|
339
|
+
var maxStringLength = 2048;
|
|
340
|
+
var TestStats = class extends RunnableStats {
|
|
341
|
+
uid;
|
|
342
|
+
cid;
|
|
343
|
+
title;
|
|
344
|
+
currentTest;
|
|
345
|
+
fullTitle;
|
|
346
|
+
output;
|
|
347
|
+
argument;
|
|
348
|
+
retries;
|
|
349
|
+
parent;
|
|
350
|
+
/**
|
|
351
|
+
* initial test state is pending
|
|
352
|
+
* the state can change to the following: passed, skipped, failed
|
|
353
|
+
*/
|
|
354
|
+
state;
|
|
355
|
+
pendingReason;
|
|
356
|
+
errors;
|
|
357
|
+
error;
|
|
358
|
+
body;
|
|
359
|
+
constructor(test) {
|
|
360
|
+
super("test");
|
|
361
|
+
this.uid = RunnableStats.getIdentifier(test);
|
|
362
|
+
this.cid = test.cid;
|
|
363
|
+
this.title = test.title;
|
|
364
|
+
this.fullTitle = test.fullTitle;
|
|
365
|
+
this.output = [];
|
|
366
|
+
this.argument = test.argument;
|
|
367
|
+
this.retries = test.retries;
|
|
368
|
+
this.parent = test.parent;
|
|
369
|
+
this.body = test.body;
|
|
370
|
+
this.state = "pending";
|
|
371
|
+
}
|
|
372
|
+
pass() {
|
|
373
|
+
this.complete();
|
|
374
|
+
this.state = "passed";
|
|
375
|
+
}
|
|
376
|
+
skip(reason) {
|
|
377
|
+
this.pendingReason = reason;
|
|
378
|
+
this.state = "skipped";
|
|
379
|
+
}
|
|
380
|
+
fail(errors) {
|
|
381
|
+
this.complete();
|
|
382
|
+
this.state = "failed";
|
|
383
|
+
const formattedErrors = errors?.map((err) => (
|
|
384
|
+
/**
|
|
385
|
+
* only format if error object has either an "expected" or "actual" property set
|
|
386
|
+
*/
|
|
387
|
+
(err.expected || err.actual) && !import_node_util.types.isProxy(err.actual) && /**
|
|
388
|
+
* and if they aren't already formated, e.g. in Jasmine
|
|
389
|
+
*/
|
|
390
|
+
(err.message && !err.message.includes("Expected: ") && !err.message.includes("Received: ")) ? this._stringifyDiffObjs(err) : err
|
|
391
|
+
));
|
|
392
|
+
this.errors = formattedErrors;
|
|
393
|
+
if (formattedErrors && formattedErrors.length) {
|
|
394
|
+
this.error = formattedErrors[0];
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
_stringifyDiffObjs(err) {
|
|
398
|
+
const inspectOpts = { maxStringLength };
|
|
399
|
+
const expected = (0, import_object_inspect.default)(err.expected, inspectOpts);
|
|
400
|
+
const actual = (0, import_object_inspect.default)(err.actual, inspectOpts);
|
|
401
|
+
let msg = (0, import_diff.diffWordsWithSpace)(actual, expected).map((str) => str.added ? colorLines("diff added inline", str.value) : str.removed ? colorLines("diff removed inline", str.value) : str.value).join("");
|
|
402
|
+
const lines = msg.split("\n");
|
|
403
|
+
if (lines.length > 4) {
|
|
404
|
+
const width = String(lines.length).length;
|
|
405
|
+
msg = lines.map(function(str, i) {
|
|
406
|
+
return pad(String(++i), width) + " | " + str;
|
|
407
|
+
}).join("\n");
|
|
408
|
+
}
|
|
409
|
+
msg = `
|
|
410
|
+
${color("diff removed inline", "actual")} ${color("diff added inline", "expected")}
|
|
411
|
+
|
|
412
|
+
${msg}
|
|
413
|
+
`;
|
|
414
|
+
msg = msg.replace(/^/gm, " ");
|
|
415
|
+
const newError = new Error(err.message + msg);
|
|
416
|
+
newError.stack = err.stack;
|
|
417
|
+
return newError;
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// src/stats/runner.ts
|
|
422
|
+
var RunnerStats = class extends RunnableStats {
|
|
423
|
+
cid;
|
|
424
|
+
capabilities;
|
|
425
|
+
sanitizedCapabilities;
|
|
426
|
+
config;
|
|
427
|
+
specs;
|
|
428
|
+
sessionId;
|
|
429
|
+
isMultiremote;
|
|
430
|
+
instanceOptions;
|
|
431
|
+
retry;
|
|
432
|
+
failures;
|
|
433
|
+
retries;
|
|
434
|
+
constructor(runner) {
|
|
435
|
+
super("runner");
|
|
436
|
+
this.cid = runner.cid;
|
|
437
|
+
this.capabilities = runner.capabilities;
|
|
438
|
+
this.sanitizedCapabilities = sanitizeCaps(runner.capabilities);
|
|
439
|
+
this.config = runner.config;
|
|
440
|
+
this.specs = runner.specs;
|
|
441
|
+
this.sessionId = runner.sessionId;
|
|
442
|
+
this.isMultiremote = runner.isMultiremote;
|
|
443
|
+
this.instanceOptions = runner.instanceOptions;
|
|
444
|
+
this.retry = runner.retry;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
// src/index.ts
|
|
449
|
+
var WDIOReporter = class extends import_node_events.EventEmitter {
|
|
450
|
+
constructor(options) {
|
|
451
|
+
super();
|
|
452
|
+
this.options = options;
|
|
453
|
+
if (this.options.outputDir) {
|
|
454
|
+
try {
|
|
455
|
+
import_node_fs.default.mkdirSync(this.options.outputDir, { recursive: true });
|
|
456
|
+
} catch (err) {
|
|
457
|
+
throw new Error(`Couldn't create output directory at "${this.options.outputDir}": ${err.stack}`);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
this.outputStream = (this.options.stdout || !this.options.logFile) && this.options.writeStream ? this.options.writeStream : import_node_fs.default.createWriteStream(this.options.logFile);
|
|
461
|
+
let currentTest;
|
|
462
|
+
const rootSuite = new SuiteStats({
|
|
463
|
+
title: "(root)",
|
|
464
|
+
fullTitle: "(root)",
|
|
465
|
+
file: ""
|
|
466
|
+
});
|
|
467
|
+
this.currentSuites.push(rootSuite);
|
|
468
|
+
this.on("client:beforeCommand", this.onBeforeCommand.bind(this));
|
|
469
|
+
this.on("client:afterCommand", this.onAfterCommand.bind(this));
|
|
470
|
+
this.on("client:beforeAssertion", this.onBeforeAssertion.bind(this));
|
|
471
|
+
this.on("client:afterAssertion", this.onAfterAssertion.bind(this));
|
|
472
|
+
this.on(
|
|
473
|
+
"runner:start",
|
|
474
|
+
/* istanbul ignore next */
|
|
475
|
+
(runner) => {
|
|
476
|
+
rootSuite.cid = runner.cid;
|
|
477
|
+
this.specs.push(...runner.specs);
|
|
478
|
+
this.runnerStat = new RunnerStats(runner);
|
|
479
|
+
this.onRunnerStart(this.runnerStat);
|
|
480
|
+
}
|
|
481
|
+
);
|
|
482
|
+
this.on(
|
|
483
|
+
"suite:start",
|
|
484
|
+
/* istanbul ignore next */
|
|
485
|
+
(params) => {
|
|
486
|
+
if (!params.file) {
|
|
487
|
+
params.file = !params.parent ? this.specs.shift() || "unknown spec file" : this.currentSpec;
|
|
488
|
+
this.currentSpec = params.file;
|
|
489
|
+
}
|
|
490
|
+
const suite = new SuiteStats(params);
|
|
491
|
+
const currentSuite = this.currentSuites[this.currentSuites.length - 1];
|
|
492
|
+
currentSuite.suites.push(suite);
|
|
493
|
+
this.currentSuites.push(suite);
|
|
494
|
+
this.suites[suite.uid] = suite;
|
|
495
|
+
this.onSuiteStart(suite);
|
|
496
|
+
}
|
|
497
|
+
);
|
|
498
|
+
this.on(
|
|
499
|
+
"hook:start",
|
|
500
|
+
/* istanbul ignore next */
|
|
501
|
+
(hook) => {
|
|
502
|
+
const hookStats = new HookStats(hook);
|
|
503
|
+
const currentSuite = this.currentSuites[this.currentSuites.length - 1];
|
|
504
|
+
currentSuite.hooks.push(hookStats);
|
|
505
|
+
currentSuite.hooksAndTests.push(hookStats);
|
|
506
|
+
this.hooks[hook.uid] = hookStats;
|
|
507
|
+
this.onHookStart(hookStats);
|
|
508
|
+
}
|
|
509
|
+
);
|
|
510
|
+
this.on(
|
|
511
|
+
"hook:end",
|
|
512
|
+
/* istanbul ignore next */
|
|
513
|
+
(hook) => {
|
|
514
|
+
const hookStats = this.hooks[hook.uid];
|
|
515
|
+
hookStats.complete(getErrorsFromEvent(hook));
|
|
516
|
+
this.counts.hooks++;
|
|
517
|
+
this.onHookEnd(hookStats);
|
|
518
|
+
}
|
|
519
|
+
);
|
|
520
|
+
this.on(
|
|
521
|
+
"test:start",
|
|
522
|
+
/* istanbul ignore next */
|
|
523
|
+
(test) => {
|
|
524
|
+
test.retries = this.retries;
|
|
525
|
+
currentTest = new TestStats(test);
|
|
526
|
+
const currentSuite = this.currentSuites[this.currentSuites.length - 1];
|
|
527
|
+
currentSuite.tests.push(currentTest);
|
|
528
|
+
currentSuite.hooksAndTests.push(currentTest);
|
|
529
|
+
this.tests[test.uid] = currentTest;
|
|
530
|
+
this.onTestStart(currentTest);
|
|
531
|
+
}
|
|
532
|
+
);
|
|
533
|
+
this.on(
|
|
534
|
+
"test:pass",
|
|
535
|
+
/* istanbul ignore next */
|
|
536
|
+
(test) => {
|
|
537
|
+
const testStat = this.tests[test.uid];
|
|
538
|
+
testStat.pass();
|
|
539
|
+
this.counts.passes++;
|
|
540
|
+
this.counts.tests++;
|
|
541
|
+
this.onTestPass(testStat);
|
|
542
|
+
}
|
|
543
|
+
);
|
|
544
|
+
this.on("test:skip", (test) => {
|
|
545
|
+
const testStat = this.tests[test.uid];
|
|
546
|
+
currentTest.skip(test.pendingReason);
|
|
547
|
+
this.counts.skipping++;
|
|
548
|
+
this.counts.tests++;
|
|
549
|
+
this.onTestSkip(testStat);
|
|
550
|
+
});
|
|
551
|
+
this.on(
|
|
552
|
+
"test:fail",
|
|
553
|
+
/* istanbul ignore next */
|
|
554
|
+
(test) => {
|
|
555
|
+
const testStat = this.tests[test.uid];
|
|
556
|
+
testStat.fail(getErrorsFromEvent(test));
|
|
557
|
+
this.counts.failures++;
|
|
558
|
+
this.counts.tests++;
|
|
559
|
+
this.onTestFail(testStat);
|
|
560
|
+
}
|
|
561
|
+
);
|
|
562
|
+
this.on("test:retry", (test) => {
|
|
563
|
+
const testStat = this.tests[test.uid];
|
|
564
|
+
testStat.fail(getErrorsFromEvent(test));
|
|
565
|
+
this.onTestRetry(testStat);
|
|
566
|
+
this.retries++;
|
|
567
|
+
});
|
|
568
|
+
this.on("test:pending", (test) => {
|
|
569
|
+
test.retries = this.retries;
|
|
570
|
+
const currentSuite = this.currentSuites[this.currentSuites.length - 1];
|
|
571
|
+
currentTest = new TestStats(test);
|
|
572
|
+
if (test.uid in this.tests && this.tests[test.uid].state !== "pending") {
|
|
573
|
+
currentTest.uid = test.uid in this.tests ? "skipped-" + this.counts.skipping : currentTest.uid;
|
|
574
|
+
}
|
|
575
|
+
const suiteTests = currentSuite.tests;
|
|
576
|
+
if (!suiteTests.length || currentTest.uid !== suiteTests[suiteTests.length - 1].uid) {
|
|
577
|
+
currentSuite.tests.push(currentTest);
|
|
578
|
+
currentSuite.hooksAndTests.push(currentTest);
|
|
579
|
+
} else {
|
|
580
|
+
suiteTests[suiteTests.length - 1] = currentTest;
|
|
581
|
+
currentSuite.hooksAndTests[currentSuite.hooksAndTests.length - 1] = currentTest;
|
|
582
|
+
}
|
|
583
|
+
this.tests[currentTest.uid] = currentTest;
|
|
584
|
+
currentTest.skip(test.pendingReason);
|
|
585
|
+
this.counts.skipping++;
|
|
586
|
+
this.counts.tests++;
|
|
587
|
+
this.onTestSkip(currentTest);
|
|
588
|
+
});
|
|
589
|
+
this.on(
|
|
590
|
+
"test:end",
|
|
591
|
+
/* istanbul ignore next */
|
|
592
|
+
(test) => {
|
|
593
|
+
const testStat = this.tests[test.uid];
|
|
594
|
+
this.retries = 0;
|
|
595
|
+
this.onTestEnd(testStat);
|
|
596
|
+
}
|
|
597
|
+
);
|
|
598
|
+
this.on(
|
|
599
|
+
"suite:end",
|
|
600
|
+
/* istanbul ignore next */
|
|
601
|
+
(suite) => {
|
|
602
|
+
const suiteStat = this.suites[suite.uid];
|
|
603
|
+
suiteStat.complete();
|
|
604
|
+
this.currentSuites.pop();
|
|
605
|
+
this.onSuiteEnd(suiteStat);
|
|
606
|
+
}
|
|
607
|
+
);
|
|
608
|
+
this.on(
|
|
609
|
+
"runner:end",
|
|
610
|
+
/* istanbul ignore next */
|
|
611
|
+
(runner) => {
|
|
612
|
+
rootSuite.complete();
|
|
613
|
+
if (this.runnerStat) {
|
|
614
|
+
this.runnerStat.failures = runner.failures;
|
|
615
|
+
this.runnerStat.retries = runner.retries;
|
|
616
|
+
this.runnerStat.complete();
|
|
617
|
+
this.onRunnerEnd(this.runnerStat);
|
|
618
|
+
}
|
|
619
|
+
const logFile = this.options.logFile;
|
|
620
|
+
if (!this.isContentPresent && logFile && import_node_fs.default.existsSync(logFile)) {
|
|
621
|
+
import_node_fs.default.unlinkSync(logFile);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
);
|
|
625
|
+
this.on(
|
|
626
|
+
"client:beforeCommand",
|
|
627
|
+
/* istanbul ignore next */
|
|
628
|
+
(payload) => {
|
|
629
|
+
if (!currentTest) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
currentTest.output.push(Object.assign(payload, { type: "command" }));
|
|
633
|
+
}
|
|
634
|
+
);
|
|
635
|
+
this.on(
|
|
636
|
+
"client:afterCommand",
|
|
637
|
+
/* istanbul ignore next */
|
|
638
|
+
(payload) => {
|
|
639
|
+
if (!currentTest) {
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
currentTest.output.push(Object.assign(payload, { type: "result" }));
|
|
643
|
+
}
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
outputStream;
|
|
647
|
+
failures = 0;
|
|
648
|
+
suites = {};
|
|
649
|
+
hooks = {};
|
|
650
|
+
tests = {};
|
|
651
|
+
currentSuites = [];
|
|
652
|
+
counts = {
|
|
653
|
+
suites: 0,
|
|
654
|
+
tests: 0,
|
|
655
|
+
hooks: 0,
|
|
656
|
+
passes: 0,
|
|
657
|
+
skipping: 0,
|
|
658
|
+
failures: 0
|
|
659
|
+
};
|
|
660
|
+
retries = 0;
|
|
661
|
+
runnerStat;
|
|
662
|
+
isContentPresent = false;
|
|
663
|
+
specs = [];
|
|
664
|
+
currentSpec;
|
|
665
|
+
/**
|
|
666
|
+
* allows reporter to stale process shutdown process until required sync work
|
|
667
|
+
* is done (e.g. when having to send data to some server or any other async work)
|
|
668
|
+
*/
|
|
669
|
+
get isSynchronised() {
|
|
670
|
+
return true;
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* function to write to reporters output stream
|
|
674
|
+
*/
|
|
675
|
+
write(content) {
|
|
676
|
+
if (content) {
|
|
677
|
+
this.isContentPresent = true;
|
|
678
|
+
}
|
|
679
|
+
this.outputStream.write(content);
|
|
680
|
+
}
|
|
681
|
+
/* istanbul ignore next */
|
|
682
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
683
|
+
onRunnerStart(runnerStats) {
|
|
684
|
+
}
|
|
685
|
+
/* istanbul ignore next */
|
|
686
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
687
|
+
onBeforeCommand(commandArgs) {
|
|
688
|
+
}
|
|
689
|
+
/* istanbul ignore next */
|
|
690
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
691
|
+
onAfterCommand(commandArgs) {
|
|
692
|
+
}
|
|
693
|
+
/* istanbul ignore next */
|
|
694
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
695
|
+
onBeforeAssertion(assertionArgs) {
|
|
696
|
+
}
|
|
697
|
+
/* istanbul ignore next */
|
|
698
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
699
|
+
onAfterAssertion(assertionArgs) {
|
|
700
|
+
}
|
|
701
|
+
/* istanbul ignore next */
|
|
702
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
703
|
+
onSuiteStart(suiteStats) {
|
|
704
|
+
}
|
|
705
|
+
/* istanbul ignore next */
|
|
706
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
707
|
+
onHookStart(hookStat) {
|
|
708
|
+
}
|
|
709
|
+
/* istanbul ignore next */
|
|
710
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
711
|
+
onHookEnd(hookStats) {
|
|
712
|
+
}
|
|
713
|
+
/* istanbul ignore next */
|
|
714
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
715
|
+
onTestStart(testStats) {
|
|
716
|
+
}
|
|
717
|
+
/* istanbul ignore next */
|
|
718
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
719
|
+
onTestPass(testStats) {
|
|
720
|
+
}
|
|
721
|
+
/* istanbul ignore next */
|
|
722
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
723
|
+
onTestFail(testStats) {
|
|
724
|
+
}
|
|
725
|
+
/* istanbul ignore next */
|
|
726
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
727
|
+
onTestRetry(testStats) {
|
|
728
|
+
}
|
|
729
|
+
/* istanbul ignore next */
|
|
730
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
731
|
+
onTestSkip(testStats) {
|
|
732
|
+
}
|
|
733
|
+
/* istanbul ignore next */
|
|
734
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
735
|
+
onTestEnd(testStats) {
|
|
736
|
+
}
|
|
737
|
+
/* istanbul ignore next */
|
|
738
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
739
|
+
onSuiteEnd(suiteStats) {
|
|
740
|
+
}
|
|
741
|
+
/* istanbul ignore next */
|
|
742
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
743
|
+
onRunnerEnd(runnerStats) {
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
747
|
+
0 && (module.exports = {
|
|
748
|
+
HookStats,
|
|
749
|
+
RunnerStats,
|
|
750
|
+
SuiteStats,
|
|
751
|
+
TestStats
|
|
752
|
+
});
|