@harnessed-ts/cypress 0.0.0-stage → 0.7.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 +97 -0
- package/LICENSE +21 -0
- package/README.md +28 -2
- package/dist/chunk-CGA7IP66.js +526 -0
- package/dist/chunk-CGA7IP66.js.map +1 -0
- package/dist/commands.d.ts +70 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/cypress-query.d.ts +71 -0
- package/dist/cypress-query.d.ts.map +1 -0
- package/dist/driver-id.d.ts +3 -0
- package/dist/driver-id.d.ts.map +1 -0
- package/dist/env.d.ts +44 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/index.cjs +535 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/navigation.d.ts +2 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/real-events.d.ts +18 -0
- package/dist/real-events.d.ts.map +1 -0
- package/dist/support.cjs +537 -0
- package/dist/support.cjs.map +1 -0
- package/dist/support.d.ts +2 -0
- package/dist/support.d.ts.map +1 -0
- package/dist/support.js +6 -0
- package/dist/support.js.map +1 -0
- package/package.json +75 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# @harnessed-ts/cypress
|
|
2
|
+
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ec06bdf: Vue, Solid, Svelte and Angular join React and Ember as conformance-tested UI frameworks, and node:test, Bun and Nightwatch join the runners.
|
|
8
|
+
|
|
9
|
+
New packages: `@harnessed-ts/nightwatch` drives Nightwatch 3 through the injected resolver, under Nightwatch's own runner and its Mocha runner, in end-to-end and component tests (`@nightwatch/react`, `@nightwatch/vue`), with cross-origin frames. `@harnessed-ts/angular` drives zoneless Angular 21+: every action settles at `fixture.whenStable()`, or at the `ApplicationRef`'s for an app bootstrapped without TestBed, and `goto()` drives a provided router.
|
|
10
|
+
|
|
11
|
+
`@harnessed-ts/core/register` loads TypeScript harnesses under `node --import`: esbuild strips the types, lowers standard decorators and `accessor`, and compiles JSX. `@harnessed-ts/core/bun` does the same as a `bun test` preload, so harnesses keep the standard decorator protocol whatever `experimentalDecorators` the tsconfig sets.
|
|
12
|
+
|
|
13
|
+
`@harnessed-ts/dom/matchers/bun` registers the matchers with `bun:test`. The dom driver runs on happy-dom too: it focuses the frames leading to an interaction's target, finds a frame's `<iframe>` where `frameElement` is unset, and reads a select's selection off `options`.
|
|
14
|
+
|
|
15
|
+
`@harnessed-ts/resolve/webdriver` holds the WebDriver half of injected resolution, shared by the WebdriverIO and Nightwatch drivers. `@harnessed-ts/gherkin/nightwatch` adapts the cucumber-js world to Nightwatch's Cucumber runner.
|
|
16
|
+
|
|
17
|
+
`@harnessed-ts/playwright`, and `@harnessed-ts/cypress` under `realEvents`, give the page a task after every action, so a read straight after it sees what a framework that renders on a timer (zoneless Angular) has rendered. The injectable resolver installs on the page's `window` rather than the script's global, which under Firefox's WebDriver is a sandbox in front of it.
|
|
18
|
+
|
|
19
|
+
`@harnessed-ts/conformance` exports `fixtureParity()`, the per-view parity check a port of the fixture to another framework runs, naming the first place its markup parts from the React original; it detects a simulated DOM from the DOM's own window.
|
|
20
|
+
|
|
21
|
+
`@harnessed-ts/eslint-plugin` recognises Nightwatch's, Angular's and Vue Test Utils' raw queries, and looks in `nightwatch/` by default. `npx @harnessed-ts/claude install` detects Angular, Nightwatch, node:test and Bun.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [ec06bdf]
|
|
26
|
+
- @harnessed-ts/core@0.7.0
|
|
27
|
+
- @harnessed-ts/resolve@0.7.0
|
|
28
|
+
|
|
29
|
+
## 0.6.0
|
|
30
|
+
|
|
31
|
+
### Minor Changes
|
|
32
|
+
|
|
33
|
+
- 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.
|
|
34
|
+
|
|
35
|
+
`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.
|
|
36
|
+
|
|
37
|
+
`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.
|
|
38
|
+
|
|
39
|
+
`Query` gains two abstract members, so a driver outside this repo implements both to keep compiling; the conformance catalog pins all three changes.
|
|
40
|
+
|
|
41
|
+
`@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.
|
|
42
|
+
|
|
43
|
+
`npx @harnessed-ts/claude install` detects ember-test-selectors attributes (in `.gts`, `.gjs` and `.hbs` files too) and writes `testIdAttribute: 'data-test-*'`.
|
|
44
|
+
|
|
45
|
+
`@harnessed-ts/storybook` writes and finds its story-ready marker under a `data-test-*` config, where `StoryPage` waits for it.
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [e324e94]
|
|
50
|
+
- @harnessed-ts/core@0.6.0
|
|
51
|
+
- @harnessed-ts/resolve@0.6.0
|
|
52
|
+
|
|
53
|
+
## 0.5.0
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- @harnessed-ts/core@0.5.0
|
|
58
|
+
- @harnessed-ts/resolve@0.5.0
|
|
59
|
+
|
|
60
|
+
## 0.4.0
|
|
61
|
+
|
|
62
|
+
### Minor Changes
|
|
63
|
+
|
|
64
|
+
- 9666a3d: A new Cypress driver for e2e and component tests: `cy.harness(Cls, async h => …)` runs a harness inside one command against the application under test, `cy.visitPage(Page, params)` visits a page's `urlFor()` and waits for it to be ready, and `goto()` works inside the bridge in e2e tests. Interactions use user-event by default, or trusted Chrome DevTools Protocol input with `realEvents: true` on Chromium.
|
|
65
|
+
- 1823546: `isVisible()`, `waitFor('visible')` and `waitFor('hidden')` on a target matching
|
|
66
|
+
several nodes now reject with the shared strict-mode violation, at once, under
|
|
67
|
+
every driver. The dom, Ember, Vitest browser mode and Cypress drivers answered
|
|
68
|
+
`false` from `isVisible()`, waited out the timeout in `waitFor('visible')`, and —
|
|
69
|
+
worse — resolved `waitFor('hidden')` at once, passing a wait for three rendered
|
|
70
|
+
nodes to disappear; Playwright's waits raised its own wording instead of the
|
|
71
|
+
shared one. An `nth()`
|
|
72
|
+
past the last match answers `false` from `isVisible()` and counts as hidden, as it
|
|
73
|
+
does under Playwright — Puppeteer and TestCafe used to reject it as an index out
|
|
74
|
+
of range.
|
|
75
|
+
|
|
76
|
+
Core exports `StrictModeViolation`, the class `strictViolation()` now returns, so a
|
|
77
|
+
driver can tell ambiguity apart from absence. It is the class a caller catches
|
|
78
|
+
under every driver: core also exports `reviveStrictViolation()`, which the
|
|
79
|
+
Puppeteer, WebdriverIO and TestCafe drivers apply to what the page throws, so
|
|
80
|
+
a violation raised in the page arrives as core's class, worded exactly as an
|
|
81
|
+
in-process driver words it. `instanceof StrictModeViolation` checks a brand
|
|
82
|
+
rather than the prototype, so it holds across two copies of core in one page —
|
|
83
|
+
Cypress bundles the support file and each spec separately.
|
|
84
|
+
|
|
85
|
+
`WaitState` now documents the rule it is held to: a state joins only when every
|
|
86
|
+
driver honours it with the same meaning, so a runner's own states — Playwright's
|
|
87
|
+
`attached` and `detached` — stay out of the shared interface.
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- Updated dependencies [9666a3d]
|
|
92
|
+
- Updated dependencies [9666a3d]
|
|
93
|
+
- Updated dependencies [9666a3d]
|
|
94
|
+
- Updated dependencies [9666a3d]
|
|
95
|
+
- Updated dependencies [1823546]
|
|
96
|
+
- @harnessed-ts/core@0.4.0
|
|
97
|
+
- @harnessed-ts/resolve@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,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @harnessed-ts/cypress
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Cypress driver for `@harnessed-ts/core`, for e2e and component tests. Cypress
|
|
4
|
+
commands are enqueued rather than awaited, so a harness runs inside one command —
|
|
5
|
+
`cy.harness` — as plain promises against the application under test.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
// cypress/support/e2e.ts (or component.ts)
|
|
9
|
+
import '@harnessed-ts/cypress/support'
|
|
10
|
+
import { harnessedChai } from '@harnessed-ts/chai'
|
|
11
|
+
chai.use(harnessedChai)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
cy.visitPage(LoginPage)
|
|
16
|
+
cy.harness(LoginFormHarness, async form => {
|
|
17
|
+
await form.fillIn({ email: 'ada@example.com' })
|
|
18
|
+
await expect(form).not.to.be.absent
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Interactions go through `@testing-library/user-event` bound to the AUT document;
|
|
23
|
+
pass `{ realEvents: true }` for trusted Chrome DevTools Protocol input on
|
|
24
|
+
Chromium-family browsers. Never call `cy` commands inside the callback.
|
|
25
|
+
|
|
26
|
+
Full guide, the cross-driver guarantees, and the API: the
|
|
27
|
+
[harnessed README](https://github.com/joegaudet/harnessed#readme).
|
|
28
|
+
|
|
29
|
+
MIT © Joe Gaudet, Jay Seo
|
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
import { registerDriver, registerNavigation, Query, describeScope, nth, checkFileTarget, StrictModeViolation, enabledFrom, checkedFrom, timeoutFor, getConfig } from '@harnessed-ts/core';
|
|
2
|
+
import { resolveOne, resolveAll, fileInputOf, boundingBoxOf, isVisibleInLayout, FrameEntryError, countAll } from '@harnessed-ts/resolve';
|
|
3
|
+
import { waitFor } from '@testing-library/dom';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
5
|
+
|
|
6
|
+
// src/driver-id.ts
|
|
7
|
+
var CYPRESS_DRIVER = "cypress";
|
|
8
|
+
|
|
9
|
+
// src/real-events.ts
|
|
10
|
+
var NAMED_KEYS = {
|
|
11
|
+
Enter: { code: "Enter", keyCode: 13, text: "\r" },
|
|
12
|
+
Tab: { code: "Tab", keyCode: 9 },
|
|
13
|
+
Backspace: { code: "Backspace", keyCode: 8 },
|
|
14
|
+
Delete: { code: "Delete", keyCode: 46 },
|
|
15
|
+
Escape: { code: "Escape", keyCode: 27 },
|
|
16
|
+
Space: { code: "Space", keyCode: 32, text: " " },
|
|
17
|
+
ArrowUp: { code: "ArrowUp", keyCode: 38 },
|
|
18
|
+
ArrowDown: { code: "ArrowDown", keyCode: 40 },
|
|
19
|
+
ArrowLeft: { code: "ArrowLeft", keyCode: 37 },
|
|
20
|
+
ArrowRight: { code: "ArrowRight", keyCode: 39 },
|
|
21
|
+
Home: { code: "Home", keyCode: 36 },
|
|
22
|
+
End: { code: "End", keyCode: 35 },
|
|
23
|
+
PageUp: { code: "PageUp", keyCode: 33 },
|
|
24
|
+
PageDown: { code: "PageDown", keyCode: 34 },
|
|
25
|
+
Insert: { code: "Insert", keyCode: 45 }
|
|
26
|
+
};
|
|
27
|
+
function keyDefinition(key) {
|
|
28
|
+
const named = NAMED_KEYS[key];
|
|
29
|
+
if (named !== void 0) return { key: key === "Space" ? " " : key, ...named };
|
|
30
|
+
if ([...key].length === 1) {
|
|
31
|
+
const upper = key.toUpperCase();
|
|
32
|
+
const code = /[A-Z]/.test(upper) ? `Key${upper}` : /[0-9]/.test(key) ? `Digit${key}` : "";
|
|
33
|
+
const keyCode = /[A-Z0-9]/.test(upper) ? upper.charCodeAt(0) : 0;
|
|
34
|
+
return { key, code, keyCode, text: key };
|
|
35
|
+
}
|
|
36
|
+
throw new Error(
|
|
37
|
+
`harnessed: realEvents cannot press "${key}". It presses single characters and ${Object.keys(NAMED_KEYS).join(", ")}; drop realEvents to press it through user-event.`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
function send(command, params) {
|
|
41
|
+
return Promise.resolve(Cypress.automation("remote:debugger:protocol", { command, params }));
|
|
42
|
+
}
|
|
43
|
+
function requireChromium() {
|
|
44
|
+
if (!Cypress.isBrowser({ family: "chromium" })) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`harnessed: realEvents drives Chrome DevTools Protocol input, which only Chromium-family browsers (Chrome, Edge, Electron) have; this run is in ${Cypress.browser.name}. Leave realEvents off to use user-event there.`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function framesDownTo(target, within) {
|
|
51
|
+
for (const frame of within.querySelectorAll("iframe")) {
|
|
52
|
+
if (frame.contentWindow === target) return [frame];
|
|
53
|
+
const inner = frame.contentDocument;
|
|
54
|
+
const path = inner === null ? null : framesDownTo(target, inner);
|
|
55
|
+
if (path !== null) return [frame, ...path];
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
function centreOf(element) {
|
|
60
|
+
element.scrollIntoView({ block: "center", inline: "center" });
|
|
61
|
+
const box = element.getBoundingClientRect();
|
|
62
|
+
let x = box.left + box.width / 2;
|
|
63
|
+
let y = box.top + box.height / 2;
|
|
64
|
+
const view = element.ownerDocument.defaultView;
|
|
65
|
+
const top = window.top ?? window;
|
|
66
|
+
const frames = view === null || view === top ? [] : framesDownTo(view, top.document) ?? [];
|
|
67
|
+
for (const frame of frames.reverse()) {
|
|
68
|
+
const frameBox = frame.getBoundingClientRect();
|
|
69
|
+
const scale = frame.offsetWidth > 0 ? frameBox.width / frame.offsetWidth : 1;
|
|
70
|
+
const style = frame.ownerDocument.defaultView?.getComputedStyle(frame);
|
|
71
|
+
const insetX = frame.clientLeft + parseFloat(style?.paddingLeft ?? "0");
|
|
72
|
+
const insetY = frame.clientTop + parseFloat(style?.paddingTop ?? "0");
|
|
73
|
+
x = frameBox.left + (insetX + x) * scale;
|
|
74
|
+
y = frameBox.top + (insetY + y) * scale;
|
|
75
|
+
}
|
|
76
|
+
return { x, y };
|
|
77
|
+
}
|
|
78
|
+
async function realHover(element) {
|
|
79
|
+
const { x, y } = centreOf(element);
|
|
80
|
+
await send("Input.dispatchMouseEvent", { type: "mouseMoved", x, y });
|
|
81
|
+
}
|
|
82
|
+
async function realClick(element) {
|
|
83
|
+
const { x, y } = centreOf(element);
|
|
84
|
+
await send("Input.dispatchMouseEvent", { type: "mouseMoved", x, y });
|
|
85
|
+
const press = { x, y, button: "left", clickCount: 1 };
|
|
86
|
+
await send("Input.dispatchMouseEvent", { type: "mousePressed", buttons: 1, ...press });
|
|
87
|
+
await send("Input.dispatchMouseEvent", { type: "mouseReleased", buttons: 0, ...press });
|
|
88
|
+
}
|
|
89
|
+
async function realPress(key) {
|
|
90
|
+
const { text, keyCode, ...definition } = keyDefinition(key);
|
|
91
|
+
const common = { ...definition, windowsVirtualKeyCode: keyCode, nativeVirtualKeyCode: keyCode };
|
|
92
|
+
await send(
|
|
93
|
+
"Input.dispatchKeyEvent",
|
|
94
|
+
text === void 0 ? { type: "rawKeyDown", ...common } : { type: "keyDown", text, unmodifiedText: text, ...common }
|
|
95
|
+
);
|
|
96
|
+
await send("Input.dispatchKeyEvent", { type: "keyUp", ...common });
|
|
97
|
+
}
|
|
98
|
+
async function realInsertText(text) {
|
|
99
|
+
await send("Input.insertText", { text });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/cypress-query.ts
|
|
103
|
+
function toKeyboardInput(key) {
|
|
104
|
+
return key.length === 1 ? key : `{${key}}`;
|
|
105
|
+
}
|
|
106
|
+
var users = /* @__PURE__ */ new WeakMap();
|
|
107
|
+
function userFor(env) {
|
|
108
|
+
const { document } = env;
|
|
109
|
+
const bound = users.get(env);
|
|
110
|
+
if (bound !== void 0 && bound.document === document) return bound.user;
|
|
111
|
+
const user = userEvent.setup({ document });
|
|
112
|
+
users.set(env, { document, user });
|
|
113
|
+
return user;
|
|
114
|
+
}
|
|
115
|
+
async function waitUntil(condition, container, timeout) {
|
|
116
|
+
let refused;
|
|
117
|
+
await waitFor(
|
|
118
|
+
async () => {
|
|
119
|
+
try {
|
|
120
|
+
await condition();
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (!(error instanceof FrameEntryError || error instanceof StrictModeViolation)) {
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
refused = error;
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
// The default container is the spec frame's document, which never changes;
|
|
129
|
+
// watching the AUT's is what lets a mutation end the wait early.
|
|
130
|
+
{ container, timeout }
|
|
131
|
+
);
|
|
132
|
+
if (refused !== void 0) throw refused;
|
|
133
|
+
}
|
|
134
|
+
var CypressQuery = class _CypressQuery extends Query {
|
|
135
|
+
constructor(env, scope, selector) {
|
|
136
|
+
super(scope, selector);
|
|
137
|
+
this.env = env;
|
|
138
|
+
}
|
|
139
|
+
env;
|
|
140
|
+
clone(selector) {
|
|
141
|
+
return new _CypressQuery(this.env, this.scope, selector);
|
|
142
|
+
}
|
|
143
|
+
/** Read per query: navigation replaces the document, and with it the body. */
|
|
144
|
+
get container() {
|
|
145
|
+
const { document } = this.env;
|
|
146
|
+
return document.body ?? document.documentElement;
|
|
147
|
+
}
|
|
148
|
+
element(options) {
|
|
149
|
+
return resolveOne(this.container, this.scope, this.selector, options?.timeout);
|
|
150
|
+
}
|
|
151
|
+
/** Keeps the command log telling the story: one entry per harness action. */
|
|
152
|
+
log(action, detail) {
|
|
153
|
+
if (!this.env.log) return;
|
|
154
|
+
const target = describeScope(this.scope, this.selector);
|
|
155
|
+
Cypress.log({
|
|
156
|
+
name: "harness",
|
|
157
|
+
message: `**${action}** ${target}${detail === void 0 ? "" : ` ${detail}`}`,
|
|
158
|
+
consoleProps: () => ({ action, target, detail })
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
get user() {
|
|
162
|
+
return userFor(this.env);
|
|
163
|
+
}
|
|
164
|
+
get real() {
|
|
165
|
+
if (this.env.realEvents) requireChromium();
|
|
166
|
+
return this.env.realEvents;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Trusted input returns as soon as the browser has dispatched it, so a read
|
|
170
|
+
* straight after could beat a framework that renders on a timer of its own
|
|
171
|
+
* (zoneless Angular schedules after the event). A zero-delay timer in the AUT
|
|
172
|
+
* window runs after any it queued, as user-event's own pause does in the
|
|
173
|
+
* other mode.
|
|
174
|
+
*/
|
|
175
|
+
async afterReal(action) {
|
|
176
|
+
await action;
|
|
177
|
+
await new Promise((resolve) => this.env.window.setTimeout(resolve, 0));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Every match, resolved in one pass — see `DomQuery.all` for why. Each result is
|
|
181
|
+
* bound to its node and falls back to index resolution once that node leaves
|
|
182
|
+
* the document.
|
|
183
|
+
*/
|
|
184
|
+
async all() {
|
|
185
|
+
return (await resolveAll(this.container, this.scope, this.selector)).map(
|
|
186
|
+
(element, index) => new BoundCypressQuery(this.env, this.scope, nth(this.selector, index), element)
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
// --- interactions -------------------------------------------------------
|
|
190
|
+
async click(options) {
|
|
191
|
+
this.log("click");
|
|
192
|
+
const element = await this.element(options);
|
|
193
|
+
await (this.real ? this.afterReal(realClick(element)) : this.user.click(element));
|
|
194
|
+
}
|
|
195
|
+
async fill(value, options) {
|
|
196
|
+
this.log("fill", JSON.stringify(value));
|
|
197
|
+
const element = await this.element(options);
|
|
198
|
+
if (this.real) {
|
|
199
|
+
await this.afterReal(realReplace(element, value));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
await this.user.clear(element);
|
|
203
|
+
if (value !== "") await this.user.type(element, value);
|
|
204
|
+
}
|
|
205
|
+
async clear(options) {
|
|
206
|
+
this.log("clear");
|
|
207
|
+
const element = await this.element(options);
|
|
208
|
+
await (this.real ? this.afterReal(realReplace(element, "")) : this.user.clear(element));
|
|
209
|
+
}
|
|
210
|
+
async check(options) {
|
|
211
|
+
this.log("check");
|
|
212
|
+
const element = await this.element(options);
|
|
213
|
+
if (element.checked) return;
|
|
214
|
+
await (this.real ? this.afterReal(realClick(element)) : this.user.click(element));
|
|
215
|
+
}
|
|
216
|
+
async uncheck(options) {
|
|
217
|
+
this.log("uncheck");
|
|
218
|
+
const element = await this.element(options);
|
|
219
|
+
if (!element.checked) return;
|
|
220
|
+
await (this.real ? this.afterReal(realClick(element)) : this.user.click(element));
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Through user-event in both modes: a native `<select>` opens a popup the
|
|
224
|
+
* browser draws outside the page, which CDP pointer input cannot operate.
|
|
225
|
+
*/
|
|
226
|
+
async selectOption(value, options) {
|
|
227
|
+
this.log("selectOption", JSON.stringify(value));
|
|
228
|
+
const element = await this.element(options);
|
|
229
|
+
if (element.multiple) {
|
|
230
|
+
const selected = [...element.selectedOptions].map((option) => option.value);
|
|
231
|
+
if (selected.length > 0) await this.user.deselectOptions(element, selected);
|
|
232
|
+
}
|
|
233
|
+
await this.user.selectOptions(element, value);
|
|
234
|
+
}
|
|
235
|
+
async hover(options) {
|
|
236
|
+
this.log("hover");
|
|
237
|
+
const element = await this.element(options);
|
|
238
|
+
await (this.real ? this.afterReal(realHover(element)) : this.user.hover(element));
|
|
239
|
+
}
|
|
240
|
+
async focus(options) {
|
|
241
|
+
this.log("focus");
|
|
242
|
+
(await this.element(options)).focus();
|
|
243
|
+
}
|
|
244
|
+
async blur(options) {
|
|
245
|
+
this.log("blur");
|
|
246
|
+
(await this.element(options)).blur();
|
|
247
|
+
}
|
|
248
|
+
async press(key, options) {
|
|
249
|
+
this.log("press", key);
|
|
250
|
+
const element = await this.element(options);
|
|
251
|
+
element.focus();
|
|
252
|
+
await (this.real ? this.afterReal(realPress(key)) : this.user.keyboard(toKeyboardInput(key)));
|
|
253
|
+
}
|
|
254
|
+
// --- observations -------------------------------------------------------
|
|
255
|
+
/**
|
|
256
|
+
* Through user-event, real events or not: the Chrome DevTools Protocol sets
|
|
257
|
+
* files only from paths on disk, and a File here has none.
|
|
258
|
+
*/
|
|
259
|
+
async upload(files, options) {
|
|
260
|
+
const list = Array.isArray(files) ? files : [files];
|
|
261
|
+
this.log("upload", list.map((file) => file.name).join(", "));
|
|
262
|
+
const input = fileInputOf(await this.element(options));
|
|
263
|
+
checkFileTarget(input, list.length, this.scope, this.selector);
|
|
264
|
+
await this.user.upload(input, list);
|
|
265
|
+
}
|
|
266
|
+
async boundingBox(options) {
|
|
267
|
+
this.log("boundingBox");
|
|
268
|
+
return boundingBoxOf(await this.element(options), this.env.document);
|
|
269
|
+
}
|
|
270
|
+
async text(options) {
|
|
271
|
+
this.log("text");
|
|
272
|
+
return ((await this.element(options)).textContent ?? "").trim();
|
|
273
|
+
}
|
|
274
|
+
async inputValue(options) {
|
|
275
|
+
this.log("inputValue");
|
|
276
|
+
const element = await this.element(options);
|
|
277
|
+
return element.value ?? "";
|
|
278
|
+
}
|
|
279
|
+
async attribute(name, options) {
|
|
280
|
+
this.log("attribute", name);
|
|
281
|
+
return (await this.element(options)).getAttribute(name);
|
|
282
|
+
}
|
|
283
|
+
async isVisible(options) {
|
|
284
|
+
this.log("isVisible");
|
|
285
|
+
return this.visible(options);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* A real browser lays the page out, so visibility is a layout question — a
|
|
289
|
+
* box, and not `visibility: hidden` — answered the way Playwright answers it,
|
|
290
|
+
* rather than the dom driver's computed-style walk.
|
|
291
|
+
*/
|
|
292
|
+
async visible(options) {
|
|
293
|
+
try {
|
|
294
|
+
return isVisibleInLayout(await this.element(options), this.env.document);
|
|
295
|
+
} catch (error) {
|
|
296
|
+
if (error instanceof FrameEntryError || error instanceof StrictModeViolation) throw error;
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
async isEnabled(options) {
|
|
301
|
+
this.log("isEnabled");
|
|
302
|
+
const element = await this.element(options);
|
|
303
|
+
const disabled = element.disabled === true || element.closest(":disabled") !== null;
|
|
304
|
+
return enabledFrom(disabled, element.getAttribute("aria-disabled"));
|
|
305
|
+
}
|
|
306
|
+
async isChecked(options) {
|
|
307
|
+
this.log("isChecked");
|
|
308
|
+
const element = await this.element(options);
|
|
309
|
+
return checkedFrom(
|
|
310
|
+
element.getAttribute("aria-checked"),
|
|
311
|
+
Boolean(element.checked)
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
async selectedOptions(options) {
|
|
315
|
+
this.log("selectedOptions");
|
|
316
|
+
const element = await this.element(options);
|
|
317
|
+
return [...element.selectedOptions ?? []].map((option) => option.value);
|
|
318
|
+
}
|
|
319
|
+
// --- waiting ------------------------------------------------------------
|
|
320
|
+
async waitFor(state, options) {
|
|
321
|
+
this.log("waitFor", state);
|
|
322
|
+
const timeout = timeoutFor(options?.timeout);
|
|
323
|
+
const root = this.env.document.documentElement;
|
|
324
|
+
if (state === "visible") {
|
|
325
|
+
await waitUntil(
|
|
326
|
+
async () => {
|
|
327
|
+
if (!await this.visible({ timeout })) throw new Error("not visible yet");
|
|
328
|
+
},
|
|
329
|
+
root,
|
|
330
|
+
timeout
|
|
331
|
+
);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
await waitUntil(
|
|
335
|
+
async () => {
|
|
336
|
+
if (await this.count() !== 0 && await this.visible({ timeout })) {
|
|
337
|
+
throw new Error("still visible");
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
root,
|
|
341
|
+
timeout
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
async count() {
|
|
345
|
+
return countAll(this.container, this.scope, this.selector);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
var SET_VALUE_TYPES = ["color", "date", "time", "datetime-local", "month", "range", "week"];
|
|
349
|
+
function setValue(input, value) {
|
|
350
|
+
const setter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), "value")?.set;
|
|
351
|
+
if (setter === void 0) input.value = value;
|
|
352
|
+
else setter.call(input, value);
|
|
353
|
+
if (input.value !== value) {
|
|
354
|
+
throw new Error(
|
|
355
|
+
`harnessed: "${value}" is not a valid value for an <input type="${input.type}">.`
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
input.dispatchEvent(new Event("input", { bubbles: true, composed: true }));
|
|
359
|
+
input.dispatchEvent(new Event("change", { bubbles: true }));
|
|
360
|
+
}
|
|
361
|
+
async function realReplace(element, value) {
|
|
362
|
+
element.focus();
|
|
363
|
+
const input = element;
|
|
364
|
+
if (element.localName === "input" && SET_VALUE_TYPES.includes(input.type)) {
|
|
365
|
+
setValue(input, value);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (element.localName === "input" || element.localName === "textarea") {
|
|
369
|
+
element.select();
|
|
370
|
+
} else {
|
|
371
|
+
element.ownerDocument.getSelection()?.selectAllChildren(element);
|
|
372
|
+
}
|
|
373
|
+
await (value === "" ? realPress("Delete") : realInsertText(value));
|
|
374
|
+
}
|
|
375
|
+
var BoundCypressQuery = class extends CypressQuery {
|
|
376
|
+
constructor(env, scope, selector, bound) {
|
|
377
|
+
super(env, scope, selector);
|
|
378
|
+
this.bound = bound;
|
|
379
|
+
}
|
|
380
|
+
bound;
|
|
381
|
+
async element(options) {
|
|
382
|
+
if (this.bound.isConnected) return this.bound;
|
|
383
|
+
return super.element(options);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
registerDriver(CYPRESS_DRIVER, (env, scope, selector) => {
|
|
387
|
+
return new CypressQuery(env, scope, selector);
|
|
388
|
+
});
|
|
389
|
+
var POLL_MS = 20;
|
|
390
|
+
function sleep(ms) {
|
|
391
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
392
|
+
}
|
|
393
|
+
function baseOf(window2) {
|
|
394
|
+
const baseUrl = Cypress.config("baseUrl");
|
|
395
|
+
if (baseUrl !== null && baseUrl !== "") return baseUrl;
|
|
396
|
+
if (/^https?:$/.test(window2.location.protocol)) return window2.location.href;
|
|
397
|
+
return void 0;
|
|
398
|
+
}
|
|
399
|
+
function resolveUrl(window2, url) {
|
|
400
|
+
try {
|
|
401
|
+
return new URL(url, baseOf(window2));
|
|
402
|
+
} catch {
|
|
403
|
+
throw new Error(
|
|
404
|
+
`harnessed: cannot resolve "${url}": the application under test has not loaded a page yet and Cypress has no baseUrl. Set baseUrl, or pass an absolute URL.`
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function sameDocument(from, to) {
|
|
409
|
+
const current = new URL(from);
|
|
410
|
+
return to.hash !== "" && current.href.split("#")[0] === to.href.split("#")[0];
|
|
411
|
+
}
|
|
412
|
+
async function goto(env, url) {
|
|
413
|
+
if (Cypress.testingType === "component") {
|
|
414
|
+
throw new Error(
|
|
415
|
+
"harnessed: goto() cannot run in component testing \u2014 the component is mounted in the spec frame, so navigating it would end the test. Navigate in an e2e spec, or mount the screen you want."
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
const { window: window2 } = env;
|
|
419
|
+
const leaving = window2.document;
|
|
420
|
+
const target = resolveUrl(window2, url);
|
|
421
|
+
const sameDoc = window2.location.protocol !== "about:" && sameDocument(window2.location.href, target);
|
|
422
|
+
window2.location.href = target.href;
|
|
423
|
+
if (sameDoc) return;
|
|
424
|
+
const timeout = Cypress.config("pageLoadTimeout");
|
|
425
|
+
const deadline = Date.now() + timeout;
|
|
426
|
+
for (; ; ) {
|
|
427
|
+
const document = window2.document;
|
|
428
|
+
if (document !== leaving && document.readyState !== "loading") return;
|
|
429
|
+
if (Date.now() > deadline) {
|
|
430
|
+
throw new Error(`harnessed: ${target.href} did not load within ${timeout}ms.`);
|
|
431
|
+
}
|
|
432
|
+
await sleep(POLL_MS);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
registerNavigation(CYPRESS_DRIVER, {
|
|
436
|
+
goto,
|
|
437
|
+
currentUrl(env) {
|
|
438
|
+
return env.window.location.href;
|
|
439
|
+
},
|
|
440
|
+
async waitForUrl(env, matches, timeout) {
|
|
441
|
+
const { window: window2 } = env;
|
|
442
|
+
const deadline = Date.now() + timeout;
|
|
443
|
+
while (!matches(new URL(window2.location.href))) {
|
|
444
|
+
if (Date.now() > deadline) {
|
|
445
|
+
throw new Error(
|
|
446
|
+
`harnessed: the URL did not match within ${timeout}ms; it is ${window2.location.href}.`
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
await sleep(POLL_MS);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// src/env.ts
|
|
455
|
+
function cypress({
|
|
456
|
+
window: window2,
|
|
457
|
+
document,
|
|
458
|
+
realEvents = false,
|
|
459
|
+
log = true
|
|
460
|
+
}) {
|
|
461
|
+
return {
|
|
462
|
+
driver: CYPRESS_DRIVER,
|
|
463
|
+
window: window2,
|
|
464
|
+
get document() {
|
|
465
|
+
return document ?? window2.document;
|
|
466
|
+
},
|
|
467
|
+
realEvents,
|
|
468
|
+
log
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
function timeoutOf(options) {
|
|
472
|
+
return options?.timeout ?? getConfig().defaultTimeout * 4;
|
|
473
|
+
}
|
|
474
|
+
function envFor(window2, options) {
|
|
475
|
+
return cypress({
|
|
476
|
+
window: window2,
|
|
477
|
+
realEvents: options?.realEvents ?? false,
|
|
478
|
+
log: options?.log ?? true
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
function inPage(subject, fn, options) {
|
|
482
|
+
return cy.window({ log: false }).then({ timeout: timeoutOf(options) }, async (window2) => ({
|
|
483
|
+
result: await fn(envFor(window2, options))
|
|
484
|
+
})).then(({ result }) => cy.wrap(result === void 0 ? subject : result, { log: false }));
|
|
485
|
+
}
|
|
486
|
+
function registerCommands() {
|
|
487
|
+
Cypress.Commands.add(
|
|
488
|
+
"harnessEnv",
|
|
489
|
+
{ prevSubject: "optional" },
|
|
490
|
+
(subject, fn, options) => inPage(subject, fn, options)
|
|
491
|
+
);
|
|
492
|
+
Cypress.Commands.add(
|
|
493
|
+
"harness",
|
|
494
|
+
{ prevSubject: "optional" },
|
|
495
|
+
(subject, Harness, fnOrOptions, maybeOptions) => {
|
|
496
|
+
const fn = typeof fnOrOptions === "function" ? fnOrOptions : void 0;
|
|
497
|
+
const options = typeof fnOrOptions === "function" ? maybeOptions : fnOrOptions;
|
|
498
|
+
Cypress.log({ name: "harness", message: Harness.name });
|
|
499
|
+
return inPage(
|
|
500
|
+
subject,
|
|
501
|
+
(env) => {
|
|
502
|
+
const harness = new Harness(env);
|
|
503
|
+
return fn === void 0 ? harness : fn(harness);
|
|
504
|
+
},
|
|
505
|
+
options
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
);
|
|
509
|
+
Cypress.Commands.add(
|
|
510
|
+
"visitPage",
|
|
511
|
+
(Page, params, rawOptions) => {
|
|
512
|
+
const options = rawOptions;
|
|
513
|
+
return cy.window({ log: false }).then((window2) => {
|
|
514
|
+
const page = new Page(envFor(window2, options));
|
|
515
|
+
return cy.visit(page.urlFor(params)).then({ timeout: timeoutOf(options) }, async () => {
|
|
516
|
+
await page.expectReady();
|
|
517
|
+
return page;
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export { CYPRESS_DRIVER, CypressQuery, cypress, registerCommands };
|
|
525
|
+
//# sourceMappingURL=chunk-CGA7IP66.js.map
|
|
526
|
+
//# sourceMappingURL=chunk-CGA7IP66.js.map
|