@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAC/C,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,YAAY,EACV,YAAY,EACZ,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,OAAO,GACR,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../src/navigation.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trusted input through the Chrome DevTools Protocol, for `realEvents: true`.
|
|
3
|
+
*
|
|
4
|
+
* Cypress's own `trigger` and the cypress-real-events commands are `cy`
|
|
5
|
+
* commands, and a harness runs inside a promise where nothing can be enqueued.
|
|
6
|
+
* `Cypress.automation('remote:debugger:protocol')` is the one way to reach CDP
|
|
7
|
+
* that is itself a promise. The browser then produces the events — `isTrusted`,
|
|
8
|
+
* default actions and all — rather than a script imitating them.
|
|
9
|
+
*/
|
|
10
|
+
/** Refuses early and by name, instead of failing inside the automation channel. */
|
|
11
|
+
export declare function requireChromium(): void;
|
|
12
|
+
export declare function realHover(element: Element): Promise<void>;
|
|
13
|
+
export declare function realClick(element: Element): Promise<void>;
|
|
14
|
+
/** One key, down then up, into whatever has focus. */
|
|
15
|
+
export declare function realPress(key: string): Promise<void>;
|
|
16
|
+
/** Text into whatever has focus, the way an IME commits it — Playwright's `fill`. */
|
|
17
|
+
export declare function realInsertText(text: string): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=real-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"real-events.d.ts","sourceRoot":"","sources":["../src/real-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA+CH,mFAAmF;AACnF,wBAAgB,eAAe,IAAI,IAAI,CAQtC;AA4CD,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAG/D;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAM/D;AAED,sDAAsD;AACtD,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAW1D;AAED,qFAAqF;AACrF,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhE"}
|
package/dist/support.cjs
ADDED
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@harnessed-ts/core');
|
|
4
|
+
var resolve = require('@harnessed-ts/resolve');
|
|
5
|
+
var dom = require('@testing-library/dom');
|
|
6
|
+
var userEvent = require('@testing-library/user-event');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var userEvent__default = /*#__PURE__*/_interopDefault(userEvent);
|
|
11
|
+
|
|
12
|
+
// src/commands.ts
|
|
13
|
+
|
|
14
|
+
// src/driver-id.ts
|
|
15
|
+
var CYPRESS_DRIVER = "cypress";
|
|
16
|
+
|
|
17
|
+
// src/real-events.ts
|
|
18
|
+
var NAMED_KEYS = {
|
|
19
|
+
Enter: { code: "Enter", keyCode: 13, text: "\r" },
|
|
20
|
+
Tab: { code: "Tab", keyCode: 9 },
|
|
21
|
+
Backspace: { code: "Backspace", keyCode: 8 },
|
|
22
|
+
Delete: { code: "Delete", keyCode: 46 },
|
|
23
|
+
Escape: { code: "Escape", keyCode: 27 },
|
|
24
|
+
Space: { code: "Space", keyCode: 32, text: " " },
|
|
25
|
+
ArrowUp: { code: "ArrowUp", keyCode: 38 },
|
|
26
|
+
ArrowDown: { code: "ArrowDown", keyCode: 40 },
|
|
27
|
+
ArrowLeft: { code: "ArrowLeft", keyCode: 37 },
|
|
28
|
+
ArrowRight: { code: "ArrowRight", keyCode: 39 },
|
|
29
|
+
Home: { code: "Home", keyCode: 36 },
|
|
30
|
+
End: { code: "End", keyCode: 35 },
|
|
31
|
+
PageUp: { code: "PageUp", keyCode: 33 },
|
|
32
|
+
PageDown: { code: "PageDown", keyCode: 34 },
|
|
33
|
+
Insert: { code: "Insert", keyCode: 45 }
|
|
34
|
+
};
|
|
35
|
+
function keyDefinition(key) {
|
|
36
|
+
const named = NAMED_KEYS[key];
|
|
37
|
+
if (named !== void 0) return { key: key === "Space" ? " " : key, ...named };
|
|
38
|
+
if ([...key].length === 1) {
|
|
39
|
+
const upper = key.toUpperCase();
|
|
40
|
+
const code = /[A-Z]/.test(upper) ? `Key${upper}` : /[0-9]/.test(key) ? `Digit${key}` : "";
|
|
41
|
+
const keyCode = /[A-Z0-9]/.test(upper) ? upper.charCodeAt(0) : 0;
|
|
42
|
+
return { key, code, keyCode, text: key };
|
|
43
|
+
}
|
|
44
|
+
throw new Error(
|
|
45
|
+
`harnessed: realEvents cannot press "${key}". It presses single characters and ${Object.keys(NAMED_KEYS).join(", ")}; drop realEvents to press it through user-event.`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
function send(command, params) {
|
|
49
|
+
return Promise.resolve(Cypress.automation("remote:debugger:protocol", { command, params }));
|
|
50
|
+
}
|
|
51
|
+
function requireChromium() {
|
|
52
|
+
if (!Cypress.isBrowser({ family: "chromium" })) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`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.`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function framesDownTo(target, within) {
|
|
59
|
+
for (const frame of within.querySelectorAll("iframe")) {
|
|
60
|
+
if (frame.contentWindow === target) return [frame];
|
|
61
|
+
const inner = frame.contentDocument;
|
|
62
|
+
const path = inner === null ? null : framesDownTo(target, inner);
|
|
63
|
+
if (path !== null) return [frame, ...path];
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
function centreOf(element) {
|
|
68
|
+
element.scrollIntoView({ block: "center", inline: "center" });
|
|
69
|
+
const box = element.getBoundingClientRect();
|
|
70
|
+
let x = box.left + box.width / 2;
|
|
71
|
+
let y = box.top + box.height / 2;
|
|
72
|
+
const view = element.ownerDocument.defaultView;
|
|
73
|
+
const top = window.top ?? window;
|
|
74
|
+
const frames = view === null || view === top ? [] : framesDownTo(view, top.document) ?? [];
|
|
75
|
+
for (const frame of frames.reverse()) {
|
|
76
|
+
const frameBox = frame.getBoundingClientRect();
|
|
77
|
+
const scale = frame.offsetWidth > 0 ? frameBox.width / frame.offsetWidth : 1;
|
|
78
|
+
const style = frame.ownerDocument.defaultView?.getComputedStyle(frame);
|
|
79
|
+
const insetX = frame.clientLeft + parseFloat(style?.paddingLeft ?? "0");
|
|
80
|
+
const insetY = frame.clientTop + parseFloat(style?.paddingTop ?? "0");
|
|
81
|
+
x = frameBox.left + (insetX + x) * scale;
|
|
82
|
+
y = frameBox.top + (insetY + y) * scale;
|
|
83
|
+
}
|
|
84
|
+
return { x, y };
|
|
85
|
+
}
|
|
86
|
+
async function realHover(element) {
|
|
87
|
+
const { x, y } = centreOf(element);
|
|
88
|
+
await send("Input.dispatchMouseEvent", { type: "mouseMoved", x, y });
|
|
89
|
+
}
|
|
90
|
+
async function realClick(element) {
|
|
91
|
+
const { x, y } = centreOf(element);
|
|
92
|
+
await send("Input.dispatchMouseEvent", { type: "mouseMoved", x, y });
|
|
93
|
+
const press = { x, y, button: "left", clickCount: 1 };
|
|
94
|
+
await send("Input.dispatchMouseEvent", { type: "mousePressed", buttons: 1, ...press });
|
|
95
|
+
await send("Input.dispatchMouseEvent", { type: "mouseReleased", buttons: 0, ...press });
|
|
96
|
+
}
|
|
97
|
+
async function realPress(key) {
|
|
98
|
+
const { text, keyCode, ...definition } = keyDefinition(key);
|
|
99
|
+
const common = { ...definition, windowsVirtualKeyCode: keyCode, nativeVirtualKeyCode: keyCode };
|
|
100
|
+
await send(
|
|
101
|
+
"Input.dispatchKeyEvent",
|
|
102
|
+
text === void 0 ? { type: "rawKeyDown", ...common } : { type: "keyDown", text, unmodifiedText: text, ...common }
|
|
103
|
+
);
|
|
104
|
+
await send("Input.dispatchKeyEvent", { type: "keyUp", ...common });
|
|
105
|
+
}
|
|
106
|
+
async function realInsertText(text) {
|
|
107
|
+
await send("Input.insertText", { text });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/cypress-query.ts
|
|
111
|
+
function toKeyboardInput(key) {
|
|
112
|
+
return key.length === 1 ? key : `{${key}}`;
|
|
113
|
+
}
|
|
114
|
+
var users = /* @__PURE__ */ new WeakMap();
|
|
115
|
+
function userFor(env) {
|
|
116
|
+
const { document } = env;
|
|
117
|
+
const bound = users.get(env);
|
|
118
|
+
if (bound !== void 0 && bound.document === document) return bound.user;
|
|
119
|
+
const user = userEvent__default.default.setup({ document });
|
|
120
|
+
users.set(env, { document, user });
|
|
121
|
+
return user;
|
|
122
|
+
}
|
|
123
|
+
async function waitUntil(condition, container, timeout) {
|
|
124
|
+
let refused;
|
|
125
|
+
await dom.waitFor(
|
|
126
|
+
async () => {
|
|
127
|
+
try {
|
|
128
|
+
await condition();
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (!(error instanceof resolve.FrameEntryError || error instanceof core.StrictModeViolation)) {
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
refused = error;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
// The default container is the spec frame's document, which never changes;
|
|
137
|
+
// watching the AUT's is what lets a mutation end the wait early.
|
|
138
|
+
{ container, timeout }
|
|
139
|
+
);
|
|
140
|
+
if (refused !== void 0) throw refused;
|
|
141
|
+
}
|
|
142
|
+
var CypressQuery = class _CypressQuery extends core.Query {
|
|
143
|
+
constructor(env, scope, selector) {
|
|
144
|
+
super(scope, selector);
|
|
145
|
+
this.env = env;
|
|
146
|
+
}
|
|
147
|
+
env;
|
|
148
|
+
clone(selector) {
|
|
149
|
+
return new _CypressQuery(this.env, this.scope, selector);
|
|
150
|
+
}
|
|
151
|
+
/** Read per query: navigation replaces the document, and with it the body. */
|
|
152
|
+
get container() {
|
|
153
|
+
const { document } = this.env;
|
|
154
|
+
return document.body ?? document.documentElement;
|
|
155
|
+
}
|
|
156
|
+
element(options) {
|
|
157
|
+
return resolve.resolveOne(this.container, this.scope, this.selector, options?.timeout);
|
|
158
|
+
}
|
|
159
|
+
/** Keeps the command log telling the story: one entry per harness action. */
|
|
160
|
+
log(action, detail) {
|
|
161
|
+
if (!this.env.log) return;
|
|
162
|
+
const target = core.describeScope(this.scope, this.selector);
|
|
163
|
+
Cypress.log({
|
|
164
|
+
name: "harness",
|
|
165
|
+
message: `**${action}** ${target}${detail === void 0 ? "" : ` ${detail}`}`,
|
|
166
|
+
consoleProps: () => ({ action, target, detail })
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
get user() {
|
|
170
|
+
return userFor(this.env);
|
|
171
|
+
}
|
|
172
|
+
get real() {
|
|
173
|
+
if (this.env.realEvents) requireChromium();
|
|
174
|
+
return this.env.realEvents;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Trusted input returns as soon as the browser has dispatched it, so a read
|
|
178
|
+
* straight after could beat a framework that renders on a timer of its own
|
|
179
|
+
* (zoneless Angular schedules after the event). A zero-delay timer in the AUT
|
|
180
|
+
* window runs after any it queued, as user-event's own pause does in the
|
|
181
|
+
* other mode.
|
|
182
|
+
*/
|
|
183
|
+
async afterReal(action) {
|
|
184
|
+
await action;
|
|
185
|
+
await new Promise((resolve) => this.env.window.setTimeout(resolve, 0));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Every match, resolved in one pass — see `DomQuery.all` for why. Each result is
|
|
189
|
+
* bound to its node and falls back to index resolution once that node leaves
|
|
190
|
+
* the document.
|
|
191
|
+
*/
|
|
192
|
+
async all() {
|
|
193
|
+
return (await resolve.resolveAll(this.container, this.scope, this.selector)).map(
|
|
194
|
+
(element, index) => new BoundCypressQuery(this.env, this.scope, core.nth(this.selector, index), element)
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
// --- interactions -------------------------------------------------------
|
|
198
|
+
async click(options) {
|
|
199
|
+
this.log("click");
|
|
200
|
+
const element = await this.element(options);
|
|
201
|
+
await (this.real ? this.afterReal(realClick(element)) : this.user.click(element));
|
|
202
|
+
}
|
|
203
|
+
async fill(value, options) {
|
|
204
|
+
this.log("fill", JSON.stringify(value));
|
|
205
|
+
const element = await this.element(options);
|
|
206
|
+
if (this.real) {
|
|
207
|
+
await this.afterReal(realReplace(element, value));
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
await this.user.clear(element);
|
|
211
|
+
if (value !== "") await this.user.type(element, value);
|
|
212
|
+
}
|
|
213
|
+
async clear(options) {
|
|
214
|
+
this.log("clear");
|
|
215
|
+
const element = await this.element(options);
|
|
216
|
+
await (this.real ? this.afterReal(realReplace(element, "")) : this.user.clear(element));
|
|
217
|
+
}
|
|
218
|
+
async check(options) {
|
|
219
|
+
this.log("check");
|
|
220
|
+
const element = await this.element(options);
|
|
221
|
+
if (element.checked) return;
|
|
222
|
+
await (this.real ? this.afterReal(realClick(element)) : this.user.click(element));
|
|
223
|
+
}
|
|
224
|
+
async uncheck(options) {
|
|
225
|
+
this.log("uncheck");
|
|
226
|
+
const element = await this.element(options);
|
|
227
|
+
if (!element.checked) return;
|
|
228
|
+
await (this.real ? this.afterReal(realClick(element)) : this.user.click(element));
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Through user-event in both modes: a native `<select>` opens a popup the
|
|
232
|
+
* browser draws outside the page, which CDP pointer input cannot operate.
|
|
233
|
+
*/
|
|
234
|
+
async selectOption(value, options) {
|
|
235
|
+
this.log("selectOption", JSON.stringify(value));
|
|
236
|
+
const element = await this.element(options);
|
|
237
|
+
if (element.multiple) {
|
|
238
|
+
const selected = [...element.selectedOptions].map((option) => option.value);
|
|
239
|
+
if (selected.length > 0) await this.user.deselectOptions(element, selected);
|
|
240
|
+
}
|
|
241
|
+
await this.user.selectOptions(element, value);
|
|
242
|
+
}
|
|
243
|
+
async hover(options) {
|
|
244
|
+
this.log("hover");
|
|
245
|
+
const element = await this.element(options);
|
|
246
|
+
await (this.real ? this.afterReal(realHover(element)) : this.user.hover(element));
|
|
247
|
+
}
|
|
248
|
+
async focus(options) {
|
|
249
|
+
this.log("focus");
|
|
250
|
+
(await this.element(options)).focus();
|
|
251
|
+
}
|
|
252
|
+
async blur(options) {
|
|
253
|
+
this.log("blur");
|
|
254
|
+
(await this.element(options)).blur();
|
|
255
|
+
}
|
|
256
|
+
async press(key, options) {
|
|
257
|
+
this.log("press", key);
|
|
258
|
+
const element = await this.element(options);
|
|
259
|
+
element.focus();
|
|
260
|
+
await (this.real ? this.afterReal(realPress(key)) : this.user.keyboard(toKeyboardInput(key)));
|
|
261
|
+
}
|
|
262
|
+
// --- observations -------------------------------------------------------
|
|
263
|
+
/**
|
|
264
|
+
* Through user-event, real events or not: the Chrome DevTools Protocol sets
|
|
265
|
+
* files only from paths on disk, and a File here has none.
|
|
266
|
+
*/
|
|
267
|
+
async upload(files, options) {
|
|
268
|
+
const list = Array.isArray(files) ? files : [files];
|
|
269
|
+
this.log("upload", list.map((file) => file.name).join(", "));
|
|
270
|
+
const input = resolve.fileInputOf(await this.element(options));
|
|
271
|
+
core.checkFileTarget(input, list.length, this.scope, this.selector);
|
|
272
|
+
await this.user.upload(input, list);
|
|
273
|
+
}
|
|
274
|
+
async boundingBox(options) {
|
|
275
|
+
this.log("boundingBox");
|
|
276
|
+
return resolve.boundingBoxOf(await this.element(options), this.env.document);
|
|
277
|
+
}
|
|
278
|
+
async text(options) {
|
|
279
|
+
this.log("text");
|
|
280
|
+
return ((await this.element(options)).textContent ?? "").trim();
|
|
281
|
+
}
|
|
282
|
+
async inputValue(options) {
|
|
283
|
+
this.log("inputValue");
|
|
284
|
+
const element = await this.element(options);
|
|
285
|
+
return element.value ?? "";
|
|
286
|
+
}
|
|
287
|
+
async attribute(name, options) {
|
|
288
|
+
this.log("attribute", name);
|
|
289
|
+
return (await this.element(options)).getAttribute(name);
|
|
290
|
+
}
|
|
291
|
+
async isVisible(options) {
|
|
292
|
+
this.log("isVisible");
|
|
293
|
+
return this.visible(options);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* A real browser lays the page out, so visibility is a layout question — a
|
|
297
|
+
* box, and not `visibility: hidden` — answered the way Playwright answers it,
|
|
298
|
+
* rather than the dom driver's computed-style walk.
|
|
299
|
+
*/
|
|
300
|
+
async visible(options) {
|
|
301
|
+
try {
|
|
302
|
+
return resolve.isVisibleInLayout(await this.element(options), this.env.document);
|
|
303
|
+
} catch (error) {
|
|
304
|
+
if (error instanceof resolve.FrameEntryError || error instanceof core.StrictModeViolation) throw error;
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async isEnabled(options) {
|
|
309
|
+
this.log("isEnabled");
|
|
310
|
+
const element = await this.element(options);
|
|
311
|
+
const disabled = element.disabled === true || element.closest(":disabled") !== null;
|
|
312
|
+
return core.enabledFrom(disabled, element.getAttribute("aria-disabled"));
|
|
313
|
+
}
|
|
314
|
+
async isChecked(options) {
|
|
315
|
+
this.log("isChecked");
|
|
316
|
+
const element = await this.element(options);
|
|
317
|
+
return core.checkedFrom(
|
|
318
|
+
element.getAttribute("aria-checked"),
|
|
319
|
+
Boolean(element.checked)
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
async selectedOptions(options) {
|
|
323
|
+
this.log("selectedOptions");
|
|
324
|
+
const element = await this.element(options);
|
|
325
|
+
return [...element.selectedOptions ?? []].map((option) => option.value);
|
|
326
|
+
}
|
|
327
|
+
// --- waiting ------------------------------------------------------------
|
|
328
|
+
async waitFor(state, options) {
|
|
329
|
+
this.log("waitFor", state);
|
|
330
|
+
const timeout = core.timeoutFor(options?.timeout);
|
|
331
|
+
const root = this.env.document.documentElement;
|
|
332
|
+
if (state === "visible") {
|
|
333
|
+
await waitUntil(
|
|
334
|
+
async () => {
|
|
335
|
+
if (!await this.visible({ timeout })) throw new Error("not visible yet");
|
|
336
|
+
},
|
|
337
|
+
root,
|
|
338
|
+
timeout
|
|
339
|
+
);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
await waitUntil(
|
|
343
|
+
async () => {
|
|
344
|
+
if (await this.count() !== 0 && await this.visible({ timeout })) {
|
|
345
|
+
throw new Error("still visible");
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
root,
|
|
349
|
+
timeout
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
async count() {
|
|
353
|
+
return resolve.countAll(this.container, this.scope, this.selector);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
var SET_VALUE_TYPES = ["color", "date", "time", "datetime-local", "month", "range", "week"];
|
|
357
|
+
function setValue(input, value) {
|
|
358
|
+
const setter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), "value")?.set;
|
|
359
|
+
if (setter === void 0) input.value = value;
|
|
360
|
+
else setter.call(input, value);
|
|
361
|
+
if (input.value !== value) {
|
|
362
|
+
throw new Error(
|
|
363
|
+
`harnessed: "${value}" is not a valid value for an <input type="${input.type}">.`
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
input.dispatchEvent(new Event("input", { bubbles: true, composed: true }));
|
|
367
|
+
input.dispatchEvent(new Event("change", { bubbles: true }));
|
|
368
|
+
}
|
|
369
|
+
async function realReplace(element, value) {
|
|
370
|
+
element.focus();
|
|
371
|
+
const input = element;
|
|
372
|
+
if (element.localName === "input" && SET_VALUE_TYPES.includes(input.type)) {
|
|
373
|
+
setValue(input, value);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (element.localName === "input" || element.localName === "textarea") {
|
|
377
|
+
element.select();
|
|
378
|
+
} else {
|
|
379
|
+
element.ownerDocument.getSelection()?.selectAllChildren(element);
|
|
380
|
+
}
|
|
381
|
+
await (value === "" ? realPress("Delete") : realInsertText(value));
|
|
382
|
+
}
|
|
383
|
+
var BoundCypressQuery = class extends CypressQuery {
|
|
384
|
+
constructor(env, scope, selector, bound) {
|
|
385
|
+
super(env, scope, selector);
|
|
386
|
+
this.bound = bound;
|
|
387
|
+
}
|
|
388
|
+
bound;
|
|
389
|
+
async element(options) {
|
|
390
|
+
if (this.bound.isConnected) return this.bound;
|
|
391
|
+
return super.element(options);
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
core.registerDriver(CYPRESS_DRIVER, (env, scope, selector) => {
|
|
395
|
+
return new CypressQuery(env, scope, selector);
|
|
396
|
+
});
|
|
397
|
+
var POLL_MS = 20;
|
|
398
|
+
function sleep(ms) {
|
|
399
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
400
|
+
}
|
|
401
|
+
function baseOf(window2) {
|
|
402
|
+
const baseUrl = Cypress.config("baseUrl");
|
|
403
|
+
if (baseUrl !== null && baseUrl !== "") return baseUrl;
|
|
404
|
+
if (/^https?:$/.test(window2.location.protocol)) return window2.location.href;
|
|
405
|
+
return void 0;
|
|
406
|
+
}
|
|
407
|
+
function resolveUrl(window2, url) {
|
|
408
|
+
try {
|
|
409
|
+
return new URL(url, baseOf(window2));
|
|
410
|
+
} catch {
|
|
411
|
+
throw new Error(
|
|
412
|
+
`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.`
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function sameDocument(from, to) {
|
|
417
|
+
const current = new URL(from);
|
|
418
|
+
return to.hash !== "" && current.href.split("#")[0] === to.href.split("#")[0];
|
|
419
|
+
}
|
|
420
|
+
async function goto(env, url) {
|
|
421
|
+
if (Cypress.testingType === "component") {
|
|
422
|
+
throw new Error(
|
|
423
|
+
"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."
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
const { window: window2 } = env;
|
|
427
|
+
const leaving = window2.document;
|
|
428
|
+
const target = resolveUrl(window2, url);
|
|
429
|
+
const sameDoc = window2.location.protocol !== "about:" && sameDocument(window2.location.href, target);
|
|
430
|
+
window2.location.href = target.href;
|
|
431
|
+
if (sameDoc) return;
|
|
432
|
+
const timeout = Cypress.config("pageLoadTimeout");
|
|
433
|
+
const deadline = Date.now() + timeout;
|
|
434
|
+
for (; ; ) {
|
|
435
|
+
const document = window2.document;
|
|
436
|
+
if (document !== leaving && document.readyState !== "loading") return;
|
|
437
|
+
if (Date.now() > deadline) {
|
|
438
|
+
throw new Error(`harnessed: ${target.href} did not load within ${timeout}ms.`);
|
|
439
|
+
}
|
|
440
|
+
await sleep(POLL_MS);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
core.registerNavigation(CYPRESS_DRIVER, {
|
|
444
|
+
goto,
|
|
445
|
+
currentUrl(env) {
|
|
446
|
+
return env.window.location.href;
|
|
447
|
+
},
|
|
448
|
+
async waitForUrl(env, matches, timeout) {
|
|
449
|
+
const { window: window2 } = env;
|
|
450
|
+
const deadline = Date.now() + timeout;
|
|
451
|
+
while (!matches(new URL(window2.location.href))) {
|
|
452
|
+
if (Date.now() > deadline) {
|
|
453
|
+
throw new Error(
|
|
454
|
+
`harnessed: the URL did not match within ${timeout}ms; it is ${window2.location.href}.`
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
await sleep(POLL_MS);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
// src/env.ts
|
|
463
|
+
function cypress({
|
|
464
|
+
window: window2,
|
|
465
|
+
document,
|
|
466
|
+
realEvents = false,
|
|
467
|
+
log = true
|
|
468
|
+
}) {
|
|
469
|
+
return {
|
|
470
|
+
driver: CYPRESS_DRIVER,
|
|
471
|
+
window: window2,
|
|
472
|
+
get document() {
|
|
473
|
+
return document ?? window2.document;
|
|
474
|
+
},
|
|
475
|
+
realEvents,
|
|
476
|
+
log
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// src/commands.ts
|
|
481
|
+
function timeoutOf(options) {
|
|
482
|
+
return options?.timeout ?? core.getConfig().defaultTimeout * 4;
|
|
483
|
+
}
|
|
484
|
+
function envFor(window2, options) {
|
|
485
|
+
return cypress({
|
|
486
|
+
window: window2,
|
|
487
|
+
realEvents: options?.realEvents ?? false,
|
|
488
|
+
log: options?.log ?? true
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
function inPage(subject, fn, options) {
|
|
492
|
+
return cy.window({ log: false }).then({ timeout: timeoutOf(options) }, async (window2) => ({
|
|
493
|
+
result: await fn(envFor(window2, options))
|
|
494
|
+
})).then(({ result }) => cy.wrap(result === void 0 ? subject : result, { log: false }));
|
|
495
|
+
}
|
|
496
|
+
function registerCommands() {
|
|
497
|
+
Cypress.Commands.add(
|
|
498
|
+
"harnessEnv",
|
|
499
|
+
{ prevSubject: "optional" },
|
|
500
|
+
(subject, fn, options) => inPage(subject, fn, options)
|
|
501
|
+
);
|
|
502
|
+
Cypress.Commands.add(
|
|
503
|
+
"harness",
|
|
504
|
+
{ prevSubject: "optional" },
|
|
505
|
+
(subject, Harness, fnOrOptions, maybeOptions) => {
|
|
506
|
+
const fn = typeof fnOrOptions === "function" ? fnOrOptions : void 0;
|
|
507
|
+
const options = typeof fnOrOptions === "function" ? maybeOptions : fnOrOptions;
|
|
508
|
+
Cypress.log({ name: "harness", message: Harness.name });
|
|
509
|
+
return inPage(
|
|
510
|
+
subject,
|
|
511
|
+
(env) => {
|
|
512
|
+
const harness = new Harness(env);
|
|
513
|
+
return fn === void 0 ? harness : fn(harness);
|
|
514
|
+
},
|
|
515
|
+
options
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
);
|
|
519
|
+
Cypress.Commands.add(
|
|
520
|
+
"visitPage",
|
|
521
|
+
(Page, params, rawOptions) => {
|
|
522
|
+
const options = rawOptions;
|
|
523
|
+
return cy.window({ log: false }).then((window2) => {
|
|
524
|
+
const page = new Page(envFor(window2, options));
|
|
525
|
+
return cy.visit(page.urlFor(params)).then({ timeout: timeoutOf(options) }, async () => {
|
|
526
|
+
await page.expectReady();
|
|
527
|
+
return page;
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// src/support.ts
|
|
535
|
+
registerCommands();
|
|
536
|
+
//# sourceMappingURL=support.cjs.map
|
|
537
|
+
//# sourceMappingURL=support.cjs.map
|