@plune-ai/playwright 0.2.1 → 0.2.2
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/index.cjs +57 -13
- package/dist/index.js +57 -13
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -36,12 +36,13 @@ module.exports = __toCommonJS(src_exports);
|
|
|
36
36
|
var import_node_fs = require("fs");
|
|
37
37
|
|
|
38
38
|
// ../../dist/reporter-core.js
|
|
39
|
+
var import_crypto = require("crypto");
|
|
39
40
|
var import_fs = require("fs");
|
|
40
41
|
var import_os = require("os");
|
|
41
42
|
var import_path = require("path");
|
|
42
43
|
var fs = __toESM(require("fs"), 1);
|
|
43
44
|
var path = __toESM(require("path"), 1);
|
|
44
|
-
var
|
|
45
|
+
var import_crypto2 = require("crypto");
|
|
45
46
|
var DEFAULT_API_URL = "https://beta-api.plune.ai";
|
|
46
47
|
function resolveApiUrl(explicit) {
|
|
47
48
|
const raw = explicit ?? process.env["PLUNE_API_URL"] ?? DEFAULT_API_URL;
|
|
@@ -87,7 +88,7 @@ function createClient(opts) {
|
|
|
87
88
|
const wait = opts.wait ?? sleep;
|
|
88
89
|
const base = opts.apiUrl.replace(/\/+$/, "");
|
|
89
90
|
const scrub = (text) => opts.token === "" ? text : text.split(opts.token).join("***");
|
|
90
|
-
async function
|
|
91
|
+
async function send(method, path2, body) {
|
|
91
92
|
let last = {
|
|
92
93
|
kind: "unavailable",
|
|
93
94
|
status: null,
|
|
@@ -97,16 +98,22 @@ function createClient(opts) {
|
|
|
97
98
|
let res;
|
|
98
99
|
try {
|
|
99
100
|
res = await doFetch(`${base}${path2}`, {
|
|
100
|
-
method
|
|
101
|
+
method,
|
|
101
102
|
headers: { "content-type": "application/json", authorization: `Bearer ${opts.token}` },
|
|
102
|
-
|
|
103
|
+
// A DELETE carries none. Sending `"undefined"` as a body is what a naive
|
|
104
|
+
// `JSON.stringify(body)` would do, and some proxies answer that with a 400 nobody can
|
|
105
|
+
// explain.
|
|
106
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
103
107
|
});
|
|
104
108
|
} catch (err) {
|
|
105
109
|
last = { kind: "unavailable", status: null, detail: scrub(String(err)) };
|
|
106
110
|
if (attempt < RETRY_DELAYS_MS.length) await wait(RETRY_DELAYS_MS[attempt]);
|
|
107
111
|
continue;
|
|
108
112
|
}
|
|
109
|
-
if (res.ok)
|
|
113
|
+
if (res.ok) {
|
|
114
|
+
if (res.status === 204) return { ok: true, status: res.status, body: void 0 };
|
|
115
|
+
return { ok: true, status: res.status, body: await res.json() };
|
|
116
|
+
}
|
|
110
117
|
const detail = scrub(await detailOf(res));
|
|
111
118
|
const kind = classify(res.status);
|
|
112
119
|
last = { kind, status: res.status, detail };
|
|
@@ -117,7 +124,10 @@ function createClient(opts) {
|
|
|
117
124
|
}
|
|
118
125
|
return { ok: false, ...last };
|
|
119
126
|
}
|
|
120
|
-
return {
|
|
127
|
+
return {
|
|
128
|
+
post: (path2, body) => send("POST", path2, body),
|
|
129
|
+
del: (path2) => send("DELETE", path2)
|
|
130
|
+
};
|
|
121
131
|
}
|
|
122
132
|
var UNSUPPORTED_VARS = ["PLUNE_GROUP"];
|
|
123
133
|
function value(env, name) {
|
|
@@ -188,6 +198,18 @@ var BATCH_MAX = 500;
|
|
|
188
198
|
var DISCOVER_MAX = 500;
|
|
189
199
|
var BATCH_DEFAULT = 100;
|
|
190
200
|
var EXPECTED_MAX = 1e4;
|
|
201
|
+
var KEY_MAX = 1024;
|
|
202
|
+
var TITLE_MAX = 300;
|
|
203
|
+
function boundKey(key) {
|
|
204
|
+
if (key.value.length <= KEY_MAX) return key;
|
|
205
|
+
const digest = (0, import_crypto.createHash)("sha256").update(key.value).digest("hex").slice(0, 16);
|
|
206
|
+
let head = key.value.slice(0, KEY_MAX - digest.length - 1);
|
|
207
|
+
if (/[\uD800-\uDBFF]$/.test(head)) head = head.slice(0, -1);
|
|
208
|
+
return { ...key, value: `${head}#${digest}` };
|
|
209
|
+
}
|
|
210
|
+
function boundTitle(title) {
|
|
211
|
+
return title.length <= TITLE_MAX ? title : `${title.slice(0, TITLE_MAX - 1)}\u2026`;
|
|
212
|
+
}
|
|
191
213
|
function chunk(items, size) {
|
|
192
214
|
const out = [];
|
|
193
215
|
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
@@ -201,7 +223,7 @@ function warnIfDropped(sent, run, log) {
|
|
|
201
223
|
`plune: this deployment stored none of ${names.join(", ")} \u2014 it is older than the fields. The run is otherwise reported in full.`
|
|
202
224
|
);
|
|
203
225
|
}
|
|
204
|
-
async function startRun(passed,
|
|
226
|
+
async function startRun(passed, declared) {
|
|
205
227
|
const env = readEnv();
|
|
206
228
|
const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
|
|
207
229
|
const cfg = { ...env.config, ...stated };
|
|
@@ -224,6 +246,7 @@ async function startRun(passed, expected) {
|
|
|
224
246
|
rejected: 0,
|
|
225
247
|
unresolved: 0,
|
|
226
248
|
offered: 0,
|
|
249
|
+
created: 0,
|
|
227
250
|
unoffered: 0,
|
|
228
251
|
deferred: 0
|
|
229
252
|
};
|
|
@@ -234,6 +257,22 @@ async function startRun(passed, expected) {
|
|
|
234
257
|
let joined = false;
|
|
235
258
|
let offline = token === "";
|
|
236
259
|
let done = false;
|
|
260
|
+
const shortened = /* @__PURE__ */ new Set();
|
|
261
|
+
function bound(keys) {
|
|
262
|
+
return keys.map((key) => {
|
|
263
|
+
const fit = boundKey(key);
|
|
264
|
+
if (fit !== key && !shortened.has(key.value)) {
|
|
265
|
+
shortened.add(key.value);
|
|
266
|
+
if (shortened.size === 1) {
|
|
267
|
+
log(
|
|
268
|
+
`plune: a test name longer than ${KEY_MAX} characters was shortened to fit its key \u2014 "${key.value.slice(0, 80)}\u2026". Give the test a shorter name; until then this is its identity.`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return fit;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
const expected = declared?.map(bound);
|
|
237
276
|
if (offline) {
|
|
238
277
|
log('plune: no API token \u2014 run "plune login" first. Results will be written to the fallback file.');
|
|
239
278
|
}
|
|
@@ -261,9 +300,9 @@ async function startRun(passed, expected) {
|
|
|
261
300
|
}
|
|
262
301
|
if (!offline) {
|
|
263
302
|
if (expected !== void 0) await resolveKeys(expected.flat());
|
|
264
|
-
const
|
|
265
|
-
const configuration =
|
|
266
|
-
expected:
|
|
303
|
+
const stated2 = expected?.slice(0, EXPECTED_MAX) ?? [];
|
|
304
|
+
const configuration = stated2.length === 0 ? void 0 : {
|
|
305
|
+
expected: stated2.flatMap((keys) => {
|
|
267
306
|
const hit = keys.map((k) => resolved.get(k.value)).find((v) => typeof v === "string");
|
|
268
307
|
if (typeof hit === "string") return [{ testCaseId: hit }];
|
|
269
308
|
return keys[0] === void 0 ? [] : [{ externalKey: keys[0] }];
|
|
@@ -307,9 +346,11 @@ async function startRun(passed, expected) {
|
|
|
307
346
|
if (!offerDiscovered) return;
|
|
308
347
|
if (result.title === void 0 || result.specRef === void 0) return;
|
|
309
348
|
if (result.keys.length === 0) return;
|
|
349
|
+
const title = boundTitle(result.title);
|
|
350
|
+
if (title !== result.title) shortened.add(result.title);
|
|
310
351
|
discoveries.set(result.keys[0].value, {
|
|
311
352
|
keys: result.keys,
|
|
312
|
-
title
|
|
353
|
+
title,
|
|
313
354
|
source: result.source,
|
|
314
355
|
specRef: result.specRef,
|
|
315
356
|
rawStatus: result.rawStatus
|
|
@@ -331,6 +372,7 @@ async function startRun(passed, expected) {
|
|
|
331
372
|
return;
|
|
332
373
|
}
|
|
333
374
|
stats.offered += out.body.results.filter((r) => r.outcome === "queued").length;
|
|
375
|
+
stats.created += out.body.results.filter((r) => r.outcome === "created").length;
|
|
334
376
|
}
|
|
335
377
|
}
|
|
336
378
|
async function flush() {
|
|
@@ -396,7 +438,9 @@ async function startRun(passed, expected) {
|
|
|
396
438
|
if (stats.rejected > 0) parts.push(`${stats.rejected} rejected`);
|
|
397
439
|
if (stats.unresolved > 0) parts.push(`${stats.unresolved} with no matching test case`);
|
|
398
440
|
if (stats.offered > 0) parts.push(`${stats.offered} offered for review`);
|
|
441
|
+
if (stats.created > 0) parts.push(`${stats.created} added as cases (trusted source)`);
|
|
399
442
|
if (stats.deferred > 0) parts.push(`${stats.deferred} written to ${fallbackPath}`);
|
|
443
|
+
if (shortened.size > 0) parts.push(`${shortened.size} test name(s) shortened to fit a key`);
|
|
400
444
|
log(`plune: ${parts.join(" \xB7 ")}`);
|
|
401
445
|
}
|
|
402
446
|
return {
|
|
@@ -410,7 +454,7 @@ async function startRun(passed, expected) {
|
|
|
410
454
|
return stats;
|
|
411
455
|
},
|
|
412
456
|
async add(result) {
|
|
413
|
-
buffer.push(result);
|
|
457
|
+
buffer.push({ ...result, keys: bound(result.keys) });
|
|
414
458
|
if (buffer.length >= batchSize) await flush();
|
|
415
459
|
},
|
|
416
460
|
flush,
|
|
@@ -441,7 +485,7 @@ async function startRun(passed, expected) {
|
|
|
441
485
|
};
|
|
442
486
|
}
|
|
443
487
|
function sha256(input) {
|
|
444
|
-
return (0,
|
|
488
|
+
return (0, import_crypto2.createHash)("sha256").update(input, "utf8").digest("hex");
|
|
445
489
|
}
|
|
446
490
|
var RESULT_KEY_MAX = 200;
|
|
447
491
|
var HASH_CHARS = 32;
|
package/dist/index.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
import { readFileSync as readFileSync2 } from "fs";
|
|
3
3
|
|
|
4
4
|
// ../../dist/reporter-core.js
|
|
5
|
+
import { createHash } from "crypto";
|
|
5
6
|
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
6
7
|
import { homedir } from "os";
|
|
7
8
|
import { dirname, join } from "path";
|
|
8
9
|
import * as fs from "fs";
|
|
9
10
|
import * as path from "path";
|
|
10
|
-
import { createHash } from "crypto";
|
|
11
|
+
import { createHash as createHash2 } from "crypto";
|
|
11
12
|
var DEFAULT_API_URL = "https://beta-api.plune.ai";
|
|
12
13
|
function resolveApiUrl(explicit) {
|
|
13
14
|
const raw = explicit ?? process.env["PLUNE_API_URL"] ?? DEFAULT_API_URL;
|
|
@@ -53,7 +54,7 @@ function createClient(opts) {
|
|
|
53
54
|
const wait = opts.wait ?? sleep;
|
|
54
55
|
const base = opts.apiUrl.replace(/\/+$/, "");
|
|
55
56
|
const scrub = (text) => opts.token === "" ? text : text.split(opts.token).join("***");
|
|
56
|
-
async function
|
|
57
|
+
async function send(method, path2, body) {
|
|
57
58
|
let last = {
|
|
58
59
|
kind: "unavailable",
|
|
59
60
|
status: null,
|
|
@@ -63,16 +64,22 @@ function createClient(opts) {
|
|
|
63
64
|
let res;
|
|
64
65
|
try {
|
|
65
66
|
res = await doFetch(`${base}${path2}`, {
|
|
66
|
-
method
|
|
67
|
+
method,
|
|
67
68
|
headers: { "content-type": "application/json", authorization: `Bearer ${opts.token}` },
|
|
68
|
-
|
|
69
|
+
// A DELETE carries none. Sending `"undefined"` as a body is what a naive
|
|
70
|
+
// `JSON.stringify(body)` would do, and some proxies answer that with a 400 nobody can
|
|
71
|
+
// explain.
|
|
72
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
69
73
|
});
|
|
70
74
|
} catch (err) {
|
|
71
75
|
last = { kind: "unavailable", status: null, detail: scrub(String(err)) };
|
|
72
76
|
if (attempt < RETRY_DELAYS_MS.length) await wait(RETRY_DELAYS_MS[attempt]);
|
|
73
77
|
continue;
|
|
74
78
|
}
|
|
75
|
-
if (res.ok)
|
|
79
|
+
if (res.ok) {
|
|
80
|
+
if (res.status === 204) return { ok: true, status: res.status, body: void 0 };
|
|
81
|
+
return { ok: true, status: res.status, body: await res.json() };
|
|
82
|
+
}
|
|
76
83
|
const detail = scrub(await detailOf(res));
|
|
77
84
|
const kind = classify(res.status);
|
|
78
85
|
last = { kind, status: res.status, detail };
|
|
@@ -83,7 +90,10 @@ function createClient(opts) {
|
|
|
83
90
|
}
|
|
84
91
|
return { ok: false, ...last };
|
|
85
92
|
}
|
|
86
|
-
return {
|
|
93
|
+
return {
|
|
94
|
+
post: (path2, body) => send("POST", path2, body),
|
|
95
|
+
del: (path2) => send("DELETE", path2)
|
|
96
|
+
};
|
|
87
97
|
}
|
|
88
98
|
var UNSUPPORTED_VARS = ["PLUNE_GROUP"];
|
|
89
99
|
function value(env, name) {
|
|
@@ -154,6 +164,18 @@ var BATCH_MAX = 500;
|
|
|
154
164
|
var DISCOVER_MAX = 500;
|
|
155
165
|
var BATCH_DEFAULT = 100;
|
|
156
166
|
var EXPECTED_MAX = 1e4;
|
|
167
|
+
var KEY_MAX = 1024;
|
|
168
|
+
var TITLE_MAX = 300;
|
|
169
|
+
function boundKey(key) {
|
|
170
|
+
if (key.value.length <= KEY_MAX) return key;
|
|
171
|
+
const digest = createHash("sha256").update(key.value).digest("hex").slice(0, 16);
|
|
172
|
+
let head = key.value.slice(0, KEY_MAX - digest.length - 1);
|
|
173
|
+
if (/[\uD800-\uDBFF]$/.test(head)) head = head.slice(0, -1);
|
|
174
|
+
return { ...key, value: `${head}#${digest}` };
|
|
175
|
+
}
|
|
176
|
+
function boundTitle(title) {
|
|
177
|
+
return title.length <= TITLE_MAX ? title : `${title.slice(0, TITLE_MAX - 1)}\u2026`;
|
|
178
|
+
}
|
|
157
179
|
function chunk(items, size) {
|
|
158
180
|
const out = [];
|
|
159
181
|
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
@@ -167,7 +189,7 @@ function warnIfDropped(sent, run, log) {
|
|
|
167
189
|
`plune: this deployment stored none of ${names.join(", ")} \u2014 it is older than the fields. The run is otherwise reported in full.`
|
|
168
190
|
);
|
|
169
191
|
}
|
|
170
|
-
async function startRun(passed,
|
|
192
|
+
async function startRun(passed, declared) {
|
|
171
193
|
const env = readEnv();
|
|
172
194
|
const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
|
|
173
195
|
const cfg = { ...env.config, ...stated };
|
|
@@ -190,6 +212,7 @@ async function startRun(passed, expected) {
|
|
|
190
212
|
rejected: 0,
|
|
191
213
|
unresolved: 0,
|
|
192
214
|
offered: 0,
|
|
215
|
+
created: 0,
|
|
193
216
|
unoffered: 0,
|
|
194
217
|
deferred: 0
|
|
195
218
|
};
|
|
@@ -200,6 +223,22 @@ async function startRun(passed, expected) {
|
|
|
200
223
|
let joined = false;
|
|
201
224
|
let offline = token === "";
|
|
202
225
|
let done = false;
|
|
226
|
+
const shortened = /* @__PURE__ */ new Set();
|
|
227
|
+
function bound(keys) {
|
|
228
|
+
return keys.map((key) => {
|
|
229
|
+
const fit = boundKey(key);
|
|
230
|
+
if (fit !== key && !shortened.has(key.value)) {
|
|
231
|
+
shortened.add(key.value);
|
|
232
|
+
if (shortened.size === 1) {
|
|
233
|
+
log(
|
|
234
|
+
`plune: a test name longer than ${KEY_MAX} characters was shortened to fit its key \u2014 "${key.value.slice(0, 80)}\u2026". Give the test a shorter name; until then this is its identity.`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return fit;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
const expected = declared?.map(bound);
|
|
203
242
|
if (offline) {
|
|
204
243
|
log('plune: no API token \u2014 run "plune login" first. Results will be written to the fallback file.');
|
|
205
244
|
}
|
|
@@ -227,9 +266,9 @@ async function startRun(passed, expected) {
|
|
|
227
266
|
}
|
|
228
267
|
if (!offline) {
|
|
229
268
|
if (expected !== void 0) await resolveKeys(expected.flat());
|
|
230
|
-
const
|
|
231
|
-
const configuration =
|
|
232
|
-
expected:
|
|
269
|
+
const stated2 = expected?.slice(0, EXPECTED_MAX) ?? [];
|
|
270
|
+
const configuration = stated2.length === 0 ? void 0 : {
|
|
271
|
+
expected: stated2.flatMap((keys) => {
|
|
233
272
|
const hit = keys.map((k) => resolved.get(k.value)).find((v) => typeof v === "string");
|
|
234
273
|
if (typeof hit === "string") return [{ testCaseId: hit }];
|
|
235
274
|
return keys[0] === void 0 ? [] : [{ externalKey: keys[0] }];
|
|
@@ -273,9 +312,11 @@ async function startRun(passed, expected) {
|
|
|
273
312
|
if (!offerDiscovered) return;
|
|
274
313
|
if (result.title === void 0 || result.specRef === void 0) return;
|
|
275
314
|
if (result.keys.length === 0) return;
|
|
315
|
+
const title = boundTitle(result.title);
|
|
316
|
+
if (title !== result.title) shortened.add(result.title);
|
|
276
317
|
discoveries.set(result.keys[0].value, {
|
|
277
318
|
keys: result.keys,
|
|
278
|
-
title
|
|
319
|
+
title,
|
|
279
320
|
source: result.source,
|
|
280
321
|
specRef: result.specRef,
|
|
281
322
|
rawStatus: result.rawStatus
|
|
@@ -297,6 +338,7 @@ async function startRun(passed, expected) {
|
|
|
297
338
|
return;
|
|
298
339
|
}
|
|
299
340
|
stats.offered += out.body.results.filter((r) => r.outcome === "queued").length;
|
|
341
|
+
stats.created += out.body.results.filter((r) => r.outcome === "created").length;
|
|
300
342
|
}
|
|
301
343
|
}
|
|
302
344
|
async function flush() {
|
|
@@ -362,7 +404,9 @@ async function startRun(passed, expected) {
|
|
|
362
404
|
if (stats.rejected > 0) parts.push(`${stats.rejected} rejected`);
|
|
363
405
|
if (stats.unresolved > 0) parts.push(`${stats.unresolved} with no matching test case`);
|
|
364
406
|
if (stats.offered > 0) parts.push(`${stats.offered} offered for review`);
|
|
407
|
+
if (stats.created > 0) parts.push(`${stats.created} added as cases (trusted source)`);
|
|
365
408
|
if (stats.deferred > 0) parts.push(`${stats.deferred} written to ${fallbackPath}`);
|
|
409
|
+
if (shortened.size > 0) parts.push(`${shortened.size} test name(s) shortened to fit a key`);
|
|
366
410
|
log(`plune: ${parts.join(" \xB7 ")}`);
|
|
367
411
|
}
|
|
368
412
|
return {
|
|
@@ -376,7 +420,7 @@ async function startRun(passed, expected) {
|
|
|
376
420
|
return stats;
|
|
377
421
|
},
|
|
378
422
|
async add(result) {
|
|
379
|
-
buffer.push(result);
|
|
423
|
+
buffer.push({ ...result, keys: bound(result.keys) });
|
|
380
424
|
if (buffer.length >= batchSize) await flush();
|
|
381
425
|
},
|
|
382
426
|
flush,
|
|
@@ -407,7 +451,7 @@ async function startRun(passed, expected) {
|
|
|
407
451
|
};
|
|
408
452
|
}
|
|
409
453
|
function sha256(input) {
|
|
410
|
-
return
|
|
454
|
+
return createHash2("sha256").update(input, "utf8").digest("hex");
|
|
411
455
|
}
|
|
412
456
|
var RESULT_KEY_MAX = 200;
|
|
413
457
|
var HASH_CHARS = 32;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plune-ai/playwright",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Report Playwright results to Plune — a reporter and, later, a test importer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"playwright",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"tsup": "^8.0.0",
|
|
39
39
|
"typescript": "^5.4.0",
|
|
40
40
|
"vitest": "^1.6.0",
|
|
41
|
-
"@plune-ai/cli": "0.
|
|
41
|
+
"@plune-ai/cli": "0.10.0"
|
|
42
42
|
},
|
|
43
43
|
"repository": {
|
|
44
44
|
"type": "git",
|