@clipboard-health/playwright-toolkit 1.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/README.md +221 -0
- package/package.json +39 -0
- package/src/index.d.ts +7 -0
- package/src/index.js +11 -0
- package/src/index.js.map +1 -0
- package/src/lib/adminAuthToken.d.ts +56 -0
- package/src/lib/adminAuthToken.js +369 -0
- package/src/lib/adminAuthToken.js.map +1 -0
- package/src/lib/cognitoDiagnostics.d.ts +41 -0
- package/src/lib/cognitoDiagnostics.js +331 -0
- package/src/lib/cognitoDiagnostics.js.map +1 -0
- package/src/lib/deployedAssets.d.ts +77 -0
- package/src/lib/deployedAssets.js +348 -0
- package/src/lib/deployedAssets.js.map +1 -0
- package/src/lib/mailpit.d.ts +86 -0
- package/src/lib/mailpit.js +252 -0
- package/src/lib/mailpit.js.map +1 -0
- package/src/lib/retry.d.ts +66 -0
- package/src/lib/retry.js +262 -0
- package/src/lib/retry.js.map +1 -0
- package/src/lib/setupRetry.d.ts +29 -0
- package/src/lib/setupRetry.js +55 -0
- package/src/lib/setupRetry.js.map +1 -0
- package/src/lib/traceparent.d.ts +31 -0
- package/src/lib/traceparent.js +66 -0
- package/src/lib/traceparent.js.map +1 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.classifySetupRetry = classifySetupRetry;
|
|
4
|
+
exports.isRetryableHttpStatus = isRetryableHttpStatus;
|
|
5
|
+
exports.getHttpErrorStatus = getHttpErrorStatus;
|
|
6
|
+
const util_ts_1 = require("@clipboard-health/util-ts");
|
|
7
|
+
/**
|
|
8
|
+
* Classifies setup failures without conflating identity collisions and
|
|
9
|
+
* transient infrastructure errors.
|
|
10
|
+
*
|
|
11
|
+
* Collision retries must regenerate a fresh identity. Transient retries must
|
|
12
|
+
* repeat the same identity so they do not change the scenario under test.
|
|
13
|
+
*/
|
|
14
|
+
function classifySetupRetry(params) {
|
|
15
|
+
const context = {
|
|
16
|
+
error: params.error,
|
|
17
|
+
status: getHttpErrorStatus({ error: params.error }),
|
|
18
|
+
};
|
|
19
|
+
if (params.isIdentityCollision?.(context) === true) {
|
|
20
|
+
return {
|
|
21
|
+
classification: "identity-collision",
|
|
22
|
+
retryDecision: "regenerate-identity",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (isRetryableHttpStatus({ status: context.status }) ||
|
|
26
|
+
params.isTransientError?.(context) === true) {
|
|
27
|
+
return {
|
|
28
|
+
classification: "transient",
|
|
29
|
+
retryDecision: "retry-same-identity",
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
classification: "deterministic",
|
|
34
|
+
retryDecision: "do-not-retry",
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function isRetryableHttpStatus(params) {
|
|
38
|
+
return (params.status === 408 ||
|
|
39
|
+
params.status === 429 ||
|
|
40
|
+
(typeof params.status === "number" && params.status >= 500 && params.status <= 599));
|
|
41
|
+
}
|
|
42
|
+
function getHttpErrorStatus(params) {
|
|
43
|
+
if (!(0, util_ts_1.isRecord)(params.error)) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
if (typeof params.error["status"] === "number") {
|
|
47
|
+
return params.error["status"];
|
|
48
|
+
}
|
|
49
|
+
const response = params.error["response"];
|
|
50
|
+
if ((0, util_ts_1.isRecord)(response) && typeof response["status"] === "number") {
|
|
51
|
+
return response["status"];
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=setupRetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupRetry.js","sourceRoot":"","sources":["../../../../../packages/playwright-toolkit/src/lib/setupRetry.ts"],"names":[],"mappings":";;;;;AAAA,uDAAqD;AAqBrD;;;;;;GAMG;AACH,4BAAmC,MAAgC;IACjE,MAAM,OAAO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IAAI,IAAA,kBAAQ,EAAC,QAAQ,CAAC,IAAI,OAAO,QAAQ,CAAC,QAAQ,CAAC,KAAK,QAAQ,EAAE,CAAC;QACjE,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from "@playwright/test";
|
|
2
|
+
export interface TraceparentFixtures {
|
|
3
|
+
traceparent: string;
|
|
4
|
+
}
|
|
5
|
+
export interface TraceparentContextLike {
|
|
6
|
+
setExtraHTTPHeaders(headers: Record<string, string>): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface TraceparentTestInfoLike {
|
|
9
|
+
annotations: Array<{
|
|
10
|
+
type: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
export interface CreateTraceparentParams {
|
|
15
|
+
randomBytesImplementation?: (byteCount: number) => Uint8Array;
|
|
16
|
+
}
|
|
17
|
+
export interface InstallTraceparentForTestParams {
|
|
18
|
+
context: TraceparentContextLike;
|
|
19
|
+
testInfo: TraceparentTestInfoLike;
|
|
20
|
+
traceparent?: string;
|
|
21
|
+
existingHeaders?: Record<string, string> | undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates an auto fixture that installs one W3C traceparent per Playwright
|
|
25
|
+
* test and records it as a test annotation for reporter/APM correlation.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createTraceparentFixtures(params?: CreateTraceparentParams): Fixtures<TraceparentFixtures, Record<never, never>, PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
|
|
28
|
+
export declare function createTraceparent(params?: CreateTraceparentParams): string;
|
|
29
|
+
export declare function installTraceparentForTest(params: InstallTraceparentForTestParams): Promise<{
|
|
30
|
+
traceparent: string;
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTraceparentFixtures = createTraceparentFixtures;
|
|
4
|
+
exports.createTraceparent = createTraceparent;
|
|
5
|
+
exports.installTraceparentForTest = installTraceparentForTest;
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
const INVALID_TRACE_ID = "00000000000000000000000000000000";
|
|
8
|
+
const INVALID_PARENT_ID = "0000000000000000";
|
|
9
|
+
/**
|
|
10
|
+
* Creates an auto fixture that installs one W3C traceparent per Playwright
|
|
11
|
+
* test and records it as a test annotation for reporter/APM correlation.
|
|
12
|
+
*/
|
|
13
|
+
function createTraceparentFixtures(params = {}) {
|
|
14
|
+
return {
|
|
15
|
+
traceparent: [
|
|
16
|
+
async ({ context, extraHTTPHeaders }, use, testInfo) => {
|
|
17
|
+
const result = await installTraceparentForTest({
|
|
18
|
+
context,
|
|
19
|
+
existingHeaders: extraHTTPHeaders,
|
|
20
|
+
testInfo,
|
|
21
|
+
traceparent: createTraceparent(params),
|
|
22
|
+
});
|
|
23
|
+
await use(result.traceparent);
|
|
24
|
+
},
|
|
25
|
+
{ auto: true },
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function createTraceparent(params = {}) {
|
|
30
|
+
const randomBytesImplementation = params.randomBytesImplementation ?? node_crypto_1.randomBytes;
|
|
31
|
+
const traceId = createNonZeroHex({
|
|
32
|
+
byteCount: 16,
|
|
33
|
+
invalidValue: INVALID_TRACE_ID,
|
|
34
|
+
randomBytesImplementation,
|
|
35
|
+
});
|
|
36
|
+
const parentId = createNonZeroHex({
|
|
37
|
+
byteCount: 8,
|
|
38
|
+
invalidValue: INVALID_PARENT_ID,
|
|
39
|
+
randomBytesImplementation,
|
|
40
|
+
});
|
|
41
|
+
return `00-${traceId}-${parentId}-01`;
|
|
42
|
+
}
|
|
43
|
+
async function installTraceparentForTest(params) {
|
|
44
|
+
const traceparent = params.traceparent ?? createTraceparent();
|
|
45
|
+
await params.context.setExtraHTTPHeaders({
|
|
46
|
+
...params.existingHeaders,
|
|
47
|
+
traceparent,
|
|
48
|
+
});
|
|
49
|
+
params.testInfo.annotations.push({
|
|
50
|
+
type: "traceparent",
|
|
51
|
+
description: traceparent,
|
|
52
|
+
});
|
|
53
|
+
return { traceparent };
|
|
54
|
+
}
|
|
55
|
+
function createNonZeroHex(params) {
|
|
56
|
+
for (;;) {
|
|
57
|
+
const value = Buffer.from(params.randomBytesImplementation(params.byteCount)).toString("hex");
|
|
58
|
+
if (value.length !== params.byteCount * 2) {
|
|
59
|
+
throw new Error(`Random byte source returned ${value.length / 2} bytes`);
|
|
60
|
+
}
|
|
61
|
+
if (value !== params.invalidValue) {
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=traceparent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traceparent.js","sourceRoot":"","sources":["../../../../../packages/playwright-toolkit/src/lib/traceparent.ts"],"names":[],"mappings":";;;;;AAAA,6CAA0C;AAU1C,MAAM,gBAAgB,GAAG,kCAAkC,CAAC;AAC5D,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAyB7C;;;GAGG;AACH,mCACE,MAAM,GAA4B,EAAE;IAOpC,OAAO;QACL,WAAW,EAAE;YACX,KAAK,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE;gBACrD,MAAM,MAAM,GAAG,MAAM,yBAAyB,CAAC;oBAC7C,OAAO;oBACP,eAAe,EAAE,gBAAgB;oBACjC,QAAQ;oBACR,WAAW,EAAE,iBAAiB,CAAC,MAAM,CAAC;iBACvC,CAAC,CAAC;gBAEH,MAAM,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YA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