@piwitests/reporter 0.66.0 → 0.67.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/dist/global-setup-module.js +100 -14
- package/dist/index.d.ts +45 -21
- package/dist/index.js +2261 -1892
- package/dist/internal/capture/capture-fixtures.d.ts +14 -1
- package/dist/internal/capture/capture-fixtures.js +350 -211
- package/package.json +1 -1
|
@@ -220,6 +220,7 @@ var PIWI_ENV_KEYS = {
|
|
|
220
220
|
};
|
|
221
221
|
var PIWI_DESKTOP_CONFIG_ENV = "PIWI_DESKTOP_CONFIG";
|
|
222
222
|
var PIWI_SHARD_ENV = "PIWI_SHARD";
|
|
223
|
+
var PIWI_RUN_LOG_ENV = "PIWI_RUN_LOG";
|
|
223
224
|
function readBool(val) {
|
|
224
225
|
if (val === void 0) return void 0;
|
|
225
226
|
return ["true", "1", "yes", "on"].includes(val.trim().toLowerCase());
|
|
@@ -446,6 +447,7 @@ var HttpClient = class {
|
|
|
446
447
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
447
448
|
/** Set by `close`: every later request fails with this reason. */
|
|
448
449
|
this.closedReason = null;
|
|
450
|
+
this.loginAnnounced = false;
|
|
449
451
|
this.warnIfInsecureTransport();
|
|
450
452
|
}
|
|
451
453
|
/**
|
|
@@ -494,7 +496,9 @@ var HttpClient = class {
|
|
|
494
496
|
async resolveAuth(options) {
|
|
495
497
|
if (options.apiKey) return options.apiKey;
|
|
496
498
|
if (options.username && options.password) {
|
|
497
|
-
this.logger.
|
|
499
|
+
if (this.loginAnnounced) this.logger.debug(`Authenticating as ${options.username} again...`);
|
|
500
|
+
else this.logger.info(`Authenticating as ${options.username}...`);
|
|
501
|
+
this.loginAnnounced = true;
|
|
498
502
|
return this.login(options.username, options.password);
|
|
499
503
|
}
|
|
500
504
|
return null;
|
|
@@ -881,6 +885,16 @@ function privateTempDir() {
|
|
|
881
885
|
}
|
|
882
886
|
var NO_FOLLOW = fs3.constants.O_NOFOLLOW ?? 0;
|
|
883
887
|
var NO_WAIT = fs3.constants.O_NONBLOCK ?? 0;
|
|
888
|
+
function untrustedReason(stat) {
|
|
889
|
+
if (stat.isSymbolicLink()) return "it is a symbolic link";
|
|
890
|
+
if (!stat.isFile()) return "it is not a regular file";
|
|
891
|
+
if (typeof process.getuid === "function") {
|
|
892
|
+
if (stat.uid !== process.getuid()) return "another user owns it";
|
|
893
|
+
if (stat.mode & 18) return "other users may write to it";
|
|
894
|
+
if (stat.nlink > 1) return "it has another name";
|
|
895
|
+
}
|
|
896
|
+
return null;
|
|
897
|
+
}
|
|
884
898
|
function writePrivateFile(file, text) {
|
|
885
899
|
const temp = `${file}.${process.pid}.${crypto2.randomBytes(6).toString("hex")}.tmp`;
|
|
886
900
|
try {
|
|
@@ -891,6 +905,20 @@ function writePrivateFile(file, text) {
|
|
|
891
905
|
throw error;
|
|
892
906
|
}
|
|
893
907
|
}
|
|
908
|
+
function readPrivateFile(file) {
|
|
909
|
+
const found = fs3.lstatSync(file, { throwIfNoEntry: false });
|
|
910
|
+
if (!found) return null;
|
|
911
|
+
const reason = untrustedReason(found);
|
|
912
|
+
if (reason) return { untrusted: reason };
|
|
913
|
+
const fd = fs3.openSync(file, fs3.constants.O_RDONLY | NO_FOLLOW | NO_WAIT);
|
|
914
|
+
try {
|
|
915
|
+
const opened = untrustedReason(fs3.fstatSync(fd));
|
|
916
|
+
if (opened) return { untrusted: opened };
|
|
917
|
+
return { text: fs3.readFileSync(fd, "utf8") };
|
|
918
|
+
} finally {
|
|
919
|
+
fs3.closeSync(fd);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
894
922
|
|
|
895
923
|
// src/internal/support/setup-file.ts
|
|
896
924
|
var logger = new Logger();
|
|
@@ -900,6 +928,13 @@ function getSetupFilePath(projectName, pid = process.pid) {
|
|
|
900
928
|
function writeSetupInfo(info) {
|
|
901
929
|
writePrivateFile(getSetupFilePath(info.projectName), JSON.stringify(info));
|
|
902
930
|
}
|
|
931
|
+
function writeSetupFailure(projectName, failed) {
|
|
932
|
+
const failure = { projectName, failed };
|
|
933
|
+
try {
|
|
934
|
+
writePrivateFile(getSetupFilePath(projectName), JSON.stringify(failure));
|
|
935
|
+
} catch {
|
|
936
|
+
}
|
|
937
|
+
}
|
|
903
938
|
|
|
904
939
|
// src/internal/support/aria-sampling.ts
|
|
905
940
|
var path6 = __toESM(require("path"));
|
|
@@ -1163,8 +1198,8 @@ var MAX_MANIFEST_BYTES = 4 * 1024 * 1024;
|
|
|
1163
1198
|
function instrumentationManifestUrls(baseUrl) {
|
|
1164
1199
|
const base = new URL(baseUrl);
|
|
1165
1200
|
const root = new URL(INSTRUMENTATION_MANIFEST_PATH, base).toString();
|
|
1166
|
-
const
|
|
1167
|
-
return
|
|
1201
|
+
const path12 = base.pathname.replace(/\/+$/, "");
|
|
1202
|
+
return path12 ? [new URL(`${path12}${INSTRUMENTATION_MANIFEST_PATH}`, base).toString(), root] : [root];
|
|
1168
1203
|
}
|
|
1169
1204
|
async function fetchInstrumentationManifest(baseUrl, fetchImpl = fetch) {
|
|
1170
1205
|
try {
|
|
@@ -1260,7 +1295,42 @@ function getReporterVersion() {
|
|
|
1260
1295
|
return cachedVersion;
|
|
1261
1296
|
}
|
|
1262
1297
|
|
|
1298
|
+
// src/internal/support/run-log.ts
|
|
1299
|
+
var import_node_crypto = require("crypto");
|
|
1300
|
+
var fs9 = __toESM(require("fs"));
|
|
1301
|
+
var path11 = __toESM(require("path"));
|
|
1302
|
+
var READ_MS = 1e3;
|
|
1303
|
+
function relayRunLog(print, env = process.env) {
|
|
1304
|
+
const file = path11.join(privateTempDir(), `piwi-run-log-${(0, import_node_crypto.randomBytes)(12).toString("hex")}.txt`);
|
|
1305
|
+
writePrivateFile(file, "");
|
|
1306
|
+
env[PIWI_RUN_LOG_ENV] = file;
|
|
1307
|
+
let printed = 0;
|
|
1308
|
+
const flush = () => {
|
|
1309
|
+
let text;
|
|
1310
|
+
try {
|
|
1311
|
+
const found = readPrivateFile(file);
|
|
1312
|
+
if (!found || !("text" in found)) return;
|
|
1313
|
+
text = found.text;
|
|
1314
|
+
} catch {
|
|
1315
|
+
return;
|
|
1316
|
+
}
|
|
1317
|
+
const end = text.lastIndexOf("\n") + 1;
|
|
1318
|
+
if (end <= printed) return;
|
|
1319
|
+
const lines = text.slice(printed, end).split("\n");
|
|
1320
|
+
printed = end;
|
|
1321
|
+
for (const line of lines) if (line) print(line);
|
|
1322
|
+
};
|
|
1323
|
+
const timer = setInterval(flush, READ_MS);
|
|
1324
|
+
timer.unref();
|
|
1325
|
+
return () => {
|
|
1326
|
+
clearInterval(timer);
|
|
1327
|
+
flush();
|
|
1328
|
+
fs9.rmSync(file, { force: true });
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1263
1332
|
// src/public/global-setup.ts
|
|
1333
|
+
var relaying = false;
|
|
1264
1334
|
function createGlobalSetup(options, userSetup) {
|
|
1265
1335
|
return async function globalSetupFn(config) {
|
|
1266
1336
|
const configDir = configDirFromConfig(config);
|
|
@@ -1305,9 +1375,14 @@ function createGlobalSetup(options, userSetup) {
|
|
|
1305
1375
|
return;
|
|
1306
1376
|
}
|
|
1307
1377
|
const httpClient = new HttpClient(opts.serverUrl, logger2);
|
|
1378
|
+
const registers = opts.streaming !== false;
|
|
1379
|
+
let registered = false;
|
|
1308
1380
|
try {
|
|
1309
1381
|
const auth = await httpClient.resolveAuth(opts);
|
|
1310
|
-
if (
|
|
1382
|
+
if (registers) {
|
|
1383
|
+
await registerRun(httpClient, auth, opts, config, logger2);
|
|
1384
|
+
registered = true;
|
|
1385
|
+
}
|
|
1311
1386
|
if (opts.projectName) clearAriaSampleFile(opts.projectName);
|
|
1312
1387
|
const wantsAria = opts.sampleAriaOnPass !== false && !!opts.projectName;
|
|
1313
1388
|
const committedManifest = opts.uploadManifest !== false ? readCommittedManifest(configDirFromConfig(config)) : null;
|
|
@@ -1346,6 +1421,7 @@ function createGlobalSetup(options, userSetup) {
|
|
|
1346
1421
|
}
|
|
1347
1422
|
} catch (error) {
|
|
1348
1423
|
logger2.warn(`Could not register global setup: ${errorMessage(error)}`);
|
|
1424
|
+
if (registers && !registered && opts.projectName) writeSetupFailure(opts.projectName, errorMessage(error));
|
|
1349
1425
|
}
|
|
1350
1426
|
if (userSetup) return userSetup(config);
|
|
1351
1427
|
};
|
|
@@ -1373,16 +1449,26 @@ async function registerRun(httpClient, auth, opts, config, logger2) {
|
|
|
1373
1449
|
},
|
|
1374
1450
|
auth
|
|
1375
1451
|
);
|
|
1376
|
-
if (response?.runId
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1452
|
+
if (!response?.runId || !response?.setupToken) {
|
|
1453
|
+
throw new Error("the answer to /api/test-runs/setup names no run");
|
|
1454
|
+
}
|
|
1455
|
+
const liveViewKey = response.liveView?.key;
|
|
1456
|
+
writeSetupInfo({
|
|
1457
|
+
runId: response.runId,
|
|
1458
|
+
setupToken: response.setupToken,
|
|
1459
|
+
projectName: opts.projectName,
|
|
1460
|
+
...isLiveViewKey(liveViewKey) ? { liveViewKey } : {},
|
|
1461
|
+
...response.liveView?.refused === "local" ? { liveViewLocal: true } : {}
|
|
1462
|
+
});
|
|
1463
|
+
logger2.debug(`Global setup: initializing run #${response.runId}`);
|
|
1464
|
+
if (isLiveViewKey(liveViewKey) && detectCi(process.env) && !relaying) {
|
|
1465
|
+
try {
|
|
1466
|
+
const stopRelay = relayRunLog((line) => logger2.info(line));
|
|
1467
|
+
relaying = true;
|
|
1468
|
+
process.once("exit", stopRelay);
|
|
1469
|
+
} catch (error) {
|
|
1470
|
+
logger2.debug(`Global setup: the live view's lines go to no file (${errorMessage(error)})`);
|
|
1471
|
+
}
|
|
1386
1472
|
}
|
|
1387
1473
|
}
|
|
1388
1474
|
|
package/dist/index.d.ts
CHANGED
|
@@ -256,16 +256,20 @@ interface PiwiDashboardOptions {
|
|
|
256
256
|
* `trace` options on the top-level `use` block so a failing test keeps a
|
|
257
257
|
* screenshot (`'only-on-failure'`) and a trace (`'retain-on-failure'`) even
|
|
258
258
|
* without the capture fixtures — the trace alone unlocks the DOM snapshot,
|
|
259
|
-
* full call stack, full network with bodies and the visual diff.
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
259
|
+
* full call stack, full network with bodies and the visual diff. The trace
|
|
260
|
+
* records DOM snapshots, not ARIA snapshots. To record those too (Playwright
|
|
261
|
+
* 1.63+), for the in-execution page diff and the accessibility tree at the
|
|
262
|
+
* failing action, set the trace yourself: `use: { trace: { mode: 'retain-on-failure',
|
|
263
|
+
* snapshots: { dom: true, aria: true } } }`. They cost run time on every
|
|
264
|
+
* attempt, passing ones included: Playwright waits for up to three ARIA
|
|
265
|
+
* snapshots per input action, each hundreds of milliseconds on a large page
|
|
266
|
+
* (ten clicks on a 1,000-row table took 8,967 ms with them against 1,021 ms
|
|
267
|
+
* without, on Playwright 1.64.1 and Chromium). Add `screen: true` for a PNG
|
|
268
|
+
* per action, the trace's biggest storage cost. Only fills options the config
|
|
269
|
+
* leaves unset; an explicit value (including `'off'`) and per-project `use`
|
|
270
|
+
* blocks are never touched. Defaults to `true`. Set to `false` (or
|
|
271
|
+
* `PIWI_DEFAULT_CAPTURE=false`) to opt out and let Playwright's own defaults
|
|
272
|
+
* stand.
|
|
269
273
|
*/
|
|
270
274
|
defaultCapture?: boolean;
|
|
271
275
|
/**
|
|
@@ -488,8 +492,8 @@ declare function createGlobalSetup(options?: PiwiDashboardOptions, userSetup?: (
|
|
|
488
492
|
*
|
|
489
493
|
* The top-level `use` block's `screenshot` and `trace` are defaulted to
|
|
490
494
|
* `'only-on-failure'` / `'retain-on-failure'` when unset so failure evidence is
|
|
491
|
-
* captured without the fixtures;
|
|
492
|
-
*
|
|
495
|
+
* captured without the fixtures; the trace records DOM snapshots, not ARIA
|
|
496
|
+
* snapshots (set `trace` yourself to record them, see `defaultCapture`). An
|
|
493
497
|
* explicit value (including `'off'`) is kept. Opt out with `defaultCapture:
|
|
494
498
|
* false` (or `PIWI_DEFAULT_CAPTURE=false`).
|
|
495
499
|
*
|
|
@@ -529,8 +533,13 @@ declare class PiwiDashboardReporter {
|
|
|
529
533
|
private plannedTests;
|
|
530
534
|
/** Ids of tests that actually reported via `onTestEnd`, to find the ones that never ran. */
|
|
531
535
|
private reportedTestIds;
|
|
532
|
-
/**
|
|
536
|
+
/**
|
|
537
|
+
* The spec files said to have run without the capture fixtures in a run that can stop, or whose workers stream to
|
|
538
|
+
* the instance's live view (`noteUncaptured`).
|
|
539
|
+
*/
|
|
533
540
|
private uncapturedSpecs;
|
|
541
|
+
/** Whether the run is a CI run whose workers stream to the instance's live view, set in `onBegin`. */
|
|
542
|
+
private liveViewOn;
|
|
534
543
|
/** The live steps begun and not ended, by step, sent again when someone opens the run (`onWatched`). */
|
|
535
544
|
private openSteps;
|
|
536
545
|
/**
|
|
@@ -559,6 +568,8 @@ declare class PiwiDashboardReporter {
|
|
|
559
568
|
* finalizing a run would create an empty phantom run and upload an empty report.
|
|
560
569
|
*/
|
|
561
570
|
private readonly listMode;
|
|
571
|
+
/** True under `playwright merge-reports`, which replays blob reports: no test runs and nothing of the run is live. */
|
|
572
|
+
private readonly mergingReports;
|
|
562
573
|
/** True when the server URL and API key came from the desktop app, not from config. */
|
|
563
574
|
private viaDesktopApp;
|
|
564
575
|
/** The configured server `desktopApp: 'prefer'` set aside for the desktop app, if any. */
|
|
@@ -627,9 +638,12 @@ declare class PiwiDashboardReporter {
|
|
|
627
638
|
* environment: the key the instance gave the global setup, for a project that turned its live view on, for this run
|
|
628
639
|
* alone. A CI run's workers stream with it at once; a run outside CI's hold it until a person shares the run (Share
|
|
629
640
|
* live), and such a run without a key names why instead, for the surfaces that would share it; a CI run without one
|
|
630
|
-
* says why in its log (`ciLiveViewNote`). Read before the stream starts, which takes the setup file.
|
|
641
|
+
* says why in its log (`ciLiveViewNote`). Read before the stream starts, which takes the setup file. A run that
|
|
642
|
+
* merges blob reports starts no worker and is not live: it says nothing of the live view.
|
|
631
643
|
*/
|
|
632
644
|
private shareLiveView;
|
|
645
|
+
/** Why the run holds no live view key, from what its global setup left (`setup`, its registration, if any). */
|
|
646
|
+
private liveViewMissing;
|
|
633
647
|
/**
|
|
634
648
|
* Settle each planned test's external ID before any test runs, name the IDs two tests share, and record them on
|
|
635
649
|
* the run so the dashboard lists them too.
|
|
@@ -655,21 +669,31 @@ declare class PiwiDashboardReporter {
|
|
|
655
669
|
/** Step categories streamed live while the run executes. */
|
|
656
670
|
private static readonly LIVE_STEP_CATEGORIES;
|
|
657
671
|
/**
|
|
658
|
-
* Whether a step streams live: its category is in `LIVE_STEP_CATEGORIES
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
672
|
+
* Whether a step streams live: its category is in `LIVE_STEP_CATEGORIES`,
|
|
673
|
+
* no ancestor is an `expect` step, and neither it nor an ancestor is Piwi's
|
|
674
|
+
* own (`isCaptureStep`: its fixtures, its attachments, its page reads). The
|
|
675
|
+
* steps inside an assertion are its polling — every `expect.poll` attempt and
|
|
676
|
+
* `toPass` retry — not a step a human watches; the meaningful readout is the
|
|
677
|
+
* assertion around them.
|
|
662
678
|
*/
|
|
663
679
|
private static isLiveStep;
|
|
680
|
+
/** Whether a step is Piwi's own, by core's rule for a stored step. */
|
|
681
|
+
private static isOwnStep;
|
|
664
682
|
/**
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
683
|
+
* Say of the first spec file whose test made Playwright calls without the capture fixtures what it misses in this
|
|
684
|
+
* run, which nothing else says: in a run that can stop (breakpoints, or a run channel to an editor or the desktop
|
|
685
|
+
* app, where the stops happen), its tests never stop at a breakpoint nor at Pause; in a CI run whose workers stream
|
|
686
|
+
* to the instance's live view, nobody can watch them. The others are named in one line as the run ends
|
|
668
687
|
* (`noteOtherUncaptured`).
|
|
669
688
|
*/
|
|
670
689
|
private noteUncaptured;
|
|
671
690
|
/** The spec files past the first that ran without the capture fixtures, in one line (`noteUncaptured`). */
|
|
672
691
|
private noteOtherUncaptured;
|
|
692
|
+
/**
|
|
693
|
+
* What a spec file that runs without the capture fixtures misses in this run, said of one file and of several: the
|
|
694
|
+
* live view only for a test with a page (`page`).
|
|
695
|
+
*/
|
|
696
|
+
private uncapturedCosts;
|
|
673
697
|
/** Playwright reporter hook: called when a step (including hook/fixture) begins */
|
|
674
698
|
onStepBegin(test: TestCase | undefined, _result: TestResult | undefined, step: any): void;
|
|
675
699
|
/** Playwright reporter hook: called when a step (including hook/fixture) ends */
|