@enhance-eng/sdk 0.1.0-dev.sha-3f7dd0acb078 → 0.1.158
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 +112 -18
- package/dist/browser/kernel.iife.js +4598 -3208
- package/dist/capture-client.client--zU5zvd3.d.mts +78 -0
- package/dist/capture-client.client-YvUy2nGh.mjs +525 -0
- package/dist/capture-context.lib-BivWcwWc.mjs +40 -0
- package/dist/client.d.mts +2 -0
- package/dist/client.mjs +2 -0
- package/dist/environment.config-B2WQJWaS.mjs +34 -0
- package/dist/environment.config-Dx5WHap5.d.mts +12 -0
- package/dist/index-7uzK6oto.d.mts +656 -0
- package/dist/index.d.mts +9 -36
- package/dist/index.mjs +3 -3
- package/dist/package-VWmCi21a.mjs +4 -0
- package/dist/playwright/index.d.mts +7 -1
- package/dist/playwright/index.mjs +613 -6175
- package/dist/playwright/reporter.d.mts +4 -5
- package/dist/playwright/reporter.mjs +99 -31
- package/dist/stall-watch.lib-C6VmIsz-.mjs +8474 -0
- package/package.json +17 -6
- package/dist/capture-client.client-BDphetFj.mjs +0 -226
- package/dist/capture-files.lib-BA_KBz9W.mjs +0 -406
- package/dist/capture-files.lib-CvX7Ca8M.d.mts +0 -11
- package/dist/environment.config-BgNT6S_H.mjs +0 -14
- package/dist/index-PIb9iIwo.d.mts +0 -257
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { p as CaptureRunDescriptor } from "../index-7uzK6oto.mjs";
|
|
2
|
+
import { t as BeginCaptureRun } from "../capture-client.client--zU5zvd3.mjs";
|
|
3
|
+
import { n as CaptureConnectionOptions } from "../environment.config-Dx5WHap5.mjs";
|
|
2
4
|
import { Reporter } from "@playwright/test/reporter";
|
|
3
5
|
//#region src/playwright/capture-reporter.lib.d.ts
|
|
4
|
-
interface EnhanceReporterOptions {
|
|
5
|
-
readonly canvas: string;
|
|
6
|
+
interface EnhanceReporterOptions extends CaptureConnectionOptions, Omit<BeginCaptureRun, 'runKey'> {
|
|
6
7
|
readonly source?: string;
|
|
7
|
-
readonly apiUrl?: string;
|
|
8
|
-
readonly token?: string;
|
|
9
8
|
readonly runKey?: string;
|
|
10
9
|
readonly directory?: string;
|
|
11
10
|
readonly run?: CaptureRunDescriptor;
|
|
@@ -1,50 +1,101 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as createEnhance } from "../
|
|
3
|
-
import {
|
|
1
|
+
import { B as captureLeftOutSchema, C as isCaptureError, D as fitCaptureNames, O as leftOutCapture, P as CAPTURE_LEFT_OUT_REASONS, d as captureDiagnostics, g as writeCaptureJson, z as captureArtifactSchema } from "../stall-watch.lib-C6VmIsz-.mjs";
|
|
2
|
+
import { t as createEnhance } from "../environment.config-B2WQJWaS.mjs";
|
|
3
|
+
import { i as setCaptureDirectory } from "../capture-context.lib-BivWcwWc.mjs";
|
|
4
|
+
import process from "node:process";
|
|
4
5
|
import { mkdir, readFile } from "node:fs/promises";
|
|
5
6
|
import nodePath from "node:path";
|
|
6
|
-
import process from "node:process";
|
|
7
7
|
//#region src/playwright/capture-reporter.lib.ts
|
|
8
8
|
const errorOf = (error) => error instanceof Error ? error : /* @__PURE__ */ new Error("Enhance reporter could not complete the capture run.");
|
|
9
9
|
const initialize = async (session) => {
|
|
10
10
|
const current = session;
|
|
11
11
|
await mkdir(session.directory, { recursive: true });
|
|
12
12
|
try {
|
|
13
|
-
current.client = createEnhance(
|
|
14
|
-
apiUrl: session.options.apiUrl ?? captureEnvironment().apiUrl,
|
|
15
|
-
token: session.options.token ?? captureEnvironment().token
|
|
16
|
-
});
|
|
13
|
+
current.client = createEnhance(session.options);
|
|
17
14
|
if (session.options.run === void 0) current.run = (await current.client.captures.begin({
|
|
18
|
-
|
|
15
|
+
...session.options,
|
|
19
16
|
...session.options.source !== void 0 && { source: session.options.source },
|
|
20
17
|
runKey: session.options.runKey ?? globalThis.crypto.randomUUID(),
|
|
21
|
-
participants:
|
|
18
|
+
participants: session.participants,
|
|
22
19
|
directory: session.directory
|
|
23
20
|
})).descriptor;
|
|
24
21
|
else current.run = session.options.run;
|
|
25
|
-
if (!current.run.participants.includes(session.participant) || current.run.canvasId !== session.options.canvas) throw new Error("Enhance participant or canvas differs from the reserved run.");
|
|
22
|
+
if (!current.run.participants.includes(session.participant) || session.options.canvas !== void 0 && current.run.canvasId !== session.options.canvas) throw new Error("Enhance participant or canvas differs from the reserved run.");
|
|
26
23
|
await writeCaptureJson(nodePath.join(session.directory, "ready.json"), current.run);
|
|
27
24
|
} catch (error) {
|
|
28
25
|
current.failure = errorOf(error);
|
|
29
26
|
await writeCaptureJson(nodePath.join(session.directory, "ready.json"), { failed: true });
|
|
30
27
|
}
|
|
31
28
|
};
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
const attachmentText = async (attachment) => {
|
|
30
|
+
try {
|
|
31
|
+
return (attachment.body ?? await readFile(attachment.path ?? "")).toString("utf8");
|
|
32
|
+
} catch (error) {
|
|
33
|
+
captureDiagnostics.publish({
|
|
34
|
+
stage: "attachment-read",
|
|
35
|
+
error
|
|
36
|
+
});
|
|
37
|
+
return null;
|
|
40
38
|
}
|
|
39
|
+
};
|
|
40
|
+
const parsedJson = (text) => {
|
|
41
|
+
try {
|
|
42
|
+
return { value: JSON.parse(text) };
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/** One capture, or the plain reason it was left out: its stored copy cannot be read or parsed. */
|
|
48
|
+
const readCapture = async (attachment, testId) => {
|
|
49
|
+
const text = await attachmentText(attachment);
|
|
50
|
+
if (text === null) return {
|
|
51
|
+
testId,
|
|
52
|
+
message: CAPTURE_LEFT_OUT_REASONS.unreadable
|
|
53
|
+
};
|
|
54
|
+
const json = parsedJson(text);
|
|
55
|
+
if (json === null) return {
|
|
56
|
+
testId,
|
|
57
|
+
message: CAPTURE_LEFT_OUT_REASONS.notACapture
|
|
58
|
+
};
|
|
59
|
+
const capture = fitCaptureNames(json.value);
|
|
60
|
+
const parsed = captureArtifactSchema.safeParse(capture);
|
|
61
|
+
if (parsed.success) return parsed.data;
|
|
62
|
+
captureDiagnostics.publish({
|
|
63
|
+
stage: "format-check",
|
|
64
|
+
issues: parsed.error.issues
|
|
65
|
+
});
|
|
66
|
+
return leftOutCapture(capture, testId, parsed.error.issues);
|
|
67
|
+
};
|
|
68
|
+
/** A capture the step itself left out, as it recorded it. */
|
|
69
|
+
const readLeftOut = async (attachment, testId) => {
|
|
70
|
+
const text = await attachmentText(attachment);
|
|
71
|
+
const parsed = captureLeftOutSchema.safeParse(text === null ? null : parsedJson(text)?.value);
|
|
72
|
+
return parsed.success ? {
|
|
73
|
+
...parsed.data,
|
|
74
|
+
testId
|
|
75
|
+
} : {
|
|
76
|
+
testId,
|
|
77
|
+
message: CAPTURE_LEFT_OUT_REASONS.unreadable
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const recordAttempt = async (session, test, result) => {
|
|
81
|
+
const captures = [];
|
|
82
|
+
for (const attachment of result.attachments) if (attachment.name === "enhance-capture") {
|
|
83
|
+
const read = await readCapture(attachment, test.id);
|
|
84
|
+
if ("format" in read) captures.push(read);
|
|
85
|
+
else session.leftOut.push(read);
|
|
86
|
+
} else if (attachment.name === "enhance-capture-left-out") session.leftOut.push(await readLeftOut(attachment, test.id));
|
|
41
87
|
const project = test.parent.project()?.name;
|
|
42
88
|
return {
|
|
43
|
-
participant,
|
|
89
|
+
participant: session.participant,
|
|
44
90
|
testId: test.id,
|
|
45
91
|
project: project === void 0 || project === "" ? "default" : project,
|
|
46
92
|
retry: result.retry,
|
|
47
93
|
status: result.status,
|
|
94
|
+
title: test.title,
|
|
95
|
+
location: {
|
|
96
|
+
file: nodePath.relative(session.rootDir, test.location.file),
|
|
97
|
+
line: test.location.line
|
|
98
|
+
},
|
|
48
99
|
captures
|
|
49
100
|
};
|
|
50
101
|
};
|
|
@@ -57,6 +108,7 @@ const finish = async (session, result, attempts) => {
|
|
|
57
108
|
run: session.run,
|
|
58
109
|
ordering: "partial",
|
|
59
110
|
attempts,
|
|
111
|
+
...session.leftOut.length > 0 && { leftOut: session.leftOut },
|
|
60
112
|
participants: [{
|
|
61
113
|
id: session.participant,
|
|
62
114
|
status: result.status === "passed" ? "passed" : result.status === "interrupted" ? "interrupted" : "failed"
|
|
@@ -64,11 +116,12 @@ const finish = async (session, result, attempts) => {
|
|
|
64
116
|
};
|
|
65
117
|
const manifestPath = nodePath.join(session.directory, "manifest.json");
|
|
66
118
|
await writeCaptureJson(manifestPath, manifest);
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
119
|
+
if (session.options.publish !== false && session.run.participants.length === 1) await session.client.captures.publishManifest(manifestPath, { write: (text) => process.stdout.write(text) });
|
|
120
|
+
else process.stdout.write(`Enhance captures: ${manifestPath}\n`);
|
|
121
|
+
};
|
|
122
|
+
const writeFailedReadiness = async (directory) => {
|
|
123
|
+
await mkdir(directory, { recursive: true });
|
|
124
|
+
await writeCaptureJson(nodePath.join(directory, "ready.json"), { failed: true });
|
|
72
125
|
};
|
|
73
126
|
const createCaptureReporter = (options) => {
|
|
74
127
|
const directory = nodePath.resolve(options.directory ?? nodePath.join(".enhance", "captures"), globalThis.crypto.randomUUID());
|
|
@@ -76,22 +129,33 @@ const createCaptureReporter = (options) => {
|
|
|
76
129
|
const session = {
|
|
77
130
|
directory,
|
|
78
131
|
participant: options.participant ?? "local",
|
|
132
|
+
participants: options.participants ?? [options.participant ?? "local"],
|
|
79
133
|
options,
|
|
80
134
|
run: null,
|
|
81
135
|
client: null,
|
|
82
|
-
failure: null
|
|
136
|
+
failure: null,
|
|
137
|
+
leftOut: [],
|
|
138
|
+
rootDir: process.cwd()
|
|
83
139
|
};
|
|
84
140
|
let ready = Promise.resolve();
|
|
85
141
|
const records = [];
|
|
86
142
|
return {
|
|
87
|
-
onBegin: () => {
|
|
143
|
+
onBegin: (config) => {
|
|
144
|
+
session.rootDir = config?.rootDir ?? session.rootDir;
|
|
145
|
+
const shard = config?.shard ?? null;
|
|
146
|
+
if (shard !== null && options.run === void 0 && options.participants === void 0) {
|
|
147
|
+
session.participant = `shard-${String(shard.current)}`;
|
|
148
|
+
session.participants = Array.from({ length: shard.total }, (_, index) => `shard-${String(index + 1)}`);
|
|
149
|
+
if (options.runKey === void 0) {
|
|
150
|
+
session.failure = /* @__PURE__ */ new Error("Sharded captures require one shared runKey for the execution.");
|
|
151
|
+
ready = writeFailedReadiness(directory);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
88
155
|
ready = initialize(session);
|
|
89
156
|
},
|
|
90
157
|
onTestEnd: (test, result) => {
|
|
91
|
-
records.push(recordAttempt(session
|
|
92
|
-
},
|
|
93
|
-
onError: (error) => {
|
|
94
|
-
session.failure = new Error(error.message ?? "The test runner failed.");
|
|
158
|
+
records.push(recordAttempt(session, test, result));
|
|
95
159
|
},
|
|
96
160
|
onEnd: async (result) => {
|
|
97
161
|
try {
|
|
@@ -99,6 +163,10 @@ const createCaptureReporter = (options) => {
|
|
|
99
163
|
await finish(session, result, await Promise.all(records));
|
|
100
164
|
return;
|
|
101
165
|
} catch (error) {
|
|
166
|
+
if (isCaptureError(error) && error.code === "pending") {
|
|
167
|
+
process.stdout.write(`Enhance: ${error.message}\n`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
102
170
|
process.stderr.write(`Enhance: ${errorOf(error).message}\nCapture files: ${directory}\n`);
|
|
103
171
|
return { status: "failed" };
|
|
104
172
|
}
|