@harnessed-ts/resolve 0.0.0-stage → 0.6.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/CHANGELOG.md ADDED
@@ -0,0 +1,70 @@
1
+ # @harnessed-ts/resolve
2
+
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e324e94: ember-test-selectors style test ids: `configure({ testIdAttribute: 'data-test-*' })` makes `testId('x')` match any element that has the attribute `data-test-x`, whatever its value, with the same scoping, strictness, `{ global: true }`, frame and absence rules as before under every driver. A plain attribute name keeps matching by value. A presence id is held to letters, digits, `-`, `_`, `.` and `:`, and anything else (or a `RegExp`) is refused rather than spliced into a selector.
8
+
9
+ `Query.boundingBox()` resolves to `{ x, y, width, height }`: the target's border box in CSS pixels, relative to the top-level viewport, offset by every frame crossed. Strict, and on an absent target it rejects after the timeout, as `text()` does. A node that draws no box reads as all zeros, and so does every node under the dom driver: jsdom computes no layout.
10
+
11
+ `Query.upload(files)` sets the files of an `<input type="file">`, or of the input a `<label>` is for, and fires `input` and `change`, replacing any earlier selection. It refuses any other element, and several files for an input that is not `multiple`. Puppeteer, WebdriverIO and TestCafe take only paths, so there each `File` is written to a temporary directory first: its name and bytes arrive, and the browser infers its type from the extension.
12
+
13
+ `Query` gains two abstract members, so a driver outside this repo implements both to keep compiling; the conformance catalog pins all three changes.
14
+
15
+ `@harnessed-ts/eslint-plugin` supports ESLint 8.57 and legacy `.eslintrc`: the peer range is now `>=8.57`, `legacy-recommended` and `legacy-strict` name the rules under `@harnessed-ts/`, and the CJS build exposes `rules` and `configs` at the top level, where eslintrc reads them.
16
+
17
+ `npx @harnessed-ts/claude install` detects ember-test-selectors attributes (in `.gts`, `.gjs` and `.hbs` files too) and writes `testIdAttribute: 'data-test-*'`.
18
+
19
+ `@harnessed-ts/storybook` writes and finds its story-ready marker under a `data-test-*` config, where `StoryPage` waits for it.
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [e324e94]
24
+ - @harnessed-ts/core@0.6.0
25
+
26
+ ## 0.5.0
27
+
28
+ ### Patch Changes
29
+
30
+ - @harnessed-ts/core@0.5.0
31
+
32
+ ## 0.4.0
33
+
34
+ ### Minor Changes
35
+
36
+ - 9666a3d: New package `@harnessed-ts/resolve`: the selector resolver the Testing Library driver has always used, extracted so every driver that can run JavaScript in the page shares it — role with `level`, strictness, absence, and frame semantics come from one implementation. Adds non-waiting forms (`resolveOneNow`, `resolveAllNow`) for runtimes that retry on their own, and `@harnessed-ts/resolve/inject`, a self-contained build a remote driver (WebdriverIO, Puppeteer, TestCafe) injects into the page, with `encodeSelector` to carry `RegExp`s across the wire.
37
+
38
+ `@harnessed-ts/dom` now depends on it. No behaviour change.
39
+
40
+ - 9666a3d: Add `isVisibleInLayout(element, home?)`, Playwright's visibility rule — a non-empty box that `visibility` does not hide, inside frames that are visible too — for in-page drivers running in a real browser. The injected page API answers it too, as `visible(element)`, for drivers that resolve from outside the page. The main entry no longer imports Node's `url` and `path` through a chunk shared with `/inject`, so it loads in a browser.
41
+ - 1823546: `isVisible()`, `waitFor('visible')` and `waitFor('hidden')` on a target matching
42
+ several nodes now reject with the shared strict-mode violation, at once, under
43
+ every driver. The dom, Ember, Vitest browser mode and Cypress drivers answered
44
+ `false` from `isVisible()`, waited out the timeout in `waitFor('visible')`, and —
45
+ worse — resolved `waitFor('hidden')` at once, passing a wait for three rendered
46
+ nodes to disappear; Playwright's waits raised its own wording instead of the
47
+ shared one. An `nth()`
48
+ past the last match answers `false` from `isVisible()` and counts as hidden, as it
49
+ does under Playwright — Puppeteer and TestCafe used to reject it as an index out
50
+ of range.
51
+
52
+ Core exports `StrictModeViolation`, the class `strictViolation()` now returns, so a
53
+ driver can tell ambiguity apart from absence. It is the class a caller catches
54
+ under every driver: core also exports `reviveStrictViolation()`, which the
55
+ Puppeteer, WebdriverIO and TestCafe drivers apply to what the page throws, so
56
+ a violation raised in the page arrives as core's class, worded exactly as an
57
+ in-process driver words it. `instanceof StrictModeViolation` checks a brand
58
+ rather than the prototype, so it holds across two copies of core in one page —
59
+ Cypress bundles the support file and each spec separately.
60
+
61
+ `WaitState` now documents the rule it is held to: a state joins only when every
62
+ driver honours it with the same meaning, so a runner's own states — Playwright's
63
+ `attached` and `detached` — stay out of the shared interface.
64
+
65
+ ### Patch Changes
66
+
67
+ - Updated dependencies [9666a3d]
68
+ - Updated dependencies [9666a3d]
69
+ - Updated dependencies [1823546]
70
+ - @harnessed-ts/core@0.4.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Joe Gaudet, Jay Seo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,73 @@
1
- # Temporary Holding Version
1
+ # @harnessed-ts/resolve
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The selector resolver behind every Testing Library-family driver for
4
+ `@harnessed-ts/core`. It turns a scope chain plus a `Selector` into DOM nodes with
5
+ the cross-driver guarantees built in: `role` honours `level`, a single-target
6
+ lookup is strict, absence answers at once, and only `frame()` crosses into an
7
+ `<iframe>`.
8
+
9
+ You do not install this to write harnesses — a driver depends on it. Install it
10
+ when you are **writing a driver**.
11
+
12
+ ## In-process drivers
13
+
14
+ A driver that shares a realm with the page (jsdom, Ember's test container,
15
+ Cypress's AUT, Vitest browser mode) calls the resolver directly:
16
+
17
+ ```ts
18
+ import { countAll, resolveOne } from '@harnessed-ts/resolve'
19
+
20
+ const element = await resolveOne(container, scope, selector, timeout)
21
+ const total = await countAll(container, scope, selector)
22
+ ```
23
+
24
+ `resolveOneNow`, `resolveAllNow` and `resolveScopeNow` are the non-waiting forms,
25
+ for a runtime that does its own retrying: "not there yet" is `null`, while
26
+ strictness and frame errors still throw.
27
+
28
+ A driver running in a real browser answers `isVisible()` with
29
+ `isVisibleInLayout(element, home)` — Playwright's rule: a non-empty box that
30
+ `visibility` does not hide, inside frames that are visible too, crossed up to
31
+ `home`. It answers `boundingBox()` with `boundingBoxOf(element, home)`, which adds
32
+ each crossed frame's `frameOrigin()`, and finds an upload's input with
33
+ `fileInputOf(element)` — the element, or a `<label>`'s control — before handing
34
+ the result to core's `checkFileTarget()`.
35
+
36
+ A remote driver asks the same of the page through `box`, `origin` and
37
+ `fileTarget`, and adds the origin of each frame it entered itself.
38
+ `filesOnDisk(files)` from `@harnessed-ts/resolve/inject` writes `File`s to a
39
+ temporary directory for a browser that only takes paths.
40
+
41
+ ## Remote drivers
42
+
43
+ A driver whose test code runs in Node while the page runs elsewhere (WebdriverIO,
44
+ Puppeteer, TestCafe) injects a self-contained build and calls it through the page:
45
+
46
+ ```ts
47
+ import { encodeSelector, injectSource, PAGE_API_GLOBAL } from '@harnessed-ts/resolve/inject'
48
+
49
+ await page.evaluate(injectSource())
50
+ const handle = await page.evaluateHandle(
51
+ (name, scope, selector, options) => window[name].one(null, scope, selector, options),
52
+ PAGE_API_GLOBAL,
53
+ scope.map(encodeSelector),
54
+ encodeSelector(selector),
55
+ { testIdAttribute: 'data-testid', timeout: 5000 },
56
+ )
57
+ ```
58
+
59
+ `encodeSelector` is required: a `RegExp` does not survive WebDriver, CDP or
60
+ TestCafe serialisation, and the page API decodes the tagged form back. The
61
+ runtime config travels with each call because the page cannot see the test
62
+ process's `configure()`. `injectPath()` gives the file's path for tools that inject
63
+ by path.
64
+
65
+ An error the page throws comes back as a plain error: WebDriver, CDP and TestCafe
66
+ keep its message and, at most, its name. Pass it through `reviveStrictViolation()`
67
+ from `@harnessed-ts/core` so a strict-mode violation is `StrictModeViolation`
68
+ again, worded exactly as an in-process driver words it — that is how a caller
69
+ tells ambiguity apart from absence.
70
+
71
+ Full guide: the [harnessed README](https://github.com/joegaudet/harnessed#readme).
72
+
73
+ MIT © Joe Gaudet, Jay Seo
package/dist/box.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { BoundingBox } from '@harnessed-ts/core';
2
+ /** A point in a document's viewport, in CSS pixels. */
3
+ export interface Point {
4
+ x: number;
5
+ y: number;
6
+ }
7
+ /**
8
+ * An element's border box in its own document's viewport, or `null` when it
9
+ * renders no box at all (`display: none`, or anything inside it). Every driver
10
+ * reads `null` as all zeros, which is what Playwright and Puppeteer — whose
11
+ * native boxes are `null` there — are normalised to.
12
+ */
13
+ export declare function boxInOwnDocument(element: Element): BoundingBox | null;
14
+ /**
15
+ * Where an iframe's document is drawn, in the iframe's own document: the corner
16
+ * of its content box, inside its border and padding. The same offset Playwright
17
+ * and Puppeteer add when they report a framed element's box.
18
+ */
19
+ export declare function frameOrigin(iframe: Element): Point;
20
+ /**
21
+ * An element's box relative to the viewport of `home` — the document the
22
+ * driver drives — adding the origin of every same-origin frame crossed on the
23
+ * way up. For drivers that resolve inside the page; under jsdom everything is
24
+ * zeros, because jsdom computes no layout.
25
+ */
26
+ export declare function boundingBoxOf(element: Element, home?: Document): BoundingBox;
27
+ //# sourceMappingURL=box.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../src/box.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,uDAAuD;AACvD,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAIrE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,KAAK,CAQlD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,QAAQ,GAAG,WAAW,CAc5E"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The file input an upload sets: the element itself, or the control of a
3
+ * `<label>` — user-event's and Playwright's rule both. Anything else comes back
4
+ * described as markup, for core's `checkFileTarget` to refuse in one wording.
5
+ */
6
+ export declare function fileInputOf(element: Element): HTMLInputElement | string;
7
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,GAAG,MAAM,CAOvE"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Where the injected build installs itself on the page's `window`. A leaf
3
+ * module with no imports, so the Node-side `inject` entry can name it without
4
+ * pulling in the resolver and Testing Library, which only run in the page.
5
+ */
6
+ export declare const PAGE_API_GLOBAL = "__harnessedResolve";
7
+ //# sourceMappingURL=global-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-name.d.ts","sourceRoot":"","sources":["../src/global-name.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,eAAe,uBAAuB,CAAA"}
package/dist/index.cjs ADDED
@@ -0,0 +1,315 @@
1
+ 'use strict';
2
+
3
+ var core = require('@harnessed-ts/core');
4
+ var dom = require('@testing-library/dom');
5
+
6
+ // src/resolve.ts
7
+ var syncTestIdAttribute = core.testIdSync(
8
+ (testIdAttribute) => dom.configure({ testIdAttribute })
9
+ );
10
+ function queryAllByPresence(container, css) {
11
+ return [...container.querySelectorAll(css)];
12
+ }
13
+ var [, , , findAllByPresence] = dom.buildQueries(
14
+ queryAllByPresence,
15
+ (_container, css) => `Found multiple elements by: ${css}`,
16
+ (_container, css) => `Unable to find an element by: ${css}`
17
+ );
18
+ function presenceOf(selector) {
19
+ return core.testIdPresenceSelector(core.getConfig().testIdAttribute, selector.testId);
20
+ }
21
+ function queryAll(root, selector) {
22
+ syncTestIdAttribute();
23
+ const scoped = dom.within(root);
24
+ switch (selector.type) {
25
+ case "role":
26
+ return scoped.queryAllByRole(selector.role, selector.options);
27
+ case "label":
28
+ return scoped.queryAllByLabelText(selector.text);
29
+ case "testId": {
30
+ const css = presenceOf(selector);
31
+ return css === void 0 ? scoped.queryAllByTestId(selector.testId) : queryAllByPresence(root, css);
32
+ }
33
+ case "text":
34
+ return scoped.queryAllByText(selector.text);
35
+ case "placeholder":
36
+ return scoped.queryAllByPlaceholderText(selector.text);
37
+ }
38
+ }
39
+ async function findOne(root, scope, selector, timeout) {
40
+ syncTestIdAttribute();
41
+ const immediate = queryAll(root, selector);
42
+ const resolved = immediate.length > 0 ? immediate : await findAll(root, selector, timeout);
43
+ return pick(resolved, scope, selector);
44
+ }
45
+ function pick(resolved, scope, selector) {
46
+ if (selector.nth !== void 0) {
47
+ const found = resolved[selector.nth];
48
+ if (found === void 0) {
49
+ throw core.indexOutOfRange(selector.nth, resolved.length, scope, selector);
50
+ }
51
+ return found;
52
+ }
53
+ if (resolved.length > 1) throw core.strictViolation(resolved.length, scope, selector);
54
+ return resolved[0];
55
+ }
56
+ async function findAll(root, selector, timeout) {
57
+ syncTestIdAttribute();
58
+ const scoped = dom.within(root);
59
+ const options = { timeout: core.timeoutFor(timeout) };
60
+ switch (selector.type) {
61
+ case "role":
62
+ return scoped.findAllByRole(selector.role, selector.options, options);
63
+ case "label":
64
+ return scoped.findAllByLabelText(selector.text, void 0, options);
65
+ case "testId": {
66
+ const css = presenceOf(selector);
67
+ return css === void 0 ? scoped.findAllByTestId(selector.testId, void 0, options) : findAllByPresence(root, css, void 0, options);
68
+ }
69
+ case "text":
70
+ return scoped.findAllByText(selector.text, void 0, options);
71
+ case "placeholder":
72
+ return scoped.findAllByPlaceholderText(selector.text, void 0, options);
73
+ }
74
+ }
75
+ async function resolveScope(container, scope, timeout) {
76
+ let current = container;
77
+ for (const [index, step] of scope.entries()) {
78
+ const path = scope.slice(0, index);
79
+ const found = await findOne(current, path, step, timeout);
80
+ current = step.frame === true ? frameBody(found, path, step) : found;
81
+ }
82
+ return current;
83
+ }
84
+ var FrameEntryError = class extends Error {
85
+ name = "FrameEntryError";
86
+ };
87
+ function frameBody(element, scope, selector) {
88
+ if (element.localName !== "iframe") {
89
+ throw new FrameEntryError(
90
+ `harnessed: ${core.describeScope(scope, selector)} is marked as a frame but is a <${element.localName}>, not an <iframe>.`
91
+ );
92
+ }
93
+ const body = element.contentDocument?.body;
94
+ if (body == null) {
95
+ throw new FrameEntryError(
96
+ `harnessed: ${core.describeScope(scope, selector)} has no reachable document: it is cross-origin, or its document has no body. The dom driver enters same-origin frames only; drive a cross-origin one with a browser driver.`
97
+ );
98
+ }
99
+ return body;
100
+ }
101
+ async function resolveOne(container, scope, selector, timeout) {
102
+ const root = await resolveScope(container, scope, timeout);
103
+ return findOne(root, scope, selector, timeout);
104
+ }
105
+ async function countAll(container, scope, selector, timeout) {
106
+ let root;
107
+ try {
108
+ root = await resolveScope(container, scope, timeout);
109
+ } catch (error) {
110
+ if (error instanceof FrameEntryError) throw error;
111
+ return 0;
112
+ }
113
+ const matches = queryAll(root, selector);
114
+ if (selector.nth === void 0) return matches.length;
115
+ return matches[selector.nth] === void 0 ? 0 : 1;
116
+ }
117
+ function resolveScopeNow(container, scope) {
118
+ let current = container;
119
+ for (const [index, step] of scope.entries()) {
120
+ const path = scope.slice(0, index);
121
+ const matches = queryAll(current, step);
122
+ if (matches.length === 0) return null;
123
+ const found = pick(matches, path, step);
124
+ current = step.frame === true ? frameBody(found, path, step) : found;
125
+ }
126
+ return current;
127
+ }
128
+ function resolveOneNow(container, scope, selector) {
129
+ const root = resolveScopeNow(container, scope);
130
+ if (root === null) return null;
131
+ const matches = queryAll(root, selector);
132
+ if (matches.length === 0) return null;
133
+ return pick(matches, scope, selector);
134
+ }
135
+ function resolveAllNow(container, scope, selector) {
136
+ let root;
137
+ try {
138
+ root = resolveScopeNow(container, scope);
139
+ } catch (error) {
140
+ if (error instanceof FrameEntryError) throw error;
141
+ return [];
142
+ }
143
+ if (root === null) return [];
144
+ const matches = queryAll(root, selector);
145
+ if (selector.nth === void 0) return matches;
146
+ const found = matches[selector.nth];
147
+ return found === void 0 ? [] : [found];
148
+ }
149
+ async function resolveAll(container, scope, selector, timeout) {
150
+ return queryAll(await resolveScope(container, scope, timeout), selector);
151
+ }
152
+
153
+ // src/visible.ts
154
+ function isVisibleInLayout(element, home) {
155
+ if (!isVisibleInOwnDocument(element)) return false;
156
+ const document = element.ownerDocument;
157
+ if (document === home) return true;
158
+ const frame = document.defaultView?.frameElement;
159
+ return frame == null || isVisibleInLayout(frame, home);
160
+ }
161
+ function isVisibleInOwnDocument(element) {
162
+ const view = element.ownerDocument.defaultView;
163
+ if (view == null) return false;
164
+ const style = view.getComputedStyle(element);
165
+ if (style.display === "contents") {
166
+ return [...element.children].some((child) => isVisibleInOwnDocument(child));
167
+ }
168
+ if (style.visibility !== "visible") return false;
169
+ const box = element.getBoundingClientRect();
170
+ return box.width > 0 && box.height > 0;
171
+ }
172
+
173
+ // src/box.ts
174
+ function boxInOwnDocument(element) {
175
+ if (element.getClientRects().length === 0) return null;
176
+ const { x, y, width, height } = element.getBoundingClientRect();
177
+ return { x, y, width, height };
178
+ }
179
+ function frameOrigin(iframe) {
180
+ const { x, y } = iframe.getBoundingClientRect();
181
+ const style = iframe.ownerDocument.defaultView?.getComputedStyle(iframe);
182
+ const px = (value) => Number.parseFloat(value ?? "") || 0;
183
+ return {
184
+ x: x + px(style?.borderLeftWidth) + px(style?.paddingLeft),
185
+ y: y + px(style?.borderTopWidth) + px(style?.paddingTop)
186
+ };
187
+ }
188
+ function boundingBoxOf(element, home) {
189
+ const box = boxInOwnDocument(element);
190
+ if (box === null) return { x: 0, y: 0, width: 0, height: 0 };
191
+ let document = element.ownerDocument;
192
+ while (document !== home) {
193
+ const frame = document.defaultView?.frameElement;
194
+ if (frame == null) break;
195
+ const origin = frameOrigin(frame);
196
+ box.x += origin.x;
197
+ box.y += origin.y;
198
+ document = frame.ownerDocument;
199
+ }
200
+ return box;
201
+ }
202
+
203
+ // src/files.ts
204
+ function fileInputOf(element) {
205
+ const target = element.localName === "label" ? element.control : element;
206
+ if (target === null) return "<label> with no control";
207
+ if (target.localName !== "input") return `<${target.localName}>`;
208
+ const input = target;
209
+ return input.type === "file" ? input : `<input type="${input.type}">`;
210
+ }
211
+
212
+ // src/global-name.ts
213
+ var PAGE_API_GLOBAL = "__harnessedResolve";
214
+
215
+ // src/wire.ts
216
+ function isRegExp(value) {
217
+ return Object.prototype.toString.call(value) === "[object RegExp]";
218
+ }
219
+ function encodeValue(value) {
220
+ if (isRegExp(value)) return { $regexp: value.source, flags: value.flags };
221
+ if (Array.isArray(value)) return value.map(encodeValue);
222
+ if (typeof value === "object" && value !== null) {
223
+ return Object.fromEntries(
224
+ Object.entries(value).map(([key, inner]) => [key, encodeValue(inner)])
225
+ );
226
+ }
227
+ return value;
228
+ }
229
+ function isWireRegExp(value) {
230
+ return typeof value === "object" && value !== null && typeof value.$regexp === "string" && typeof value.flags === "string";
231
+ }
232
+ function decodeValue(value) {
233
+ if (isRegExp(value)) return new RegExp(value.source, value.flags);
234
+ if (isWireRegExp(value)) return new RegExp(value.$regexp, value.flags);
235
+ if (Array.isArray(value)) return value.map(decodeValue);
236
+ if (typeof value === "object" && value !== null) {
237
+ return Object.fromEntries(
238
+ Object.entries(value).map(([key, inner]) => [key, decodeValue(inner)])
239
+ );
240
+ }
241
+ return value;
242
+ }
243
+ function encodeSelector(selector) {
244
+ return encodeValue(selector);
245
+ }
246
+ function decodeSelector(selector) {
247
+ return decodeValue(selector);
248
+ }
249
+
250
+ // src/page-api.ts
251
+ function createPageApi(document) {
252
+ const start = (root) => root ?? document.body;
253
+ const apply = (options) => core.configure({ testIdAttribute: options.testIdAttribute });
254
+ const decode = (scope, selector) => [
255
+ scope.map(decodeSelector),
256
+ decodeSelector(selector)
257
+ ];
258
+ return {
259
+ async count(root, scope, selector, options) {
260
+ apply(options);
261
+ const [steps, target] = decode(scope, selector);
262
+ return countAll(start(root), steps, target, options.timeout);
263
+ },
264
+ async one(root, scope, selector, options) {
265
+ apply(options);
266
+ const [steps, target] = decode(scope, selector);
267
+ return resolveOne(start(root), steps, target, options.timeout);
268
+ },
269
+ async all(root, scope, selector, options) {
270
+ apply(options);
271
+ const [steps, target] = decode(scope, selector);
272
+ return resolveAll(start(root), steps, target, options.timeout);
273
+ },
274
+ oneNow(root, scope, selector, options) {
275
+ apply(options);
276
+ const [steps, target] = decode(scope, selector);
277
+ return resolveOneNow(start(root), steps, target);
278
+ },
279
+ allNow(root, scope, selector, options) {
280
+ apply(options);
281
+ const [steps, target] = decode(scope, selector);
282
+ return resolveAllNow(start(root), steps, target);
283
+ },
284
+ visible(element) {
285
+ return isVisibleInLayout(element, element.ownerDocument);
286
+ },
287
+ box: boxInOwnDocument,
288
+ origin: frameOrigin,
289
+ fileTarget(element) {
290
+ const input = fileInputOf(element);
291
+ return typeof input === "string" ? input : { multiple: input.multiple };
292
+ }
293
+ };
294
+ }
295
+
296
+ exports.FrameEntryError = FrameEntryError;
297
+ exports.PAGE_API_GLOBAL = PAGE_API_GLOBAL;
298
+ exports.boundingBoxOf = boundingBoxOf;
299
+ exports.boxInOwnDocument = boxInOwnDocument;
300
+ exports.countAll = countAll;
301
+ exports.createPageApi = createPageApi;
302
+ exports.decodeSelector = decodeSelector;
303
+ exports.encodeSelector = encodeSelector;
304
+ exports.fileInputOf = fileInputOf;
305
+ exports.frameOrigin = frameOrigin;
306
+ exports.isVisibleInLayout = isVisibleInLayout;
307
+ exports.queryAll = queryAll;
308
+ exports.resolveAll = resolveAll;
309
+ exports.resolveAllNow = resolveAllNow;
310
+ exports.resolveOne = resolveOne;
311
+ exports.resolveOneNow = resolveOneNow;
312
+ exports.resolveScope = resolveScope;
313
+ exports.resolveScopeNow = resolveScopeNow;
314
+ //# sourceMappingURL=index.cjs.map
315
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/resolve.ts","../src/visible.ts","../src/box.ts","../src/files.ts","../src/global-name.ts","../src/wire.ts","../src/page-api.ts"],"names":["testIdSync","configureTestingLibrary","buildQueries","testIdPresenceSelector","getConfig","within","indexOutOfRange","strictViolation","timeoutFor","describeScope","configure"],"mappings":";;;;;;AAiBA,IAAM,mBAAA,GAAsBA,eAAA;AAAA,EAAW,CAAA,eAAA,KACrCC,aAAA,CAAwB,EAAE,eAAA,EAAiB;AAC7C,CAAA;AAGA,SAAS,kBAAA,CAAmB,WAAwB,GAAA,EAA4B;AAC9E,EAAA,OAAO,CAAC,GAAG,SAAA,CAAU,gBAAA,CAA8B,GAAG,CAAC,CAAA;AACzD;AAIA,IAAM,OAAO,iBAAiB,CAAA,GAAIC,gBAAA;AAAA,EAChC,kBAAA;AAAA,EACA,CAAC,UAAA,EAAY,GAAA,KAAgB,CAAA,4BAAA,EAA+B,GAAG,CAAA,CAAA;AAAA,EAC/D,CAAC,UAAA,EAAY,GAAA,KAAgB,CAAA,8BAAA,EAAiC,GAAG,CAAA;AACnE,CAAA;AAGA,SAAS,WAAW,QAAA,EAA6D;AAC/E,EAAA,OA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A,GAAI,MAAA,CAAO,OAAO,QAAQ,CAAA;AAC9C,MAAA,OAAO,aAAA,CAAc,KAAA,CAAM,IAAI,CAAA,EAAG,OAAO,MAAM,CAAA;AAAA,IACjD,CAAA;AAAA,IACA,MAAA,CAAO,IAAA,EAAM,KAAA,EAAO,QAAA,EAAU,OAAA,EAAS;AACrC,MAAA,KAAA,CAAM,OAAO,CAAA;AACb,MAAA,MAAM,CAAC,KAAA,EAAO,MAAM,CAAA,GAAI,MAAA,CAAO,OAAO,QAAQ,CAAA;AAC9C,MAAA,OAAO,aAAA,CAAc,KAAA,CAAM,IAAI,CAAA,EAAG,OAAO,MAAM,CAAA;AAAA,IACjD,CAAA;AAAA,IACA,QAAQ,OAAA,EAAS;AACf,MAAA,OAAO,iBAAA,CAAkB,OAAA,EAAS,OAAA,CAAQ,aAAa,CAAA;AAAA,IACzD,CAAA;AAAA,IACA,GAAA,EAAK,gBAAA;AAAA,IACL,MAAA,EAAQ,WAAA;AAAA,IACR,WAAW,OAAA,EAAS;AAClB,MAAA,MAAM,KAAA,GAAQ,YAAY,OAAO,CAAA;AACjC,MAAA,OAAO,OAAO,KAAA,KAAU,QAAA,GAAW,QAAQ,EAAE,QAAA,EAAU,MAAM,QAAA,EAAS;AAAA,IACxE;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import {\n describeScope,\n getConfig,\n indexOutOfRange,\n strictViolation,\n testIdPresenceSelector,\n testIdSync,\n timeoutFor,\n} from '@harnessed-ts/core'\nimport type { Selector } from '@harnessed-ts/core'\nimport { buildQueries, configure as configureTestingLibrary, within } from '@testing-library/dom'\nimport type { ByRoleMatcher } from '@testing-library/dom'\n\n/** `Selector` keeps `role` a plain string so it stays driver-agnostic; each driver\n * casts it to its own role union at the boundary. */\ntype RoleName = ByRoleMatcher\n\nconst syncTestIdAttribute = testIdSync(testIdAttribute =>\n configureTestingLibrary({ testIdAttribute }),\n)\n\n/** Descendants carrying a presence-style test id: `[data-test-x]`, any value. */\nfunction queryAllByPresence(container: HTMLElement, css: string): HTMLElement[] {\n return [...container.querySelectorAll<HTMLElement>(css)]\n}\n\n// Built the way Testing Library builds its own queries, so a presence test id\n// waits, and reports \"Unable to find …\" when it gives up, exactly as `*ByTestId` does.\nconst [, , , findAllByPresence] = buildQueries(\n queryAllByPresence,\n (_container, css: string) => `Found multiple elements by: ${css}`,\n (_container, css: string) => `Unable to find an element by: ${css}`,\n)\n\n/** The presence selector for a test id under a `data-test-*` config, if that is the mode. */\nfunction presenceOf(selector: Selector & { type: 'testId' }): string | undefined {\n return testIdPresenceSelector(getConfig().testIdAttribute, selector.testId)\n}\n\n/** Every match for one selector, without waiting. Zero is an answer. */\nexport function queryAll(root: HTMLElement, selector: Selector): HTMLElement[] {\n syncTestIdAttribute()\n const scoped = within(root)\n switch (selector.type) {\n case 'role':\n return scoped.queryAllByRole(selector.role as RoleName, selector.options)\n case 'label':\n return scoped.queryAllByLabelText(selector.text)\n case 'testId': {\n const css = presenceOf(selector)\n return css === undefined\n ? scoped.queryAllByTestId(selector.testId)\n : queryAllByPresence(root, css)\n }\n case 'text':\n return scoped.queryAllByText(selector.text)\n case 'placeholder':\n return scoped.queryAllByPlaceholderText(selector.text)\n }\n}\n\n/**\n * One match, waiting for it to appear. Strict: several matches is an error.\n *\n * The non-waiting query runs first. Testing Library's `findBy*` is\n * `waitFor(getBy*)`, so a \"found multiple elements\" error is retried for the full\n * timeout before surfacing — but more than one match never becomes one by\n * waiting, and Playwright rejects at once. Checking up front keeps the two\n * drivers in step and turns a timeout into an immediate, readable failure.\n *\n * The check is applied to the waited result too. Otherwise the guarantee would\n * hold only for nodes that happened to be on screen already, and a target that\n * renders late as two nodes would still sit out the whole timeout.\n */\nasync function findOne(\n root: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n timeout?: number,\n): Promise<HTMLElement> {\n syncTestIdAttribute()\n\n const immediate = queryAll(root, selector)\n const resolved = immediate.length > 0 ? immediate : await findAll(root, selector, timeout)\n return pick(resolved, scope, selector)\n}\n\n/** The one node a strict operation takes from a set of matches. */\nfunction pick(\n resolved: readonly HTMLElement[],\n scope: readonly Selector[],\n selector: Selector,\n): HTMLElement {\n if (selector.nth !== undefined) {\n const found = resolved[selector.nth]\n if (found === undefined) {\n throw indexOutOfRange(selector.nth, resolved.length, scope, selector)\n }\n return found\n }\n\n if (resolved.length > 1) throw strictViolation(resolved.length, scope, selector)\n return resolved[0]!\n}\n\nasync function findAll(\n root: HTMLElement,\n selector: Selector,\n timeout?: number,\n): Promise<HTMLElement[]> {\n syncTestIdAttribute()\n const scoped = within(root)\n const options = { timeout: timeoutFor(timeout) }\n switch (selector.type) {\n case 'role':\n return scoped.findAllByRole(selector.role as RoleName, selector.options, options)\n case 'label':\n return scoped.findAllByLabelText(selector.text, undefined, options)\n case 'testId': {\n const css = presenceOf(selector)\n return css === undefined\n ? scoped.findAllByTestId(selector.testId, undefined, options)\n : findAllByPresence(root, css, undefined, options)\n }\n case 'text':\n return scoped.findAllByText(selector.text, undefined, options)\n case 'placeholder':\n return scoped.findAllByPlaceholderText(selector.text, undefined, options)\n }\n}\n\n/**\n * Walks the scope chain down to the element the final selector is queried within.\n * Waiting is correct here: a container that has not rendered yet is not the same\n * thing as a target that is absent.\n */\nexport async function resolveScope(\n container: HTMLElement,\n scope: readonly Selector[],\n timeout?: number,\n): Promise<HTMLElement> {\n let current = container\n for (const [index, step] of scope.entries()) {\n // Each link is reported with the path that reached it, so an ambiguous\n // container names the container rather than the leaf you asked for.\n const path = scope.slice(0, index)\n const found = await findOne(current, path, step, timeout)\n current = step.frame === true ? frameBody(found, path, step) : found\n }\n return current\n}\n\n/** A frame link that cannot be entered — a wiring mistake, never \"not rendered yet\". */\nexport class FrameEntryError extends Error {\n override name = 'FrameEntryError'\n}\n\n/**\n * The body a frame link's children are queried within. Only a same-origin frame\n * exposes one — a cross-origin document is unreachable from script by design, and\n * no amount of waiting changes that, so this refuses at once.\n */\nfunction frameBody(\n element: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n): HTMLElement {\n // localName, not instanceof: a frame nested in a frame belongs to another realm.\n if (element.localName !== 'iframe') {\n throw new FrameEntryError(\n `harnessed: ${describeScope(scope, selector)} is marked as a frame but is a <${element.localName}>, not an <iframe>.`,\n )\n }\n const body = (element as HTMLIFrameElement).contentDocument?.body\n if (body == null) {\n throw new FrameEntryError(\n `harnessed: ${describeScope(scope, selector)} has no reachable document: it is ` +\n `cross-origin, or its document has no body. The dom driver enters same-origin ` +\n `frames only; drive a cross-origin one with a browser driver.`,\n )\n }\n return body\n}\n\n/** The single node a strict operation acts on. */\nexport async function resolveOne(\n container: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n timeout?: number,\n): Promise<HTMLElement> {\n const root = await resolveScope(container, scope, timeout)\n // The errors already carry the scope path, so there is nothing to wrap.\n return findOne(root, scope, selector, timeout)\n}\n\n/**\n * How many nodes match. The scope chain still waits, but the final count uses the\n * non-waiting query so that zero answers immediately rather than throwing after a\n * retry timeout. This is the behaviour Playwright already had.\n */\nexport async function countAll(\n container: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n timeout?: number,\n): Promise<number> {\n let root: HTMLElement\n try {\n root = await resolveScope(container, scope, timeout)\n } catch (error) {\n if (error instanceof FrameEntryError) throw error\n // The scope itself is not on screen, so nothing inside it can be either.\n return 0\n }\n const matches = queryAll(root, selector)\n if (selector.nth === undefined) return matches.length\n return matches[selector.nth] === undefined ? 0 : 1\n}\n\n// --- without waiting ------------------------------------------------------\n//\n// For a driver whose own runtime does the retrying — TestCafe's Selector, a\n// remote driver polling from Node — every lookup has to answer at once. These\n// apply exactly the same strictness, index, and frame rules as the waiting\n// forms above: anything those reject at once, these throw. The one difference\n// is that \"nothing matches yet\" is `null` instead of a wait.\n\n/** The scope chain's innermost element now, or `null` if a link is not on screen. */\nexport function resolveScopeNow(\n container: HTMLElement,\n scope: readonly Selector[],\n): HTMLElement | null {\n let current = container\n for (const [index, step] of scope.entries()) {\n const path = scope.slice(0, index)\n const matches = queryAll(current, step)\n if (matches.length === 0) return null\n const found = pick(matches, path, step)\n current = step.frame === true ? frameBody(found, path, step) : found\n }\n return current\n}\n\n/** The single node a strict operation acts on now, or `null` if it is not on screen. */\nexport function resolveOneNow(\n container: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n): HTMLElement | null {\n const root = resolveScopeNow(container, scope)\n if (root === null) return null\n const matches = queryAll(root, selector)\n if (matches.length === 0) return null\n return pick(matches, scope, selector)\n}\n\n/**\n * Every match now, agreeing with `countAll` on every scope it cannot resolve:\n * an absent or ambiguous scope is an empty list, and only a frame that cannot\n * be entered throws.\n */\nexport function resolveAllNow(\n container: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n): HTMLElement[] {\n let root: HTMLElement | null\n try {\n root = resolveScopeNow(container, scope)\n } catch (error) {\n if (error instanceof FrameEntryError) throw error\n return []\n }\n if (root === null) return []\n const matches = queryAll(root, selector)\n if (selector.nth === undefined) return matches\n const found = matches[selector.nth]\n return found === undefined ? [] : [found]\n}\n\n/**\n * Every match for a list operation: the scope waits, the list does not, and\n * `nth` is ignored — each result is addressed by its own index afterwards. The\n * one definition of \"the list\" for in-process and injected drivers alike.\n */\nexport async function resolveAll(\n container: HTMLElement,\n scope: readonly Selector[],\n selector: Selector,\n timeout?: number,\n): Promise<HTMLElement[]> {\n return queryAll(await resolveScope(container, scope, timeout), selector)\n}\n","/**\n * Whether an element is visible by layout — Playwright's definition, for drivers\n * that run in a real browser beside the page (Vitest browser mode, Ember, Cypress).\n * jsdom computes no layout, so the dom driver cannot use this and reads computed\n * style instead.\n *\n * Visible means a non-empty box that `visibility` does not hide. `display: none`\n * anywhere above gives an empty box, so it needs no check of its own. Opacity\n * does not count: a transparent box is still there to click, and Playwright\n * reports it visible.\n *\n * Inside a frame, the iframe has to be visible too — a hidden frame hides its\n * content. The walk crosses frames up to `home` (by default, every reachable\n * one), so a driver passes its own document to stop at the frames its scope\n * actually entered.\n */\nexport function isVisibleInLayout(element: Element, home?: Document): boolean {\n if (!isVisibleInOwnDocument(element)) return false\n const document = element.ownerDocument\n if (document === home) return true\n // Null at the top, and for a cross-origin parent, which script cannot see into.\n const frame = document.defaultView?.frameElement\n return frame == null || isVisibleInLayout(frame, home)\n}\n\nfunction isVisibleInOwnDocument(element: Element): boolean {\n const view = element.ownerDocument.defaultView\n // A node with no window is detached from any rendering.\n if (view == null) return false\n const style = view.getComputedStyle(element)\n // `display: contents` draws no box of its own, so it is as visible as what it\n // contains.\n if (style.display === 'contents') {\n return [...element.children].some(child => isVisibleInOwnDocument(child))\n }\n if (style.visibility !== 'visible') return false\n const box = element.getBoundingClientRect()\n return box.width > 0 && box.height > 0\n}\n","import type { BoundingBox } from '@harnessed-ts/core'\n\n/** A point in a document's viewport, in CSS pixels. */\nexport interface Point {\n x: number\n y: number\n}\n\n/**\n * An element's border box in its own document's viewport, or `null` when it\n * renders no box at all (`display: none`, or anything inside it). Every driver\n * reads `null` as all zeros, which is what Playwright and Puppeteer — whose\n * native boxes are `null` there — are normalised to.\n */\nexport function boxInOwnDocument(element: Element): BoundingBox | null {\n if (element.getClientRects().length === 0) return null\n const { x, y, width, height } = element.getBoundingClientRect()\n return { x, y, width, height }\n}\n\n/**\n * Where an iframe's document is drawn, in the iframe's own document: the corner\n * of its content box, inside its border and padding. The same offset Playwright\n * and Puppeteer add when they report a framed element's box.\n */\nexport function frameOrigin(iframe: Element): Point {\n const { x, y } = iframe.getBoundingClientRect()\n const style = iframe.ownerDocument.defaultView?.getComputedStyle(iframe)\n const px = (value: string | undefined): number => Number.parseFloat(value ?? '') || 0\n return {\n x: x + px(style?.borderLeftWidth) + px(style?.paddingLeft),\n y: y + px(style?.borderTopWidth) + px(style?.paddingTop),\n }\n}\n\n/**\n * An element's box relative to the viewport of `home` — the document the\n * driver drives — adding the origin of every same-origin frame crossed on the\n * way up. For drivers that resolve inside the page; under jsdom everything is\n * zeros, because jsdom computes no layout.\n */\nexport function boundingBoxOf(element: Element, home?: Document): BoundingBox {\n const box = boxInOwnDocument(element)\n if (box === null) return { x: 0, y: 0, width: 0, height: 0 }\n let document = element.ownerDocument\n while (document !== home) {\n // Null at the top, and for a cross-origin parent, which script cannot see into.\n const frame = document.defaultView?.frameElement\n if (frame == null) break\n const origin = frameOrigin(frame)\n box.x += origin.x\n box.y += origin.y\n document = frame.ownerDocument\n }\n return box\n}\n","/**\n * The file input an upload sets: the element itself, or the control of a\n * `<label>` — user-event's and Playwright's rule both. Anything else comes back\n * described as markup, for core's `checkFileTarget` to refuse in one wording.\n */\nexport function fileInputOf(element: Element): HTMLInputElement | string {\n const target =\n element.localName === 'label' ? (element as HTMLLabelElement).control : (element as Element)\n if (target === null) return '<label> with no control'\n if (target.localName !== 'input') return `<${target.localName}>`\n const input = target as HTMLInputElement\n return input.type === 'file' ? input : `<input type=\"${input.type}\">`\n}\n","/**\n * Where the injected build installs itself on the page's `window`. A leaf\n * module with no imports, so the Node-side `inject` entry can name it without\n * pulling in the resolver and Testing Library, which only run in the page.\n */\nexport const PAGE_API_GLOBAL = '__harnessedResolve'\n","import type { Selector } from '@harnessed-ts/core'\n\n/**\n * A `Selector` as it crosses into a remote page. Everything in one is JSON-safe\n * except a RegExp — `role('button', { name: /save/i })` — which WebDriver,\n * CDP and TestCafe all serialise to `{}`. This encodes them as tagged objects\n * on the way out, and the page API decodes them on the way in.\n */\nexport interface WireRegExp {\n $regexp: string\n flags: string\n}\n\nexport type WireSelector = Record<string, unknown>\n\n/**\n * Not `instanceof`: a selector built in the test process and handed to a page\n * in the same JS engine (jsdom, a same-origin frame) carries the other realm's\n * RegExp, which `instanceof` does not recognise.\n */\nfunction isRegExp(value: unknown): value is RegExp {\n return Object.prototype.toString.call(value) === '[object RegExp]'\n}\n\nfunction encodeValue(value: unknown): unknown {\n if (isRegExp(value)) return { $regexp: value.source, flags: value.flags }\n if (Array.isArray(value)) return value.map(encodeValue)\n if (typeof value === 'object' && value !== null) {\n return Object.fromEntries(\n Object.entries(value).map(([key, inner]) => [key, encodeValue(inner)]),\n )\n }\n return value\n}\n\nfunction isWireRegExp(value: unknown): value is WireRegExp {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as WireRegExp).$regexp === 'string' &&\n typeof (value as WireRegExp).flags === 'string'\n )\n}\n\nfunction decodeValue(value: unknown): unknown {\n if (isRegExp(value)) return new RegExp(value.source, value.flags)\n if (isWireRegExp(value)) return new RegExp(value.$regexp, value.flags)\n if (Array.isArray(value)) return value.map(decodeValue)\n if (typeof value === 'object' && value !== null) {\n return Object.fromEntries(\n Object.entries(value).map(([key, inner]) => [key, decodeValue(inner)]),\n )\n }\n return value\n}\n\nexport function encodeSelector(selector: Selector): WireSelector {\n return encodeValue(selector) as WireSelector\n}\n\n/** Idempotent: a selector that never left the process decodes to itself. */\nexport function decodeSelector(selector: Selector | WireSelector): Selector {\n return decodeValue(selector) as Selector\n}\n","import { configure } from '@harnessed-ts/core'\nimport type { BoundingBox, FileTarget, Selector } from '@harnessed-ts/core'\nimport { boxInOwnDocument, frameOrigin } from './box'\nimport type { Point } from './box'\nimport { fileInputOf } from './files'\nimport { PAGE_API_GLOBAL } from './global-name'\nimport { countAll, resolveAll, resolveAllNow, resolveOne, resolveOneNow } from './resolve'\nimport { isVisibleInLayout } from './visible'\nimport { decodeSelector } from './wire'\nimport type { WireSelector } from './wire'\n\nexport { PAGE_API_GLOBAL }\n\n/**\n * Settings a remote driver passes on every call. The page has no access to the\n * test process's `configure()`, so the runtime config travels with the call\n * rather than being pushed once.\n */\n/** A selector as handed over the wire, or as-is when caller and page share a realm. */\ntype Wire = Selector | WireSelector\n\nexport interface PageApiOptions {\n testIdAttribute: string\n timeout: number\n}\n\n/**\n * The resolver as seen from inside a page a driver does not share a realm with\n * — WebdriverIO, Puppeteer, TestCafe. Every argument is serialisable except\n * `root`, which is an element handle the driver passes back in (or `null` for\n * the document body).\n *\n * The same functions back the dom driver, so role, label, strictness, index\n * and frame semantics cannot differ between a driver resolving in-process and\n * one resolving through this.\n */\nexport interface PageApi {\n /** How many nodes match. The scope waits; the count does not. */\n count(\n root: Element | null,\n scope: Wire[],\n selector: Wire,\n options: PageApiOptions,\n ): Promise<number>\n /** The single node a strict operation acts on, waiting for it. */\n one(\n root: Element | null,\n scope: Wire[],\n selector: Wire,\n options: PageApiOptions,\n ): Promise<Element>\n /** Every match, after waiting for the scope. `nth` is ignored, as for any list. */\n all(\n root: Element | null,\n scope: Wire[],\n selector: Wire,\n options: PageApiOptions,\n ): Promise<Element[]>\n /** The single node now, or `null`. For runtimes that do their own retrying. */\n oneNow(\n root: Element | null,\n scope: Wire[],\n selector: Wire,\n options: PageApiOptions,\n ): Element | null\n /** Every match now. */\n allNow(root: Element | null, scope: Wire[], selector: Wire, options: PageApiOptions): Element[]\n /**\n * Whether an element is visible by layout, within its own document only. A\n * driver that enters frames from outside the page asks about each iframe it\n * crossed in that iframe's own document, which also covers a cross-origin\n * frame no in-page walk could cross.\n */\n visible(element: Element): boolean\n /**\n * The element's box in its own document's viewport, or `null` when it draws\n * none. A driver that enters frames from outside adds each crossed frame's\n * `origin` itself.\n */\n box(element: Element): BoundingBox | null\n /** Where an iframe's document is drawn, in the iframe's own document. */\n origin(iframe: Element): Point\n /** What an upload would set: the file input's `multiple`, or what the element is instead. */\n fileTarget(element: Element): FileTarget\n}\n\nexport function createPageApi(document: Document): PageApi {\n const start = (root: Element | null): HTMLElement => (root ?? document.body) as HTMLElement\n // Only the test-id attribute: every waiting call passes its timeout\n // explicitly. Note this writes the page's harnessed config, so the API belongs\n // in a page that runs no harnesses of its own — which is every remote page.\n const apply = (options: PageApiOptions): void =>\n configure({ testIdAttribute: options.testIdAttribute })\n const decode = (scope: Wire[], selector: Wire): [Selector[], Selector] => [\n scope.map(decodeSelector),\n decodeSelector(selector),\n ]\n\n return {\n async count(root, scope, selector, options) {\n apply(options)\n const [steps, target] = decode(scope, selector)\n return countAll(start(root), steps, target, options.timeout)\n },\n async one(root, scope, selector, options) {\n apply(options)\n const [steps, target] = decode(scope, selector)\n return resolveOne(start(root), steps, target, options.timeout)\n },\n async all(root, scope, selector, options) {\n apply(options)\n const [steps, target] = decode(scope, selector)\n return resolveAll(start(root), steps, target, options.timeout)\n },\n oneNow(root, scope, selector, options) {\n apply(options)\n const [steps, target] = decode(scope, selector)\n return resolveOneNow(start(root), steps, target)\n },\n allNow(root, scope, selector, options) {\n apply(options)\n const [steps, target] = decode(scope, selector)\n return resolveAllNow(start(root), steps, target)\n },\n visible(element) {\n return isVisibleInLayout(element, element.ownerDocument)\n },\n box: boxInOwnDocument,\n origin: frameOrigin,\n fileTarget(element) {\n const input = fileInputOf(element)\n return typeof input === 'string' ? input : { multiple: input.multiple }\n },\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ export { countAll, resolveAll, FrameEntryError, queryAll, resolveAllNow, resolveOne, resolveOneNow, resolveScope, resolveScopeNow, } from './resolve';
2
+ export { isVisibleInLayout } from './visible';
3
+ export { boundingBoxOf, boxInOwnDocument, frameOrigin } from './box';
4
+ export type { Point } from './box';
5
+ export { fileInputOf } from './files';
6
+ export { createPageApi, PAGE_API_GLOBAL } from './page-api';
7
+ export type { PageApi, PageApiOptions } from './page-api';
8
+ export { decodeSelector, encodeSelector } from './wire';
9
+ export type { WireRegExp, WireSelector } from './wire';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,UAAU,EACV,eAAe,EACf,QAAQ,EACR,aAAa,EACb,UAAU,EACV,aAAa,EACb,YAAY,EACZ,eAAe,GAChB,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACpE,YAAY,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC3D,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AACvD,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA"}