@empiricalrun/playwright-utils 0.69.1 → 0.70.1
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/CHANGELOG.md +27 -0
- package/README.md +6 -3
- package/dist/api-worker-client.d.ts +3 -0
- package/dist/api-worker-client.d.ts.map +1 -1
- package/dist/api-worker-client.js +8 -0
- package/dist/email.d.ts +43 -0
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +47 -0
- package/dist/generated/api-worker-openapi.d.ts +673 -10
- package/dist/generated/api-worker-openapi.d.ts.map +1 -1
- package/dist/inbox-client.d.ts +6 -0
- package/dist/inbox-client.d.ts.map +1 -1
- package/dist/inbox-client.js +2 -0
- package/dist/reporter/incremental-blob-reporter.d.ts.map +1 -1
- package/dist/reporter/incremental-blob-reporter.js +4 -1
- package/dist/reporter/util.d.ts +1 -1
- package/dist/reporter/util.d.ts.map +1 -1
- package/dist/reporter/util.js +7 -7
- package/dist/test/index.d.ts +7 -2
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +11 -3
- package/dist/test/scoped-http-headers.d.ts +20 -0
- package/dist/test/scoped-http-headers.d.ts.map +1 -0
- package/dist/test/scoped-http-headers.js +177 -0
- package/dist/test/scoped-http-headers.spec.d.ts +2 -0
- package/dist/test/scoped-http-headers.spec.d.ts.map +1 -0
- package/dist/test/scoped-http-headers.spec.js +81 -0
- package/package.json +4 -4
- package/playwright.config.ts +5 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/docs/auth.md +0 -116
- package/docs/email.md +0 -97
- package/docs/fixtures.md +0 -81
- package/docs/kv.md +0 -90
- package/docs/video-labels.md +0 -36
package/dist/inbox-client.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ type Link = {
|
|
|
5
5
|
href?: string;
|
|
6
6
|
};
|
|
7
7
|
export type InboxEmail = {
|
|
8
|
+
/**
|
|
9
|
+
* The sender in the email's From header, e.g. `noreply@acme.com`. Falls back
|
|
10
|
+
* to the envelope sender when the email had no From header.
|
|
11
|
+
*/
|
|
12
|
+
from?: string;
|
|
13
|
+
messageId?: string;
|
|
8
14
|
subject?: string;
|
|
9
15
|
text?: string;
|
|
10
16
|
html?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inbox-client.d.ts","sourceRoot":"","sources":["../src/inbox-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EAGrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,KAAK,IAAI,GAAG;IACV,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAKF,KAAK,kBAAkB,GAAG;IACxB,SAAS,EAAE,eAAe,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAAa,WAAW;IACtB,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,OAAO,CAAS;IAExB,YAAY,IAAI,EAAE,kBAAkB,EAGnC;IAEK,YAAY,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,UAAU,CAAC,CAOrB;YAEa,cAAc;IAgD5B,OAAO,CAAC,YAAY;
|
|
1
|
+
{"version":3,"file":"inbox-client.d.ts","sourceRoot":"","sources":["../src/inbox-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EAGrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,KAAK,IAAI,GAAG;IACV,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAKF,KAAK,kBAAkB,GAAG;IACxB,SAAS,EAAE,eAAe,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAAa,WAAW;IACtB,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,OAAO,CAAS;IAExB,YAAY,IAAI,EAAE,kBAAkB,EAGnC;IAEK,YAAY,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,UAAU,CAAC,CAOrB;YAEa,cAAc;IAgD5B,OAAO,CAAC,YAAY;CAWrB"}
|
package/dist/inbox-client.js
CHANGED
|
@@ -55,6 +55,8 @@ class InboxClient {
|
|
|
55
55
|
}
|
|
56
56
|
parseMessage(message) {
|
|
57
57
|
return {
|
|
58
|
+
from: message.header_from_address || message.from_address || undefined,
|
|
59
|
+
messageId: message.message_id || undefined,
|
|
58
60
|
subject: message.subject || undefined,
|
|
59
61
|
text: message.text_body || undefined,
|
|
60
62
|
html: message.html_body || undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"incremental-blob-reporter.d.ts","sourceRoot":"","sources":["../../src/reporter/incremental-blob-reporter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,SAAS,EACT,UAAU,EACV,QAAQ,EACR,UAAU,EACX,MAAM,2BAA2B,CAAC;AA8BnC,MAAM,MAAM,gBAAgB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAOnD,cAAM,uBAAwB,YAAW,QAAQ;IAC/C,OAAO,CAAC,kBAAkB,CAAyB;IACnD,OAAO,CAAC,WAAW,CAIjB;IACF,OAAO,CAAC,UAAU,CAGhB;IACF,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,iBAAiB,CAA+B;IACxD,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,UAAU,CAAoC;IACtD,OAAO,CAAC,sBAAsB,CAAkC;IAChE,OAAO,CAAC,SAAS,CAAyB;IAC1C,OAAO,CAAC,iBAAiB,CAA0B;IACnD,OAAO,CAAC,mBAAmB,CAA0B;IACrD,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,YAAY,CAAsD;IAC1E,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,QAAQ,CAAyB;IAEzC,cAWC;IAED,OAAO,CAAC,cAAc,CAA6B;IAEnD,OAAO,CAAC,mBAAmB;IA4B3B,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,qBAAqB;YASf,uBAAuB;
|
|
1
|
+
{"version":3,"file":"incremental-blob-reporter.d.ts","sourceRoot":"","sources":["../../src/reporter/incremental-blob-reporter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,SAAS,EACT,UAAU,EACV,QAAQ,EACR,UAAU,EACX,MAAM,2BAA2B,CAAC;AA8BnC,MAAM,MAAM,gBAAgB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CA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lobReporter]"
|
|
98
|
+
: "[IncrementalBlobReporterFailure]";
|
|
99
|
+
console.warn(`${tag} No onBegin received, skipping upload (nothing to merge)`);
|
|
97
100
|
return;
|
|
98
101
|
}
|
|
99
102
|
if (this._uploader) {
|
package/dist/reporter/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type TestAttachmentMap } from "@empiricalrun/r2-uploader/html-report-utils";
|
|
2
2
|
import { TestCaseRunBeginEvent, TestCaseRunEndEventV2 } from "@empiricalrun/shared-types/playwright-utils";
|
|
3
3
|
import { JSONReport as PlaywrightJSONReport, TestCase } from "@playwright/test/reporter";
|
|
4
4
|
export declare function getPackageJsonPath(folderPath: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/reporter/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/reporter/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,iBAAiB,EAEvB,MAAM,6CAA6C,CAAC;AAKrD,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACL,UAAU,IAAI,oBAAoB,EAElC,QAAQ,EACT,MAAM,2BAA2B,CAAC;AA2BnC,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAqB7D;AAED,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GAAG,SAAS,UAQhC;AAED,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CA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
|
@@ -15,8 +15,8 @@ exports.updateHtmlZipFileAttachmentPaths = updateHtmlZipFileAttachmentPaths;
|
|
|
15
15
|
exports.buildTestAttachmentMapFromSummary = buildTestAttachmentMapFromSummary;
|
|
16
16
|
exports.checkFileExistsAsync = checkFileExistsAsync;
|
|
17
17
|
exports.updateSummaryJsonAttachmentPaths = updateSummaryJsonAttachmentPaths;
|
|
18
|
+
const html_report_utils_1 = require("@empiricalrun/r2-uploader/html-report-utils");
|
|
18
19
|
const zip_1 = require("@empiricalrun/r2-uploader/zip");
|
|
19
|
-
const reporter_1 = require("@empiricalrun/reporter");
|
|
20
20
|
const crypto_1 = __importDefault(require("crypto"));
|
|
21
21
|
const fs_1 = __importDefault(require("fs"));
|
|
22
22
|
const mime_1 = __importDefault(require("mime"));
|
|
@@ -195,7 +195,7 @@ async function updateHtmlZipFileAttachmentPaths(jsonFilePath, htmlFilePath, outp
|
|
|
195
195
|
// Support the global assignment, script tag, and Playwright 1.60 template tag.
|
|
196
196
|
// Old: window.playwrightReportBase64 = "data:application/zip;base64,..."
|
|
197
197
|
// Newer: <script|template id="playwrightReportBase64">data:application/zip;base64,...</script|template>
|
|
198
|
-
const base64 = (0,
|
|
198
|
+
const base64 = (0, html_report_utils_1.findPlaywrightReportBase64)(htmlFile);
|
|
199
199
|
if (!base64) {
|
|
200
200
|
console.error("❌ Base64 zip data not found in HTML.");
|
|
201
201
|
return;
|
|
@@ -215,14 +215,14 @@ async function updateHtmlZipFileAttachmentPaths(jsonFilePath, htmlFilePath, outp
|
|
|
215
215
|
try {
|
|
216
216
|
const reportPath = path_1.default.join(tempDir, "report.json");
|
|
217
217
|
const reportData = JSON.parse(await fs_1.default.promises.readFile(reportPath, "utf8"));
|
|
218
|
-
(0,
|
|
218
|
+
(0, html_report_utils_1.replaceMediaPaths)(reportData, testAttachmentMap);
|
|
219
219
|
await fs_1.default.promises.writeFile(reportPath, JSON.stringify(reportData, null, 2), "utf8");
|
|
220
220
|
const files = await fs_1.default.promises.readdir(tempDir);
|
|
221
221
|
for (const file of files.filter((f) => f.endsWith(".json") && f !== "report.json")) {
|
|
222
222
|
try {
|
|
223
223
|
const filePath = path_1.default.join(tempDir, file);
|
|
224
224
|
const jsonData = JSON.parse(await fs_1.default.promises.readFile(filePath, "utf8"));
|
|
225
|
-
(0,
|
|
225
|
+
(0, html_report_utils_1.replaceMediaPaths)(jsonData, testAttachmentMap);
|
|
226
226
|
await fs_1.default.promises.writeFile(filePath, JSON.stringify(jsonData, null, 2), "utf8");
|
|
227
227
|
}
|
|
228
228
|
catch (err) {
|
|
@@ -231,7 +231,7 @@ async function updateHtmlZipFileAttachmentPaths(jsonFilePath, htmlFilePath, outp
|
|
|
231
231
|
}
|
|
232
232
|
const newBuffer = await (0, zip_1.createZipFromDirectory)(tempDir);
|
|
233
233
|
const newBase64 = newBuffer.toString("base64");
|
|
234
|
-
const updatedHtml = (0,
|
|
234
|
+
const updatedHtml = (0, html_report_utils_1.replacePlaywrightReportBase64)(htmlFile, newBase64);
|
|
235
235
|
await fs_1.default.promises.writeFile(htmlFilePath, updatedHtml, "utf8");
|
|
236
236
|
logger_1.logger.debug("✅ HTML file updated with new base64 zip attachment.");
|
|
237
237
|
}
|
|
@@ -243,7 +243,7 @@ async function updateHtmlZipFileAttachmentPaths(jsonFilePath, htmlFilePath, outp
|
|
|
243
243
|
}
|
|
244
244
|
function buildTestAttachmentMapFromSummary(summaryJsonFilePath, outputDirs, doNotNormalize = false) {
|
|
245
245
|
const summaryJson = JSON.parse(fs_1.default.readFileSync(summaryJsonFilePath, "utf8"));
|
|
246
|
-
return (0,
|
|
246
|
+
return (0, html_report_utils_1.buildTestAttachmentMap)(summaryJson, {
|
|
247
247
|
transformAttachment: doNotNormalize
|
|
248
248
|
? undefined
|
|
249
249
|
: (attachment) => {
|
|
@@ -268,7 +268,7 @@ async function checkFileExistsAsync(filePath) {
|
|
|
268
268
|
}
|
|
269
269
|
async function updateSummaryJsonAttachmentPaths(filePath, outputDirs, urlPrefix) {
|
|
270
270
|
const summaryJson = JSON.parse(await fs_1.default.promises.readFile(filePath, "utf8"));
|
|
271
|
-
(0,
|
|
271
|
+
(0, html_report_utils_1.traverseJsonReportSuites)(summaryJson, (spec) => {
|
|
272
272
|
for (const test of spec.tests) {
|
|
273
273
|
for (const result of test.results || []) {
|
|
274
274
|
for (const attachment of result.attachments || []) {
|
package/dist/test/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BrowserContext, BrowserContextOptions, expect, Page, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestType } from "@playwright/test";
|
|
2
2
|
import { KVClient } from "../kv";
|
|
3
3
|
import { type WebhookMatcherOptions } from "./expect";
|
|
4
|
+
import { type ScopedHTTPHeaders, scopeHTTPHeaders } from "./scoped-http-headers";
|
|
4
5
|
import { injectLocatorHighlightScripts } from "./scripts";
|
|
5
6
|
import { type BaseTestFixtureOpts } from "./types";
|
|
6
7
|
import { setVideoLabel } from "./video-labels";
|
|
@@ -13,10 +14,13 @@ declare global {
|
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
declare const extendExpect: (expectInstance: typeof expect) => import("@playwright/test").Expect<{}>;
|
|
17
|
+
type CustomContextOptions = BrowserContextOptions & {
|
|
18
|
+
scopedHTTPHeaders?: ScopedHTTPHeaders;
|
|
19
|
+
};
|
|
16
20
|
type TestOptions = {
|
|
17
21
|
page: Page;
|
|
18
22
|
kv: KVClient;
|
|
19
|
-
customContextPageProvider: (options?:
|
|
23
|
+
customContextPageProvider: (options?: CustomContextOptions) => Promise<{
|
|
20
24
|
context: BrowserContext;
|
|
21
25
|
page: Page;
|
|
22
26
|
}>;
|
|
@@ -24,5 +28,6 @@ type TestOptions = {
|
|
|
24
28
|
crossShardLocks: void;
|
|
25
29
|
};
|
|
26
30
|
declare const baseTestFixture: (testFn: TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>, options?: BaseTestFixtureOpts) => TestType<PlaywrightTestArgs & PlaywrightTestOptions & TestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
|
|
27
|
-
export {
|
|
31
|
+
export type { CustomContextOptions, ScopedHTTPHeaders };
|
|
32
|
+
export { baseTestFixture, extendExpect, injectLocatorHighlightScripts, scopeHTTPHeaders, setVideoLabel, };
|
|
28
33
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/test/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EACrB,MAAM,EACN,IAAI,EACJ,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,QAAQ,EACT,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjC,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAA8B,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,cAAc,CAAC;QACvB,UAAU,QAAQ,CAAC,CAAC;YAClB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAC7C,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;SACnE;KACF;CACF;AAED,QAAA,MAAM,YAAY,mBAA6B,OAAO,MAAM,0CAG3D,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,IAAI,CAAC;IACX,EAAE,EAAE,QAAQ,CAAC;IACb,yBA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AA;KAAE,CAAC,CAAC;IACtD,UAAU,EAAE,IAAI,CAAC;IACjB,eAAe,EAAE,IAAI,CAAC;CACvB,CAAC;AAIF,QAAA,MAAM,eAAe,WACX,QAAQ,CACd,kBAAkB,GAAG,qBAAqB,EAC1C,oBAAoB,GAAG,uBAAuB,CAC/C,YACQ,mBAAmB,uHA2I7B,CAAC;AAEF,YAAY,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,CAAC;AACxD,OAAO,EACL,eAAe,EACf,YAAY,EACZ,6BAA6B,EAC7B,gBAAgB,EAChB,aAAa,GACd,CAAC"}
|
package/dist/test/index.js
CHANGED
|
@@ -3,12 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setVideoLabel = exports.injectLocatorHighlightScripts = exports.extendExpect = exports.baseTestFixture = void 0;
|
|
6
|
+
exports.setVideoLabel = exports.scopeHTTPHeaders = exports.injectLocatorHighlightScripts = exports.extendExpect = exports.baseTestFixture = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const kv_1 = require("../kv");
|
|
9
9
|
const coverage_1 = require("./coverage");
|
|
10
10
|
const cross_shard_locks_1 = require("./cross-shard-locks");
|
|
11
11
|
const expect_1 = require("./expect");
|
|
12
|
+
const scoped_http_headers_1 = require("./scoped-http-headers");
|
|
13
|
+
Object.defineProperty(exports, "scopeHTTPHeaders", { enumerable: true, get: function () { return scoped_http_headers_1.scopeHTTPHeaders; } });
|
|
12
14
|
const scripts_1 = require("./scripts");
|
|
13
15
|
Object.defineProperty(exports, "injectLocatorHighlightScripts", { enumerable: true, get: function () { return scripts_1.injectLocatorHighlightScripts; } });
|
|
14
16
|
const video_labels_1 = require("./video-labels");
|
|
@@ -55,16 +57,22 @@ const baseTestFixture = function (testFn, options = {}) {
|
|
|
55
57
|
const client = new kv_1.KVClient();
|
|
56
58
|
await use(client);
|
|
57
59
|
},
|
|
58
|
-
customContextPageProvider: async ({ browser }, use, testInfo) => {
|
|
60
|
+
customContextPageProvider: async ({ browser, extraHTTPHeaders }, use, testInfo) => {
|
|
59
61
|
const contexts = [];
|
|
60
|
-
async function createContext(contextOptions = {}) {
|
|
62
|
+
async function createContext({ scopedHTTPHeaders, ...contextOptions } = {}) {
|
|
61
63
|
const pageContext = await browser.newContext({
|
|
62
64
|
...contextOptions,
|
|
65
|
+
...(scopedHTTPHeaders && {
|
|
66
|
+
extraHTTPHeaders: (0, scoped_http_headers_1.withoutScopedHeaderNames)(contextOptions.extraHTTPHeaders ?? extraHTTPHeaders, scopedHTTPHeaders),
|
|
67
|
+
}),
|
|
63
68
|
recordVideo: recordVideoOptions(testInfo.outputDir),
|
|
64
69
|
});
|
|
65
70
|
const pages = [];
|
|
66
71
|
pageContext.on("page", (page) => pages.push(page));
|
|
67
72
|
const customPage = await pageContext.newPage();
|
|
73
|
+
if (scopedHTTPHeaders) {
|
|
74
|
+
await (0, scoped_http_headers_1.scopeHTTPHeaders)(pageContext, scopedHTTPHeaders);
|
|
75
|
+
}
|
|
68
76
|
contexts.push({ context: pageContext, pages });
|
|
69
77
|
(0, scripts_1.injectLocatorHighlightScripts)(customPage, extendedTestFn, options);
|
|
70
78
|
return { context: pageContext, page: customPage };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BrowserContext } from "@playwright/test";
|
|
2
|
+
export type ScopedHTTPHeaders = {
|
|
3
|
+
hosts: string[];
|
|
4
|
+
headers: Record<string, string>;
|
|
5
|
+
};
|
|
6
|
+
type Scope = {
|
|
7
|
+
context: BrowserContext;
|
|
8
|
+
hosts: string[];
|
|
9
|
+
headers: Record<string, string>;
|
|
10
|
+
names: Set<string>;
|
|
11
|
+
};
|
|
12
|
+
export declare function hostMatches(hostname: string, hosts: string[]): boolean;
|
|
13
|
+
export declare function withoutScopedHeaderNames(headers: Record<string, string> | undefined, scoped: ScopedHTTPHeaders): Record<string, string>;
|
|
14
|
+
export declare function overriddenHeaders(url: string, headers: Record<string, string>, scope: Pick<Scope, "hosts" | "headers" | "names">): Array<{
|
|
15
|
+
name: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}> | undefined;
|
|
18
|
+
export declare function scopeHTTPHeaders(context: BrowserContext, scoped: ScopedHTTPHeaders): Promise<() => Promise<void>>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=scoped-http-headers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped-http-headers.d.ts","sourceRoot":"","sources":["../../src/test/scoped-http-headers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,cAAc,EAIf,MAAM,kBAAkB,CAAC;AAE1B,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAAC;AAEF,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACpB,CAAC;AAmBF,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAMtE;AAED,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3C,MAAM,EAAE,iBAAiB,GACxB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASxB;AAED,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC,GAChD,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,SAAS,CAUpD;AA+ID,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CA4B9B"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hostMatches = hostMatches;
|
|
4
|
+
exports.withoutScopedHeaderNames = withoutScopedHeaderNames;
|
|
5
|
+
exports.overriddenHeaders = overriddenHeaders;
|
|
6
|
+
exports.scopeHTTPHeaders = scopeHTTPHeaders;
|
|
7
|
+
const CANCELLED_REQUEST = /Invalid InterceptionId/;
|
|
8
|
+
const brokers = new WeakMap();
|
|
9
|
+
function hostMatches(hostname, hosts) {
|
|
10
|
+
const host = hostname.toLowerCase();
|
|
11
|
+
return hosts.some((pattern) => {
|
|
12
|
+
const rule = pattern.toLowerCase();
|
|
13
|
+
return rule.startsWith("*.") ? host.endsWith(rule.slice(1)) : host === rule;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function withoutScopedHeaderNames(headers, scoped) {
|
|
17
|
+
const names = new Set(Object.keys(scoped.headers).map((name) => name.toLowerCase()));
|
|
18
|
+
return Object.fromEntries(Object.entries(headers ?? {}).filter(([name]) => !names.has(name.toLowerCase())));
|
|
19
|
+
}
|
|
20
|
+
function overriddenHeaders(url, headers, scope) {
|
|
21
|
+
const kept = Object.entries(headers).filter(([name]) => !scope.names.has(name.toLowerCase()));
|
|
22
|
+
const matches = hostMatches(new URL(url).hostname, scope.hosts);
|
|
23
|
+
if (!matches && kept.length === Object.keys(headers).length) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const result = matches ? [...kept, ...Object.entries(scope.headers)] : kept;
|
|
27
|
+
return result.map(([name, value]) => ({ name, value }));
|
|
28
|
+
}
|
|
29
|
+
function frameIds(tree) {
|
|
30
|
+
return [tree.frame.id, ...(tree.childFrames ?? []).flatMap(frameIds)];
|
|
31
|
+
}
|
|
32
|
+
async function createBroker(browser) {
|
|
33
|
+
const session = await browser.newBrowserCDPSession();
|
|
34
|
+
const scopes = new Map();
|
|
35
|
+
const targetContexts = new Map();
|
|
36
|
+
const frameContexts = new Map();
|
|
37
|
+
const frameSessions = new WeakMap();
|
|
38
|
+
let refreshing;
|
|
39
|
+
let enabled = false;
|
|
40
|
+
const recordTarget = ({ targetId, browserContextId }) => {
|
|
41
|
+
if (browserContextId) {
|
|
42
|
+
targetContexts.set(targetId, browserContextId);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
session.on("Target.targetCreated", ({ targetInfo }) => recordTarget(targetInfo));
|
|
46
|
+
session.on("Target.targetInfoChanged", ({ targetInfo }) => recordTarget(targetInfo));
|
|
47
|
+
session.on("Target.targetDestroyed", ({ targetId }) => targetContexts.delete(targetId));
|
|
48
|
+
await session.send("Target.setDiscoverTargets", { discover: true });
|
|
49
|
+
async function sessionFor(context, owner) {
|
|
50
|
+
if (frameSessions.has(owner)) {
|
|
51
|
+
return frameSessions.get(owner) ?? null;
|
|
52
|
+
}
|
|
53
|
+
const created = await context.newCDPSession(owner).catch(() => null);
|
|
54
|
+
frameSessions.set(owner, created);
|
|
55
|
+
return created;
|
|
56
|
+
}
|
|
57
|
+
async function readFrameTrees() {
|
|
58
|
+
for (const [contextId, scope] of scopes) {
|
|
59
|
+
for (const page of scope.context.pages()) {
|
|
60
|
+
const owners = [page, ...page.frames().slice(1)];
|
|
61
|
+
for (const owner of owners) {
|
|
62
|
+
const cdp = await sessionFor(scope.context, owner);
|
|
63
|
+
if (!cdp) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const tree = await cdp.send("Page.getFrameTree").catch(() => null);
|
|
67
|
+
if (!tree) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
for (const id of frameIds(tree.frameTree)) {
|
|
71
|
+
frameContexts.set(id, contextId);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function contextOf(frameId) {
|
|
78
|
+
if (!frameId) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
const known = targetContexts.get(frameId) ?? frameContexts.get(frameId);
|
|
82
|
+
if (known) {
|
|
83
|
+
return known;
|
|
84
|
+
}
|
|
85
|
+
refreshing ??= readFrameTrees().finally(() => (refreshing = undefined));
|
|
86
|
+
await refreshing;
|
|
87
|
+
return frameContexts.get(frameId);
|
|
88
|
+
}
|
|
89
|
+
async function onRequestPaused(event) {
|
|
90
|
+
const contextId = await contextOf(event.frameId);
|
|
91
|
+
const scope = contextId ? scopes.get(contextId) : undefined;
|
|
92
|
+
const headers = scope
|
|
93
|
+
? overriddenHeaders(event.request.url, event.request.headers, scope)
|
|
94
|
+
: undefined;
|
|
95
|
+
await session
|
|
96
|
+
.send("Fetch.continueRequest", {
|
|
97
|
+
requestId: event.requestId,
|
|
98
|
+
...(headers ? { headers } : {}),
|
|
99
|
+
})
|
|
100
|
+
.catch((error) => {
|
|
101
|
+
if (CANCELLED_REQUEST.test(error.message)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
console.warn(`[scopedHTTPHeaders] ${event.request.url}: ${error.message}`);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
session.on("Fetch.requestPaused", (event) => void onRequestPaused(event));
|
|
108
|
+
return {
|
|
109
|
+
async add(contextId, scope) {
|
|
110
|
+
scopes.set(contextId, scope);
|
|
111
|
+
if (enabled) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
enabled = true;
|
|
115
|
+
await session.send("Fetch.enable", {
|
|
116
|
+
patterns: [{ urlPattern: "*", requestStage: "Request" }],
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
async remove(contextId) {
|
|
120
|
+
scopes.delete(contextId);
|
|
121
|
+
for (const [frameId, owner] of frameContexts) {
|
|
122
|
+
if (owner === contextId) {
|
|
123
|
+
frameContexts.delete(frameId);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (scopes.size > 0 || !enabled) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
enabled = false;
|
|
130
|
+
await session.send("Fetch.disable").catch(() => undefined);
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
async function browserContextId(context) {
|
|
135
|
+
const page = context.pages()[0];
|
|
136
|
+
if (!page) {
|
|
137
|
+
throw new Error("scopeHTTPHeaders needs a context that already has a page");
|
|
138
|
+
}
|
|
139
|
+
const cdp = await context.newCDPSession(page);
|
|
140
|
+
try {
|
|
141
|
+
const { targetInfo } = await cdp.send("Target.getTargetInfo");
|
|
142
|
+
if (!targetInfo.browserContextId) {
|
|
143
|
+
throw new Error("scopeHTTPHeaders could not resolve the browser context");
|
|
144
|
+
}
|
|
145
|
+
return targetInfo.browserContextId;
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
await cdp.detach().catch(() => undefined);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function scopeHTTPHeaders(context, scoped) {
|
|
152
|
+
const browser = context.browser();
|
|
153
|
+
if (!browser || browser.browserType().name() !== "chromium") {
|
|
154
|
+
throw new Error("scopedHTTPHeaders is supported on Chromium only");
|
|
155
|
+
}
|
|
156
|
+
if (scoped.hosts.length === 0) {
|
|
157
|
+
throw new Error("scopedHTTPHeaders needs at least one host");
|
|
158
|
+
}
|
|
159
|
+
let broker = brokers.get(browser);
|
|
160
|
+
if (!broker) {
|
|
161
|
+
broker = createBroker(browser);
|
|
162
|
+
brokers.set(browser, broker);
|
|
163
|
+
}
|
|
164
|
+
const contextId = await browserContextId(context);
|
|
165
|
+
const names = new Set(Object.keys(scoped.headers).map((name) => name.toLowerCase()));
|
|
166
|
+
await (await broker).add(contextId, { context, ...scoped, names });
|
|
167
|
+
let removed = false;
|
|
168
|
+
const remove = async () => {
|
|
169
|
+
if (removed) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
removed = true;
|
|
173
|
+
await (await broker).remove(contextId);
|
|
174
|
+
};
|
|
175
|
+
context.once("close", () => void remove());
|
|
176
|
+
return remove;
|
|
177
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped-http-headers.spec.d.ts","sourceRoot":"","sources":["../../src/test/scoped-http-headers.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
|
+
const node_http_1 = __importDefault(require("node:http"));
|
|
8
|
+
const test_1 = require("@playwright/test");
|
|
9
|
+
const index_1 = require("./index");
|
|
10
|
+
const test = (0, index_1.baseTestFixture)(test_1.test).extend({
|
|
11
|
+
servers: async ({}, use) => {
|
|
12
|
+
const seen = [];
|
|
13
|
+
let otherUrl = "";
|
|
14
|
+
const server = node_http_1.default.createServer((req, res) => {
|
|
15
|
+
seen.push({
|
|
16
|
+
host: (req.headers.host ?? "").replace(/:\d+$/, ""),
|
|
17
|
+
method: req.method ?? "",
|
|
18
|
+
path: (req.url ?? "").split("?")[0] ?? "",
|
|
19
|
+
secret: req.headers["x-private-secret"],
|
|
20
|
+
agent: req.headers["x-agent"],
|
|
21
|
+
preflight: req.headers["access-control-request-headers"],
|
|
22
|
+
});
|
|
23
|
+
const cors = {
|
|
24
|
+
"access-control-allow-origin": req.headers.origin ?? "*",
|
|
25
|
+
"access-control-allow-headers": "x-agent",
|
|
26
|
+
};
|
|
27
|
+
if (req.method === "OPTIONS") {
|
|
28
|
+
res.writeHead(204, cors);
|
|
29
|
+
res.end();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (req.url === "/app") {
|
|
33
|
+
res.writeHead(200, { "content-type": "text/html" });
|
|
34
|
+
res.end(`<h1>app</h1><img src="${otherUrl}/pixel.png"><script>
|
|
35
|
+
fetch("${otherUrl}/cors", { method: "POST", body: "x" }).then(
|
|
36
|
+
() => (document.title = "cors-ok"),
|
|
37
|
+
() => (document.title = "cors-failed"),
|
|
38
|
+
);
|
|
39
|
+
</script>`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
res.writeHead(200, { ...cors, "content-type": "text/plain" });
|
|
43
|
+
res.end("ok");
|
|
44
|
+
});
|
|
45
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
46
|
+
const { port } = server.address();
|
|
47
|
+
otherUrl = `http://127.0.0.1:${port}`;
|
|
48
|
+
await use({ appUrl: `http://localhost:${port}`, otherUrl, seen });
|
|
49
|
+
server.close();
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
test.use({
|
|
53
|
+
extraHTTPHeaders: { "x-private-secret": "s3cret", "x-agent": "e" },
|
|
54
|
+
});
|
|
55
|
+
test("scopedHTTPHeaders keeps private headers on matching hosts only", async ({ customContextPageProvider, servers, }) => {
|
|
56
|
+
const { page } = await customContextPageProvider({
|
|
57
|
+
scopedHTTPHeaders: {
|
|
58
|
+
hosts: ["localhost"],
|
|
59
|
+
headers: { "x-private-secret": "s3cret" },
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
await page.goto(`${servers.appUrl}/app`);
|
|
63
|
+
await test_1.test.expect(page).toHaveTitle(/^cors-/);
|
|
64
|
+
test_1.test.expect(await page.title()).toBe("cors-ok");
|
|
65
|
+
test_1.test
|
|
66
|
+
.expect(servers.seen.filter((r) => r.preflight?.includes("x-private")))
|
|
67
|
+
.toEqual([]);
|
|
68
|
+
const app = servers.seen.filter((r) => r.host === "localhost");
|
|
69
|
+
const other = servers.seen.filter((r) => r.host === "127.0.0.1");
|
|
70
|
+
test_1.test
|
|
71
|
+
.expect(app.every((r) => r.secret === "s3cret" && r.agent === "e"))
|
|
72
|
+
.toBe(true);
|
|
73
|
+
test_1.test.expect(other.length).toBeGreaterThan(0);
|
|
74
|
+
test_1.test.expect(other.filter((r) => r.secret)).toEqual([]);
|
|
75
|
+
test_1.test
|
|
76
|
+
.expect(other.filter((r) => r.method !== "OPTIONS" && r.agent !== "e"))
|
|
77
|
+
.toEqual([]);
|
|
78
|
+
await page.context().close();
|
|
79
|
+
const video = await page.video()?.path();
|
|
80
|
+
test_1.test.expect(video && node_fs_1.default.existsSync(video)).toBeTruthy();
|
|
81
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/playwright-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.70.1",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=22"
|
|
6
6
|
},
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"playwright-core": "1.65.1",
|
|
51
51
|
"serve-handler": "^6.1.6",
|
|
52
52
|
"typescript": "7.0.2",
|
|
53
|
-
"@empiricalrun/shared-types": "0.28.
|
|
53
|
+
"@empiricalrun/shared-types": "0.28.2"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@modelcontextprotocol/client": "2.4.0",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"puppeteer-extra-plugin-recaptcha": "^3.6.8",
|
|
64
64
|
"ts-morph": "^28.0.0",
|
|
65
65
|
"@empiricalrun/cua": "^0.6.0",
|
|
66
|
-
"@empiricalrun/r2-uploader": "^0.11.
|
|
67
|
-
"@empiricalrun/reporter": "^0.30.
|
|
66
|
+
"@empiricalrun/r2-uploader": "^0.11.7",
|
|
67
|
+
"@empiricalrun/reporter": "^0.30.5"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"dev": "pnpm gen:api-worker-openapi && tsc --build --watch",
|
package/playwright.config.ts
CHANGED
|
@@ -17,6 +17,11 @@ export default defineConfig({
|
|
|
17
17
|
projects: [
|
|
18
18
|
{ name: "chromium" },
|
|
19
19
|
{ name: "mcp", testDir: "./src/mcp" },
|
|
20
|
+
{
|
|
21
|
+
name: "scoped-http-headers",
|
|
22
|
+
testDir: "./src/test",
|
|
23
|
+
testMatch: /scoped-http-headers\.spec\.ts/,
|
|
24
|
+
},
|
|
20
25
|
{
|
|
21
26
|
name: "regex-test",
|
|
22
27
|
testMatch: /.*\.random-ext.spec\.ts/,
|