@elaraai/e3-web 0.0.0-stage → 1.0.85
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/LICENSE.md +54 -0
- package/README.md +395 -2
- package/dist/src/app.d.ts +91 -0
- package/dist/src/app.d.ts.map +1 -0
- package/dist/src/app.js +112 -0
- package/dist/src/app.js.map +1 -0
- package/dist/src/bridge/bridge.spec.d.ts +6 -0
- package/dist/src/bridge/bridge.spec.d.ts.map +1 -0
- package/dist/src/bridge/bridge.spec.js +56 -0
- package/dist/src/bridge/bridge.spec.js.map +1 -0
- package/dist/src/bridge/page.d.ts +149 -0
- package/dist/src/bridge/page.d.ts.map +1 -0
- package/dist/src/bridge/page.js +328 -0
- package/dist/src/bridge/page.js.map +1 -0
- package/dist/src/bridge/protocol.d.ts +181 -0
- package/dist/src/bridge/protocol.d.ts.map +1 -0
- package/dist/src/bridge/protocol.js +113 -0
- package/dist/src/bridge/protocol.js.map +1 -0
- package/dist/src/bridge/worker.d.ts +124 -0
- package/dist/src/bridge/worker.d.ts.map +1 -0
- package/dist/src/bridge/worker.js +185 -0
- package/dist/src/bridge/worker.js.map +1 -0
- package/dist/src/browser/bridge.page.d.ts +12 -0
- package/dist/src/browser/bridge.page.d.ts.map +1 -0
- package/dist/src/browser/bridge.page.js +79 -0
- package/dist/src/browser/bridge.page.js.map +1 -0
- package/dist/src/browser/bridge.spec.d.ts +6 -0
- package/dist/src/browser/bridge.spec.d.ts.map +1 -0
- package/dist/src/browser/bridge.spec.js +105 -0
- package/dist/src/browser/bridge.spec.js.map +1 -0
- package/dist/src/browser/bridge.worker.d.ts +6 -0
- package/dist/src/browser/bridge.worker.d.ts.map +1 -0
- package/dist/src/browser/bridge.worker.js +35 -0
- package/dist/src/browser/bridge.worker.js.map +1 -0
- package/dist/src/browser/compliance.d.ts +68 -0
- package/dist/src/browser/compliance.d.ts.map +1 -0
- package/dist/src/browser/compliance.js +30 -0
- package/dist/src/browser/compliance.js.map +1 -0
- package/dist/src/browser/compliance.page.d.ts +6 -0
- package/dist/src/browser/compliance.page.d.ts.map +1 -0
- package/dist/src/browser/compliance.page.js +204 -0
- package/dist/src/browser/compliance.page.js.map +1 -0
- package/dist/src/browser/compliance.spec.d.ts +6 -0
- package/dist/src/browser/compliance.spec.d.ts.map +1 -0
- package/dist/src/browser/compliance.spec.js +147 -0
- package/dist/src/browser/compliance.spec.js.map +1 -0
- package/dist/src/browser/e3-api-1.spec.d.ts +6 -0
- package/dist/src/browser/e3-api-1.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-api-1.spec.js +12 -0
- package/dist/src/browser/e3-api-1.spec.js.map +1 -0
- package/dist/src/browser/e3-api-2.spec.d.ts +6 -0
- package/dist/src/browser/e3-api-2.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-api-2.spec.js +12 -0
- package/dist/src/browser/e3-api-2.spec.js.map +1 -0
- package/dist/src/browser/e3-api-3.spec.d.ts +6 -0
- package/dist/src/browser/e3-api-3.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-api-3.spec.js +12 -0
- package/dist/src/browser/e3-api-3.spec.js.map +1 -0
- package/dist/src/browser/e3-api-parts.spec.d.ts +6 -0
- package/dist/src/browser/e3-api-parts.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-api-parts.spec.js +45 -0
- package/dist/src/browser/e3-api-parts.spec.js.map +1 -0
- package/dist/src/browser/e3-api.d.ts +28 -0
- package/dist/src/browser/e3-api.d.ts.map +1 -0
- package/dist/src/browser/e3-api.js +144 -0
- package/dist/src/browser/e3-api.js.map +1 -0
- package/dist/src/browser/e3-client.worker.d.ts +6 -0
- package/dist/src/browser/e3-client.worker.d.ts.map +1 -0
- package/dist/src/browser/e3-client.worker.js +19 -0
- package/dist/src/browser/e3-client.worker.js.map +1 -0
- package/dist/src/browser/e3-forward.d.ts +27 -0
- package/dist/src/browser/e3-forward.d.ts.map +1 -0
- package/dist/src/browser/e3-forward.js +81 -0
- package/dist/src/browser/e3-forward.js.map +1 -0
- package/dist/src/browser/e3-forward.spec.d.ts +6 -0
- package/dist/src/browser/e3-forward.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-forward.spec.js +84 -0
- package/dist/src/browser/e3-forward.spec.js.map +1 -0
- package/dist/src/browser/e3-port.worker.d.ts +6 -0
- package/dist/src/browser/e3-port.worker.d.ts.map +1 -0
- package/dist/src/browser/e3-port.worker.js +21 -0
- package/dist/src/browser/e3-port.worker.js.map +1 -0
- package/dist/src/browser/e3-unit.worker.d.ts +6 -0
- package/dist/src/browser/e3-unit.worker.d.ts.map +1 -0
- package/dist/src/browser/e3-unit.worker.js +18 -0
- package/dist/src/browser/e3-unit.worker.js.map +1 -0
- package/dist/src/browser/e3-wire.d.ts +43 -0
- package/dist/src/browser/e3-wire.d.ts.map +1 -0
- package/dist/src/browser/e3-wire.js +32 -0
- package/dist/src/browser/e3-wire.js.map +1 -0
- package/dist/src/browser/e3.page.d.ts +21 -0
- package/dist/src/browser/e3.page.d.ts.map +1 -0
- package/dist/src/browser/e3.page.js +119 -0
- package/dist/src/browser/e3.page.js.map +1 -0
- package/dist/src/browser/e3.spec.d.ts +6 -0
- package/dist/src/browser/e3.spec.d.ts.map +1 -0
- package/dist/src/browser/e3.spec.js +358 -0
- package/dist/src/browser/e3.spec.js.map +1 -0
- package/dist/src/browser/e3.worker.d.ts +6 -0
- package/dist/src/browser/e3.worker.d.ts.map +1 -0
- package/dist/src/browser/e3.worker.js +38 -0
- package/dist/src/browser/e3.worker.js.map +1 -0
- package/dist/src/browser/harness.d.ts +175 -0
- package/dist/src/browser/harness.d.ts.map +1 -0
- package/dist/src/browser/harness.js +375 -0
- package/dist/src/browser/harness.js.map +1 -0
- package/dist/src/browser/page.d.ts +47 -0
- package/dist/src/browser/page.d.ts.map +1 -0
- package/dist/src/browser/page.js +47 -0
- package/dist/src/browser/page.js.map +1 -0
- package/dist/src/browser/repository.page.d.ts +85 -0
- package/dist/src/browser/repository.page.d.ts.map +1 -0
- package/dist/src/browser/repository.page.js +271 -0
- package/dist/src/browser/repository.page.js.map +1 -0
- package/dist/src/browser/runner.page.d.ts +6 -0
- package/dist/src/browser/runner.page.d.ts.map +1 -0
- package/dist/src/browser/runner.page.js +62 -0
- package/dist/src/browser/runner.page.js.map +1 -0
- package/dist/src/browser/runner.spec.d.ts +6 -0
- package/dist/src/browser/runner.spec.d.ts.map +1 -0
- package/dist/src/browser/runner.spec.js +46 -0
- package/dist/src/browser/runner.spec.js.map +1 -0
- package/dist/src/browser/storage.page.d.ts +6 -0
- package/dist/src/browser/storage.page.d.ts.map +1 -0
- package/dist/src/browser/storage.page.js +289 -0
- package/dist/src/browser/storage.page.js.map +1 -0
- package/dist/src/browser/storage.spec.d.ts +6 -0
- package/dist/src/browser/storage.spec.d.ts.map +1 -0
- package/dist/src/browser/storage.spec.js +211 -0
- package/dist/src/browser/storage.spec.js.map +1 -0
- package/dist/src/browser/unit.worker.d.ts +6 -0
- package/dist/src/browser/unit.worker.d.ts.map +1 -0
- package/dist/src/browser/unit.worker.js +17 -0
- package/dist/src/browser/unit.worker.js.map +1 -0
- package/dist/src/execution/WebTaskRunner.d.ts +159 -0
- package/dist/src/execution/WebTaskRunner.d.ts.map +1 -0
- package/dist/src/execution/WebTaskRunner.js +581 -0
- package/dist/src/execution/WebTaskRunner.js.map +1 -0
- package/dist/src/execution/WebTaskRunner.spec.d.ts +6 -0
- package/dist/src/execution/WebTaskRunner.spec.d.ts.map +1 -0
- package/dist/src/execution/WebTaskRunner.spec.js +91 -0
- package/dist/src/execution/WebTaskRunner.spec.js.map +1 -0
- package/dist/src/execution/e3-platform.d.ts +41 -0
- package/dist/src/execution/e3-platform.d.ts.map +1 -0
- package/dist/src/execution/e3-platform.js +52 -0
- package/dist/src/execution/e3-platform.js.map +1 -0
- package/dist/src/execution/in-process.d.ts +32 -0
- package/dist/src/execution/in-process.d.ts.map +1 -0
- package/dist/src/execution/in-process.js +89 -0
- package/dist/src/execution/in-process.js.map +1 -0
- package/dist/src/execution/pool.d.ts +172 -0
- package/dist/src/execution/pool.d.ts.map +1 -0
- package/dist/src/execution/pool.js +352 -0
- package/dist/src/execution/pool.js.map +1 -0
- package/dist/src/execution/pool.spec.d.ts +6 -0
- package/dist/src/execution/pool.spec.d.ts.map +1 -0
- package/dist/src/execution/pool.spec.js +252 -0
- package/dist/src/execution/pool.spec.js.map +1 -0
- package/dist/src/execution/protocol.d.ts +108 -0
- package/dist/src/execution/protocol.d.ts.map +1 -0
- package/dist/src/execution/protocol.js +27 -0
- package/dist/src/execution/protocol.js.map +1 -0
- package/dist/src/execution/unit-server.d.ts +131 -0
- package/dist/src/execution/unit-server.d.ts.map +1 -0
- package/dist/src/execution/unit-server.js +142 -0
- package/dist/src/execution/unit-server.js.map +1 -0
- package/dist/src/index.d.ts +39 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +37 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/index.spec.d.ts +6 -0
- package/dist/src/index.spec.d.ts.map +1 -0
- package/dist/src/index.spec.js +212 -0
- package/dist/src/index.spec.js.map +1 -0
- package/dist/src/node.d.ts +12 -0
- package/dist/src/node.d.ts.map +1 -0
- package/dist/src/node.js +12 -0
- package/dist/src/node.js.map +1 -0
- package/dist/src/storage/WebStateStore.d.ts +64 -0
- package/dist/src/storage/WebStateStore.d.ts.map +1 -0
- package/dist/src/storage/WebStateStore.js +237 -0
- package/dist/src/storage/WebStateStore.js.map +1 -0
- package/dist/src/storage/WebStorage.d.ts +225 -0
- package/dist/src/storage/WebStorage.d.ts.map +1 -0
- package/dist/src/storage/WebStorage.js +1462 -0
- package/dist/src/storage/WebStorage.js.map +1 -0
- package/dist/src/storage/adapters.d.ts +610 -0
- package/dist/src/storage/adapters.d.ts.map +1 -0
- package/dist/src/storage/adapters.js +246 -0
- package/dist/src/storage/adapters.js.map +1 -0
- package/dist/src/storage/indexeddb.d.ts +93 -0
- package/dist/src/storage/indexeddb.d.ts.map +1 -0
- package/dist/src/storage/indexeddb.js +384 -0
- package/dist/src/storage/indexeddb.js.map +1 -0
- package/dist/src/storage/indexeddb.spec.d.ts +6 -0
- package/dist/src/storage/indexeddb.spec.d.ts.map +1 -0
- package/dist/src/storage/indexeddb.spec.js +77 -0
- package/dist/src/storage/indexeddb.spec.js.map +1 -0
- package/dist/src/storage/memory.d.ts +275 -0
- package/dist/src/storage/memory.d.ts.map +1 -0
- package/dist/src/storage/memory.js +724 -0
- package/dist/src/storage/memory.js.map +1 -0
- package/dist/src/storage/memory.spec.d.ts +6 -0
- package/dist/src/storage/memory.spec.d.ts.map +1 -0
- package/dist/src/storage/memory.spec.js +71 -0
- package/dist/src/storage/memory.spec.js.map +1 -0
- package/dist/src/storage/node-files.d.ts +38 -0
- package/dist/src/storage/node-files.d.ts.map +1 -0
- package/dist/src/storage/node-files.js +148 -0
- package/dist/src/storage/node-files.js.map +1 -0
- package/dist/src/storage/node-files.spec.d.ts +6 -0
- package/dist/src/storage/node-files.spec.d.ts.map +1 -0
- package/dist/src/storage/node-files.spec.js +40 -0
- package/dist/src/storage/node-files.spec.js.map +1 -0
- package/dist/src/storage/opfs.d.ts +145 -0
- package/dist/src/storage/opfs.d.ts.map +1 -0
- package/dist/src/storage/opfs.js +514 -0
- package/dist/src/storage/opfs.js.map +1 -0
- package/dist/src/storage/opfs.spec.d.ts +6 -0
- package/dist/src/storage/opfs.spec.d.ts.map +1 -0
- package/dist/src/storage/opfs.spec.js +51 -0
- package/dist/src/storage/opfs.spec.js.map +1 -0
- package/dist/src/storage/record-keys.d.ts +78 -0
- package/dist/src/storage/record-keys.d.ts.map +1 -0
- package/dist/src/storage/record-keys.js +71 -0
- package/dist/src/storage/record-keys.js.map +1 -0
- package/dist/src/storage/stores.spec.d.ts +6 -0
- package/dist/src/storage/stores.spec.d.ts.map +1 -0
- package/dist/src/storage/stores.spec.js +326 -0
- package/dist/src/storage/stores.spec.js.map +1 -0
- package/dist/src/storage/web-locks.d.ts +103 -0
- package/dist/src/storage/web-locks.d.ts.map +1 -0
- package/dist/src/storage/web-locks.js +228 -0
- package/dist/src/storage/web-locks.js.map +1 -0
- package/dist/src/testing/adapter-contract.d.ts +116 -0
- package/dist/src/testing/adapter-contract.d.ts.map +1 -0
- package/dist/src/testing/adapter-contract.js +769 -0
- package/dist/src/testing/adapter-contract.js.map +1 -0
- package/dist/src/testing/assert.d.ts +75 -0
- package/dist/src/testing/assert.d.ts.map +1 -0
- package/dist/src/testing/assert.js +146 -0
- package/dist/src/testing/assert.js.map +1 -0
- package/dist/src/testing/assert.spec.d.ts +6 -0
- package/dist/src/testing/assert.spec.d.ts.map +1 -0
- package/dist/src/testing/assert.spec.js +62 -0
- package/dist/src/testing/assert.spec.js.map +1 -0
- package/dist/src/testing/bridge-contract.d.ts +55 -0
- package/dist/src/testing/bridge-contract.d.ts.map +1 -0
- package/dist/src/testing/bridge-contract.js +376 -0
- package/dist/src/testing/bridge-contract.js.map +1 -0
- package/dist/src/testing/bridge-handler.d.ts +35 -0
- package/dist/src/testing/bridge-handler.d.ts.map +1 -0
- package/dist/src/testing/bridge-handler.js +108 -0
- package/dist/src/testing/bridge-handler.js.map +1 -0
- package/dist/src/testing/callers.d.ts +29 -0
- package/dist/src/testing/callers.d.ts.map +1 -0
- package/dist/src/testing/callers.js +24 -0
- package/dist/src/testing/callers.js.map +1 -0
- package/dist/src/testing/e3-fixtures.d.ts +38 -0
- package/dist/src/testing/e3-fixtures.d.ts.map +1 -0
- package/dist/src/testing/e3-fixtures.js +126 -0
- package/dist/src/testing/e3-fixtures.js.map +1 -0
- package/dist/src/testing/hold-platform.d.ts +33 -0
- package/dist/src/testing/hold-platform.d.ts.map +1 -0
- package/dist/src/testing/hold-platform.js +41 -0
- package/dist/src/testing/hold-platform.js.map +1 -0
- package/dist/src/testing/runner-cases.d.ts +112 -0
- package/dist/src/testing/runner-cases.d.ts.map +1 -0
- package/dist/src/testing/runner-cases.js +959 -0
- package/dist/src/testing/runner-cases.js.map +1 -0
- package/dist/src/testing/runner-fixtures.d.ts +13 -0
- package/dist/src/testing/runner-fixtures.d.ts.map +1 -0
- package/dist/src/testing/runner-fixtures.js +173 -0
- package/dist/src/testing/runner-fixtures.js.map +1 -0
- package/dist/src/testing/test-platform.d.ts +73 -0
- package/dist/src/testing/test-platform.d.ts.map +1 -0
- package/dist/src/testing/test-platform.js +143 -0
- package/dist/src/testing/test-platform.js.map +1 -0
- package/dist/src/transfer/WebTransferBackend.d.ts +780 -0
- package/dist/src/transfer/WebTransferBackend.d.ts.map +1 -0
- package/dist/src/transfer/WebTransferBackend.js +1140 -0
- package/dist/src/transfer/WebTransferBackend.js.map +1 -0
- package/dist/src/transfer/WebTransferBackend.spec.d.ts +6 -0
- package/dist/src/transfer/WebTransferBackend.spec.d.ts.map +1 -0
- package/dist/src/transfer/WebTransferBackend.spec.js +582 -0
- package/dist/src/transfer/WebTransferBackend.spec.js.map +1 -0
- package/dist/src/transfer/endpoints.d.ts +46 -0
- package/dist/src/transfer/endpoints.d.ts.map +1 -0
- package/dist/src/transfer/endpoints.js +157 -0
- package/dist/src/transfer/endpoints.js.map +1 -0
- package/dist/src/units.d.ts +51 -0
- package/dist/src/units.d.ts.map +1 -0
- package/dist/src/units.js +74 -0
- package/dist/src/units.js.map +1 -0
- package/dist/src/worker.d.ts +126 -0
- package/dist/src/worker.d.ts.map +1 -0
- package/dist/src/worker.js +186 -0
- package/dist/src/worker.js.map +1 -0
- package/dist/src/worker.spec.d.ts +6 -0
- package/dist/src/worker.spec.d.ts.map +1 -0
- package/dist/src/worker.spec.js +195 -0
- package/dist/src/worker.spec.js.map +1 -0
- package/package.json +76 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"e3.worker.js","sourceRoot":"","sources":["../../../src/browser/e3.worker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE7D,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC;AACxD,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,SAAS,CAAC;AACzD,sBAAsB,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC;AACzC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAEpD,OAAO,CAAC;IACN,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,MAAM,CAAC,2BAA2B,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC9E,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI;IAChC,QAAQ,EAAE,cAAc;IACxB,MAAM,EAAE,oBAAoB,EAAE;IAC9B,iBAAiB,EAAE,GAAG,GAAG,IAAI;IAC7B,oBAAoB,EAAE,CAAC;IACvB,wBAAwB,EAAE,EAAE,GAAG,IAAI;CACpC,CAAC,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { type Browser, type Page } from 'playwright-core';
|
|
6
|
+
/** The environment variables that name a Chromium to launch, in precedence
|
|
7
|
+
* order: e3-ui-cli's, and Playwright's own. */
|
|
8
|
+
export declare const BROWSER_ENV_VARS: readonly ["E3_UI_CHROMIUM_PATH", "PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH"];
|
|
9
|
+
/**
|
|
10
|
+
* The Chromium the environment names, if any.
|
|
11
|
+
*
|
|
12
|
+
* @param env - The environment to read
|
|
13
|
+
* @returns The executable's path, or `null` when none is named
|
|
14
|
+
*/
|
|
15
|
+
export declare function envBrowserPath(env?: NodeJS.ProcessEnv): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* What to do when Chromium does not launch.
|
|
18
|
+
*
|
|
19
|
+
* @returns The remediation, a line a way
|
|
20
|
+
*/
|
|
21
|
+
export declare function launchRemediation(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Launches headless Chromium: the executable the environment names when it
|
|
24
|
+
* names one, and otherwise the Chromium Playwright manages.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* The managed launch lets playwright-core find its own build in its cache
|
|
28
|
+
* (`PLAYWRIGHT_BROWSERS_PATH`, or `~/.cache/ms-playwright`): the headless
|
|
29
|
+
* shell `install --only-shell chromium` installs, or a full build.
|
|
30
|
+
* `chromium.executablePath()` is never fed back to the launch, since it names
|
|
31
|
+
* the full build, which a shell-only install lacks.
|
|
32
|
+
*
|
|
33
|
+
* @param env - The environment to read the executable from
|
|
34
|
+
* @returns The browser
|
|
35
|
+
* @throws {Error} When Chromium does not launch, with the remediation
|
|
36
|
+
*/
|
|
37
|
+
export declare function launchChromium(env?: NodeJS.ProcessEnv): Promise<Browser>;
|
|
38
|
+
/**
|
|
39
|
+
* Bundles modules for a browser, each whole.
|
|
40
|
+
*
|
|
41
|
+
* @param entries - Each module's path, by the name it is served at
|
|
42
|
+
* (`/<name>.js`)
|
|
43
|
+
* @returns Each bundle, by the name it is served at
|
|
44
|
+
* @throws {Error} When a module does not bundle: it reaches Node, say
|
|
45
|
+
*/
|
|
46
|
+
export declare function bundle(entries: Readonly<Record<string, string>>): Promise<Map<string, Uint8Array>>;
|
|
47
|
+
/**
|
|
48
|
+
* How {@link Harness.open} sets up.
|
|
49
|
+
*/
|
|
50
|
+
export interface HarnessOptions {
|
|
51
|
+
/** The modules the pages load: each a test page's entry, by the name a
|
|
52
|
+
* page is opened by */
|
|
53
|
+
readonly entries: Readonly<Record<string, string>>;
|
|
54
|
+
/** Directories whose files the pages fetch, each by the name it is served
|
|
55
|
+
* under: a file of the directory named `<name>` is at `/<name>/<file>`.
|
|
56
|
+
* Only a directory's own files are served, nothing above or below it. */
|
|
57
|
+
readonly directories?: Readonly<Record<string, string>>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Chromium, a server of test pages, and the pages opened: what a browser spec
|
|
61
|
+
* runs over.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* describe('in Chromium', () => {
|
|
66
|
+
* let harness: Harness;
|
|
67
|
+
* let page: HarnessPage;
|
|
68
|
+
* before(async () => {
|
|
69
|
+
* harness = await Harness.open({ entries: { storage: fileURLToPath(new URL('./storage.page.js', import.meta.url)) } });
|
|
70
|
+
* page = await harness.newPage('storage');
|
|
71
|
+
* });
|
|
72
|
+
* after(() => harness?.close());
|
|
73
|
+
* it('runs in the page', () => page.call('runCase', 'records', 'indexeddb', 'reads a record …'));
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare class Harness {
|
|
78
|
+
private readonly server;
|
|
79
|
+
private readonly browser;
|
|
80
|
+
private readonly context;
|
|
81
|
+
/** The pages' origin: `http://127.0.0.1:<port>` */
|
|
82
|
+
readonly origin: string;
|
|
83
|
+
private readonly names;
|
|
84
|
+
private readonly pages;
|
|
85
|
+
private constructor();
|
|
86
|
+
/**
|
|
87
|
+
* Bundles the pages' modules, serves them, and launches Chromium.
|
|
88
|
+
*
|
|
89
|
+
* @param options - The modules the pages load, and the directories they
|
|
90
|
+
* fetch files from
|
|
91
|
+
* @returns The harness, with no page open
|
|
92
|
+
* @throws {Error} When a module does not bundle, or Chromium does not
|
|
93
|
+
* launch, with the remediation
|
|
94
|
+
*/
|
|
95
|
+
static open(options: HarnessOptions): Promise<Harness>;
|
|
96
|
+
/**
|
|
97
|
+
* Opens a page of the origin that loads a module, once it serves its
|
|
98
|
+
* functions.
|
|
99
|
+
*
|
|
100
|
+
* @param entry - The module's name, as the harness was given it
|
|
101
|
+
* @returns The page
|
|
102
|
+
* @throws {Error} When the harness has no such module, or the page is not a
|
|
103
|
+
* secure context
|
|
104
|
+
*/
|
|
105
|
+
newPage(entry: string): Promise<HarnessPage>;
|
|
106
|
+
/**
|
|
107
|
+
* Closes every page, Chromium and the server.
|
|
108
|
+
*/
|
|
109
|
+
close(): Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A page a spec calls functions of: a tab of the harness's origin.
|
|
113
|
+
*/
|
|
114
|
+
export declare class HarnessPage {
|
|
115
|
+
readonly page: Page;
|
|
116
|
+
private readonly url;
|
|
117
|
+
private readonly forget;
|
|
118
|
+
/** What the page raised outside any call's answer, not yet reported */
|
|
119
|
+
private readonly errors;
|
|
120
|
+
/** Every error the page has raised, reported or not: never cleared */
|
|
121
|
+
private readonly everRaised;
|
|
122
|
+
private closed;
|
|
123
|
+
/**
|
|
124
|
+
* @param page - The Playwright page, for what the bridge does not cover
|
|
125
|
+
* @param url - The page's address
|
|
126
|
+
* @param forget - Tells the harness the page has closed
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
constructor(page: Page, url: string, forget: () => void);
|
|
130
|
+
/**
|
|
131
|
+
* Every error the page has raised since it opened — reported by a call or
|
|
132
|
+
* not, in the order raised: what a spec asserts is none as each case ends,
|
|
133
|
+
* so an error raised after a case's last call, or while a call whose answer
|
|
134
|
+
* nothing reads ran, fails the case too.
|
|
135
|
+
*/
|
|
136
|
+
get raisedErrors(): readonly Error[];
|
|
137
|
+
/**
|
|
138
|
+
* Loads the page, and waits until it serves its functions.
|
|
139
|
+
*
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
load(): Promise<void>;
|
|
143
|
+
/** Throws what the page raised since it was last asked. */
|
|
144
|
+
private raised;
|
|
145
|
+
/**
|
|
146
|
+
* Calls a function the page serves.
|
|
147
|
+
*
|
|
148
|
+
* @param name - The function's name
|
|
149
|
+
* @param args - Its arguments, which serialize
|
|
150
|
+
* @returns Its answer, which serializes
|
|
151
|
+
* @throws {Error} What the function threw, or what the page raised
|
|
152
|
+
* meanwhile, or when it has not answered in two minutes
|
|
153
|
+
*/
|
|
154
|
+
call<T = unknown>(name: string, ...args: unknown[]): Promise<T>;
|
|
155
|
+
/**
|
|
156
|
+
* Calls a function the page serves, and reads no answer: what a caller
|
|
157
|
+
* that wants none sends — a forwarded request's abort, say. What the page
|
|
158
|
+
* raised meanwhile stays to be reported, by the next call and in
|
|
159
|
+
* {@link raisedErrors}; what the function throws is let go.
|
|
160
|
+
*
|
|
161
|
+
* @param name - The function's name
|
|
162
|
+
* @param args - Its arguments, which serialize
|
|
163
|
+
*/
|
|
164
|
+
tell(name: string, ...args: unknown[]): void;
|
|
165
|
+
/**
|
|
166
|
+
* Reloads the page, as a tab reloads: what it holds in memory goes, and
|
|
167
|
+
* its locks with it, and what it stored stays.
|
|
168
|
+
*/
|
|
169
|
+
reload(): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Closes the page, as a tab closes: nothing is released first.
|
|
172
|
+
*/
|
|
173
|
+
close(): Promise<void>;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=harness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../../src/browser/harness.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiCH,OAAO,EAAY,KAAK,OAAO,EAAuB,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAGzF;gDACgD;AAChD,eAAO,MAAM,gBAAgB,yEAA0E,CAAC;AAMxG;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,GAAG,IAAI,CAMlF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,MA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AAO,CAAC,QAAQ,CAAC,MAAM;IAZtF,uEAAuE;IACvE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,sEAAsE;IACtE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAC1C,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;;OAKG;gBACkB,IAAI,EAAE,IAAI,EAAmB,GAAG,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM,IAAI;IAOlG;;;;;OAKG;IACH,IAAI,YAAY,IAAI,SAAS,KAAK,EAAE,CAEnC;IAED;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAS3B,2DAA2D;IAC3D,OAAO,CAAC,MAAM;IAKd;;;;;;;;OAQG;IACG,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;IAqBrE;;;;;;;;OAQG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAO5C;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAM7B"}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The Chromium harness: what e3-web's browser specs run their pages in.
|
|
7
|
+
*
|
|
8
|
+
* A spec names the modules its pages load — each a test page's entry, which
|
|
9
|
+
* serves its functions with `servePage` (`./page.ts`) — and the harness
|
|
10
|
+
* - bundles each with esbuild, for a browser;
|
|
11
|
+
* - serves the bundles, and a page that loads each, from a local HTTP server
|
|
12
|
+
* on the loopback address, a secure context, so the pages have OPFS and Web
|
|
13
|
+
* Locks — and serves the files of any directories the spec names, for the
|
|
14
|
+
* pages to fetch;
|
|
15
|
+
* - launches Chromium through playwright-core, and opens pages of the one
|
|
16
|
+
* origin in one browser context, so they share its IndexedDB, OPFS and Web
|
|
17
|
+
* Locks as the tabs of one site do;
|
|
18
|
+
* - calls a page's functions from Node, failing the call with what the page
|
|
19
|
+
* threw, or with an error the page raised meanwhile; and keeps every error
|
|
20
|
+
* a page raised, which a spec asserts is none as each case ends, so one
|
|
21
|
+
* raised after a case's last call fails it too.
|
|
22
|
+
*
|
|
23
|
+
* A spec registers each in-page case as a `node:test` test of its own, which
|
|
24
|
+
* calls the page to run it. A spec never skips itself: when Chromium cannot
|
|
25
|
+
* launch, its `before` hook fails with the remediation, and every test in it
|
|
26
|
+
* with it.
|
|
27
|
+
*
|
|
28
|
+
* @packageDocumentation
|
|
29
|
+
*/
|
|
30
|
+
import { readFile } from 'node:fs/promises';
|
|
31
|
+
import { createServer } from 'node:http';
|
|
32
|
+
import * as path from 'node:path';
|
|
33
|
+
import { build } from 'esbuild';
|
|
34
|
+
import { chromium } from 'playwright-core';
|
|
35
|
+
import { BRIDGE } from './page.js';
|
|
36
|
+
/** The environment variables that name a Chromium to launch, in precedence
|
|
37
|
+
* order: e3-ui-cli's, and Playwright's own. */
|
|
38
|
+
export const BROWSER_ENV_VARS = ['E3_UI_CHROMIUM_PATH', 'PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH'];
|
|
39
|
+
/** How long a call of a page's function may take before it fails: a case
|
|
40
|
+
* that hangs fails, naming the call, rather than holding its run. */
|
|
41
|
+
const CALL_DEADLINE_MS = 120_000;
|
|
42
|
+
/**
|
|
43
|
+
* The Chromium the environment names, if any.
|
|
44
|
+
*
|
|
45
|
+
* @param env - The environment to read
|
|
46
|
+
* @returns The executable's path, or `null` when none is named
|
|
47
|
+
*/
|
|
48
|
+
export function envBrowserPath(env = process.env) {
|
|
49
|
+
for (const name of BROWSER_ENV_VARS) {
|
|
50
|
+
const value = env[name];
|
|
51
|
+
if (value)
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* What to do when Chromium does not launch.
|
|
58
|
+
*
|
|
59
|
+
* @returns The remediation, a line a way
|
|
60
|
+
*/
|
|
61
|
+
export function launchRemediation() {
|
|
62
|
+
return [
|
|
63
|
+
' - Install the Chromium Playwright runs: `pnpm --filter @elaraai/e3-web exec playwright-core install --only-shell chromium`' +
|
|
64
|
+
' (add --with-deps on a fresh Linux machine for its system libraries).',
|
|
65
|
+
` - Or set ${BROWSER_ENV_VARS[0]} to a Chrome or Chromium executable (not Ubuntu's snap chromium, whose confinement breaks automation).`,
|
|
66
|
+
].join('\n');
|
|
67
|
+
}
|
|
68
|
+
/** An error's first line. */
|
|
69
|
+
function firstLine(err) {
|
|
70
|
+
return (err instanceof Error ? err.message : `${err}`).split('\n')[0] ?? 'unknown error';
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Launches headless Chromium: the executable the environment names when it
|
|
74
|
+
* names one, and otherwise the Chromium Playwright manages.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* The managed launch lets playwright-core find its own build in its cache
|
|
78
|
+
* (`PLAYWRIGHT_BROWSERS_PATH`, or `~/.cache/ms-playwright`): the headless
|
|
79
|
+
* shell `install --only-shell chromium` installs, or a full build.
|
|
80
|
+
* `chromium.executablePath()` is never fed back to the launch, since it names
|
|
81
|
+
* the full build, which a shell-only install lacks.
|
|
82
|
+
*
|
|
83
|
+
* @param env - The environment to read the executable from
|
|
84
|
+
* @returns The browser
|
|
85
|
+
* @throws {Error} When Chromium does not launch, with the remediation
|
|
86
|
+
*/
|
|
87
|
+
export async function launchChromium(env = process.env) {
|
|
88
|
+
const executablePath = envBrowserPath(env);
|
|
89
|
+
try {
|
|
90
|
+
return await chromium.launch(executablePath === null ? { headless: true } : { headless: true, executablePath });
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
const which = executablePath === null
|
|
94
|
+
? 'the Chromium Playwright manages'
|
|
95
|
+
: `the Chromium ${BROWSER_ENV_VARS.find((name) => env[name]) ?? BROWSER_ENV_VARS[0]} names (${executablePath})`;
|
|
96
|
+
throw new Error(`Could not launch ${which} for e3-web's browser specs: ${firstLine(err)}\n${launchRemediation()}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Bundles modules for a browser, each whole.
|
|
101
|
+
*
|
|
102
|
+
* @param entries - Each module's path, by the name it is served at
|
|
103
|
+
* (`/<name>.js`)
|
|
104
|
+
* @returns Each bundle, by the name it is served at
|
|
105
|
+
* @throws {Error} When a module does not bundle: it reaches Node, say
|
|
106
|
+
*/
|
|
107
|
+
export async function bundle(entries) {
|
|
108
|
+
const outdir = path.resolve('/e3-web-harness');
|
|
109
|
+
const result = await build({
|
|
110
|
+
entryPoints: Object.entries(entries).map(([out, entry]) => ({ in: entry, out })),
|
|
111
|
+
bundle: true,
|
|
112
|
+
format: 'esm',
|
|
113
|
+
platform: 'browser',
|
|
114
|
+
target: 'es2022',
|
|
115
|
+
sourcemap: 'inline',
|
|
116
|
+
write: false,
|
|
117
|
+
outdir,
|
|
118
|
+
logLevel: 'silent',
|
|
119
|
+
});
|
|
120
|
+
return new Map(result.outputFiles.map((file) => [path.basename(file.path, '.js'), file.contents]));
|
|
121
|
+
}
|
|
122
|
+
/** The page that loads a bundle as a module. */
|
|
123
|
+
function pageFor(name) {
|
|
124
|
+
return [
|
|
125
|
+
'<!doctype html>',
|
|
126
|
+
'<html><head><meta charset="utf-8"><title>e3-web test page</title></head>',
|
|
127
|
+
`<body><script type="module" src="/${name}.js"></script></body></html>`,
|
|
128
|
+
].join('\n');
|
|
129
|
+
}
|
|
130
|
+
/** A path of a file a served directory holds: `/<directory>/<file>`, neither
|
|
131
|
+
* name starting with a dot. */
|
|
132
|
+
const SERVED_FILE = /^\/([\w-][\w.-]*)\/([\w-][\w.-]*)$/;
|
|
133
|
+
/**
|
|
134
|
+
* Answers a request with a file of a directory the harness serves: `404` when
|
|
135
|
+
* the directory holds no such file.
|
|
136
|
+
*
|
|
137
|
+
* @param response - The response to answer with
|
|
138
|
+
* @param file - The file's path
|
|
139
|
+
*/
|
|
140
|
+
function serveFile(response, file) {
|
|
141
|
+
readFile(file).then((body) => {
|
|
142
|
+
response.writeHead(200, {
|
|
143
|
+
'content-type': path.extname(file) === '.json' ? 'application/json' : 'application/octet-stream',
|
|
144
|
+
'cache-control': 'no-store',
|
|
145
|
+
}).end(body);
|
|
146
|
+
}, (err) => {
|
|
147
|
+
const code = err.code;
|
|
148
|
+
const missing = code === 'ENOENT' || code === 'EISDIR';
|
|
149
|
+
response.writeHead(missing ? 404 : 500, { 'content-type': 'text/plain' }).end(missing ? 'not found' : firstLine(err));
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Chromium, a server of test pages, and the pages opened: what a browser spec
|
|
154
|
+
* runs over.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* describe('in Chromium', () => {
|
|
159
|
+
* let harness: Harness;
|
|
160
|
+
* let page: HarnessPage;
|
|
161
|
+
* before(async () => {
|
|
162
|
+
* harness = await Harness.open({ entries: { storage: fileURLToPath(new URL('./storage.page.js', import.meta.url)) } });
|
|
163
|
+
* page = await harness.newPage('storage');
|
|
164
|
+
* });
|
|
165
|
+
* after(() => harness?.close());
|
|
166
|
+
* it('runs in the page', () => page.call('runCase', 'records', 'indexeddb', 'reads a record …'));
|
|
167
|
+
* });
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export class Harness {
|
|
171
|
+
server;
|
|
172
|
+
browser;
|
|
173
|
+
context;
|
|
174
|
+
origin;
|
|
175
|
+
names;
|
|
176
|
+
pages = new Set();
|
|
177
|
+
constructor(server, browser, context,
|
|
178
|
+
/** The pages' origin: `http://127.0.0.1:<port>` */
|
|
179
|
+
origin, names) {
|
|
180
|
+
this.server = server;
|
|
181
|
+
this.browser = browser;
|
|
182
|
+
this.context = context;
|
|
183
|
+
this.origin = origin;
|
|
184
|
+
this.names = names;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Bundles the pages' modules, serves them, and launches Chromium.
|
|
188
|
+
*
|
|
189
|
+
* @param options - The modules the pages load, and the directories they
|
|
190
|
+
* fetch files from
|
|
191
|
+
* @returns The harness, with no page open
|
|
192
|
+
* @throws {Error} When a module does not bundle, or Chromium does not
|
|
193
|
+
* launch, with the remediation
|
|
194
|
+
*/
|
|
195
|
+
static async open(options) {
|
|
196
|
+
const bundles = await bundle(options.entries);
|
|
197
|
+
const directories = new Map(Object.entries(options.directories ?? {}));
|
|
198
|
+
const server = createServer((request, response) => {
|
|
199
|
+
const pathname = new URL(request.url ?? '/', 'http://localhost').pathname;
|
|
200
|
+
const served = SERVED_FILE.exec(pathname);
|
|
201
|
+
const directory = served === null ? undefined : directories.get(served[1]);
|
|
202
|
+
if (served !== null && directory !== undefined && request.method === 'GET') {
|
|
203
|
+
serveFile(response, path.join(directory, served[2]));
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const name = /^\/([\w.-]+)\.(js|html)$/.exec(pathname);
|
|
207
|
+
const body = name === null ? undefined : name[2] === 'js' ? bundles.get(name[1]) : bundles.has(name[1]) ? pageFor(name[1]) : undefined;
|
|
208
|
+
if (request.method !== 'GET' || name === null || body === undefined) {
|
|
209
|
+
response.writeHead(404, { 'content-type': 'text/plain' }).end('not found');
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
response.writeHead(200, {
|
|
213
|
+
'content-type': name[2] === 'js' ? 'text/javascript; charset=utf-8' : 'text/html; charset=utf-8',
|
|
214
|
+
'cache-control': 'no-store',
|
|
215
|
+
}).end(body);
|
|
216
|
+
});
|
|
217
|
+
// The loopback address is a secure context, as localhost is.
|
|
218
|
+
await new Promise((resolve, reject) => {
|
|
219
|
+
server.once('error', reject);
|
|
220
|
+
server.listen(0, '127.0.0.1', () => resolve());
|
|
221
|
+
});
|
|
222
|
+
const origin = `http://127.0.0.1:${server.address().port}`;
|
|
223
|
+
let browser;
|
|
224
|
+
try {
|
|
225
|
+
browser = await launchChromium();
|
|
226
|
+
const context = await browser.newContext();
|
|
227
|
+
return new Harness(server, browser, context, origin, new Set(bundles.keys()));
|
|
228
|
+
}
|
|
229
|
+
catch (err) {
|
|
230
|
+
await browser?.close();
|
|
231
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
232
|
+
throw err;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Opens a page of the origin that loads a module, once it serves its
|
|
237
|
+
* functions.
|
|
238
|
+
*
|
|
239
|
+
* @param entry - The module's name, as the harness was given it
|
|
240
|
+
* @returns The page
|
|
241
|
+
* @throws {Error} When the harness has no such module, or the page is not a
|
|
242
|
+
* secure context
|
|
243
|
+
*/
|
|
244
|
+
async newPage(entry) {
|
|
245
|
+
if (!this.names.has(entry))
|
|
246
|
+
throw new Error(`the harness has no page '${entry}'`);
|
|
247
|
+
const page = new HarnessPage(await this.context.newPage(), `${this.origin}/${entry}.html`, () => this.pages.delete(page));
|
|
248
|
+
this.pages.add(page);
|
|
249
|
+
await page.load();
|
|
250
|
+
return page;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Closes every page, Chromium and the server.
|
|
254
|
+
*/
|
|
255
|
+
async close() {
|
|
256
|
+
for (const page of [...this.pages])
|
|
257
|
+
await page.close();
|
|
258
|
+
await this.context.close();
|
|
259
|
+
await this.browser.close();
|
|
260
|
+
await new Promise((resolve) => this.server.close(() => resolve()));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* A page a spec calls functions of: a tab of the harness's origin.
|
|
265
|
+
*/
|
|
266
|
+
export class HarnessPage {
|
|
267
|
+
page;
|
|
268
|
+
url;
|
|
269
|
+
forget;
|
|
270
|
+
/** What the page raised outside any call's answer, not yet reported */
|
|
271
|
+
errors = [];
|
|
272
|
+
/** Every error the page has raised, reported or not: never cleared */
|
|
273
|
+
everRaised = [];
|
|
274
|
+
closed = false;
|
|
275
|
+
/**
|
|
276
|
+
* @param page - The Playwright page, for what the bridge does not cover
|
|
277
|
+
* @param url - The page's address
|
|
278
|
+
* @param forget - Tells the harness the page has closed
|
|
279
|
+
* @internal
|
|
280
|
+
*/
|
|
281
|
+
constructor(page, url, forget) {
|
|
282
|
+
this.page = page;
|
|
283
|
+
this.url = url;
|
|
284
|
+
this.forget = forget;
|
|
285
|
+
page.on('pageerror', (error) => {
|
|
286
|
+
this.errors.push(error);
|
|
287
|
+
this.everRaised.push(error);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Every error the page has raised since it opened — reported by a call or
|
|
292
|
+
* not, in the order raised: what a spec asserts is none as each case ends,
|
|
293
|
+
* so an error raised after a case's last call, or while a call whose answer
|
|
294
|
+
* nothing reads ran, fails the case too.
|
|
295
|
+
*/
|
|
296
|
+
get raisedErrors() {
|
|
297
|
+
return [...this.everRaised];
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Loads the page, and waits until it serves its functions.
|
|
301
|
+
*
|
|
302
|
+
* @internal
|
|
303
|
+
*/
|
|
304
|
+
async load() {
|
|
305
|
+
await this.page.goto(this.url);
|
|
306
|
+
await this.page.waitForFunction((bridge) => globalThis[bridge]?.ready === true, BRIDGE);
|
|
307
|
+
if (!(await this.page.evaluate(() => isSecureContext))) {
|
|
308
|
+
throw new Error(`${this.url} is not a secure context: it has neither OPFS nor Web Locks`);
|
|
309
|
+
}
|
|
310
|
+
this.raised();
|
|
311
|
+
}
|
|
312
|
+
/** Throws what the page raised since it was last asked. */
|
|
313
|
+
raised() {
|
|
314
|
+
const errors = this.errors.splice(0);
|
|
315
|
+
if (errors.length > 0)
|
|
316
|
+
throw new Error(`the page raised: ${errors.map((error) => error.stack ?? error.message).join('\n')}`);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Calls a function the page serves.
|
|
320
|
+
*
|
|
321
|
+
* @param name - The function's name
|
|
322
|
+
* @param args - Its arguments, which serialize
|
|
323
|
+
* @returns Its answer, which serializes
|
|
324
|
+
* @throws {Error} What the function threw, or what the page raised
|
|
325
|
+
* meanwhile, or when it has not answered in two minutes
|
|
326
|
+
*/
|
|
327
|
+
async call(name, ...args) {
|
|
328
|
+
this.raised();
|
|
329
|
+
let timer;
|
|
330
|
+
const deadline = new Promise((_, reject) => {
|
|
331
|
+
timer = setTimeout(() => reject(new Error(`the page did not answer ${name} in ${CALL_DEADLINE_MS / 1000} s`)), CALL_DEADLINE_MS);
|
|
332
|
+
});
|
|
333
|
+
try {
|
|
334
|
+
const answer = await Promise.race([
|
|
335
|
+
this.page.evaluate(({ bridge, fn, fnArgs }) => globalThis[bridge].call(fn, fnArgs), { bridge: BRIDGE, fn: name, fnArgs: args }),
|
|
336
|
+
deadline,
|
|
337
|
+
]);
|
|
338
|
+
this.raised();
|
|
339
|
+
return answer;
|
|
340
|
+
}
|
|
341
|
+
finally {
|
|
342
|
+
clearTimeout(timer);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Calls a function the page serves, and reads no answer: what a caller
|
|
347
|
+
* that wants none sends — a forwarded request's abort, say. What the page
|
|
348
|
+
* raised meanwhile stays to be reported, by the next call and in
|
|
349
|
+
* {@link raisedErrors}; what the function throws is let go.
|
|
350
|
+
*
|
|
351
|
+
* @param name - The function's name
|
|
352
|
+
* @param args - Its arguments, which serialize
|
|
353
|
+
*/
|
|
354
|
+
tell(name, ...args) {
|
|
355
|
+
this.page.evaluate(({ bridge, fn, fnArgs }) => globalThis[bridge].call(fn, fnArgs), { bridge: BRIDGE, fn: name, fnArgs: args }).catch(() => undefined);
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Reloads the page, as a tab reloads: what it holds in memory goes, and
|
|
359
|
+
* its locks with it, and what it stored stays.
|
|
360
|
+
*/
|
|
361
|
+
async reload() {
|
|
362
|
+
await this.load();
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Closes the page, as a tab closes: nothing is released first.
|
|
366
|
+
*/
|
|
367
|
+
async close() {
|
|
368
|
+
if (this.closed)
|
|
369
|
+
return;
|
|
370
|
+
this.closed = true;
|
|
371
|
+
this.forget();
|
|
372
|
+
await this.page.close();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
//# sourceMappingURL=harness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness.js","sourceRoot":"","sources":["../../../src/browser/harness.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAC;AAEjG,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAgD,MAAM,iBAAiB,CAAC;AACzF,OAAO,EAAE,MAAM,EAAmB,MAAM,WAAW,CAAC;AAEpD;gDACgD;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,qBAAqB,EAAE,qCAAqC,CAAU,CAAC;AAExG;sEACsE;AACtE,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAAyB,OAAO,CAAC,GAAG;IACjE,KAAK,MAAM,IAAI,IAAI,gBAAgB,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;IAC1B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;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;;;OAGG;IACH,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The page side of the Chromium harness: what a test page gives the Node
|
|
7
|
+
* side to call.
|
|
8
|
+
*
|
|
9
|
+
* A test page's entry serves its functions with {@link servePage}; the Node
|
|
10
|
+
* side's `HarnessPage.call` calls one by name, with arguments and an answer
|
|
11
|
+
* that serialize (strings, numbers, booleans, `null`, arrays and plain
|
|
12
|
+
* objects). What a function throws fails the call, and the Node-side test
|
|
13
|
+
* with it, with its message.
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
/** The global the bridge is published under. */
|
|
18
|
+
export declare const BRIDGE = "__e3WebHarness";
|
|
19
|
+
/** A function a test page serves. */
|
|
20
|
+
export type PageFunction = (...args: never[]) => unknown;
|
|
21
|
+
/**
|
|
22
|
+
* The bridge a page publishes: what the Node side calls.
|
|
23
|
+
*/
|
|
24
|
+
export interface PageBridge {
|
|
25
|
+
/** Set once the page serves its functions */
|
|
26
|
+
readonly ready: true;
|
|
27
|
+
/** Calls a function the page serves */
|
|
28
|
+
call(name: string, args: readonly unknown[]): Promise<unknown>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Serves a test page's functions to the Node side, and says the page is
|
|
32
|
+
* ready.
|
|
33
|
+
*
|
|
34
|
+
* @param functions - The functions, by the name the Node side calls each by
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* // storage.page.ts, bundled by the harness
|
|
39
|
+
* servePage({
|
|
40
|
+
* async add(a: number, b: number) { return a + b; },
|
|
41
|
+
* });
|
|
42
|
+
* // storage.spec.ts
|
|
43
|
+
* assert.equal(await page.call('add', 1, 2), 3);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function servePage(functions: Readonly<Record<string, PageFunction>>): void;
|
|
47
|
+
//# sourceMappingURL=page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../../src/browser/page.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;GAWG;AAEH,gDAAgD;AAChD,eAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,qCAAqC;AACrC,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IACrB,uCAAuC;IACvC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAChE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,GAAG,IAAI,CAUjF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The page side of the Chromium harness: what a test page gives the Node
|
|
7
|
+
* side to call.
|
|
8
|
+
*
|
|
9
|
+
* A test page's entry serves its functions with {@link servePage}; the Node
|
|
10
|
+
* side's `HarnessPage.call` calls one by name, with arguments and an answer
|
|
11
|
+
* that serialize (strings, numbers, booleans, `null`, arrays and plain
|
|
12
|
+
* objects). What a function throws fails the call, and the Node-side test
|
|
13
|
+
* with it, with its message.
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
/** The global the bridge is published under. */
|
|
18
|
+
export const BRIDGE = '__e3WebHarness';
|
|
19
|
+
/**
|
|
20
|
+
* Serves a test page's functions to the Node side, and says the page is
|
|
21
|
+
* ready.
|
|
22
|
+
*
|
|
23
|
+
* @param functions - The functions, by the name the Node side calls each by
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* // storage.page.ts, bundled by the harness
|
|
28
|
+
* servePage({
|
|
29
|
+
* async add(a: number, b: number) { return a + b; },
|
|
30
|
+
* });
|
|
31
|
+
* // storage.spec.ts
|
|
32
|
+
* assert.equal(await page.call('add', 1, 2), 3);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function servePage(functions) {
|
|
36
|
+
const bridge = {
|
|
37
|
+
ready: true,
|
|
38
|
+
async call(name, args) {
|
|
39
|
+
const fn = functions[name];
|
|
40
|
+
if (fn === undefined)
|
|
41
|
+
throw new Error(`the page serves no function '${name}'`);
|
|
42
|
+
return await fn(...args);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
globalThis[BRIDGE] = bridge;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=page.js.map
|