@testspectra/react 1.2.7 → 1.2.9
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/dist/index.js +50 -0
- package/dist/setup.js +33 -33
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
// src/dom_driver_bridge.ts
|
|
2
2
|
import { userEvent } from "@testing-library/user-event";
|
|
3
3
|
|
|
4
|
+
// ../../core/worker-runtime/src/dsl/keyboard.ts
|
|
5
|
+
var SPECIAL_KEYS = {
|
|
6
|
+
Backspace: { code: "Backspace", windowsVirtualKeyCode: 8 },
|
|
7
|
+
Tab: { code: "Tab", windowsVirtualKeyCode: 9 },
|
|
8
|
+
Enter: { code: "Enter", windowsVirtualKeyCode: 13, text: "\r" },
|
|
9
|
+
Escape: { code: "Escape", windowsVirtualKeyCode: 27 },
|
|
10
|
+
Delete: { code: "Delete", windowsVirtualKeyCode: 46 },
|
|
11
|
+
ArrowLeft: { code: "ArrowLeft", windowsVirtualKeyCode: 37 },
|
|
12
|
+
ArrowUp: { code: "ArrowUp", windowsVirtualKeyCode: 38 },
|
|
13
|
+
ArrowRight: { code: "ArrowRight", windowsVirtualKeyCode: 39 },
|
|
14
|
+
ArrowDown: { code: "ArrowDown", windowsVirtualKeyCode: 40 },
|
|
15
|
+
Home: { code: "Home", windowsVirtualKeyCode: 36 },
|
|
16
|
+
End: { code: "End", windowsVirtualKeyCode: 35 },
|
|
17
|
+
PageUp: { code: "PageUp", windowsVirtualKeyCode: 33 },
|
|
18
|
+
PageDown: { code: "PageDown", windowsVirtualKeyCode: 34 },
|
|
19
|
+
" ": { code: "Space", windowsVirtualKeyCode: 32, text: " " },
|
|
20
|
+
Space: { code: "Space", windowsVirtualKeyCode: 32, text: " " }
|
|
21
|
+
};
|
|
22
|
+
function codeForChar(char) {
|
|
23
|
+
if (/^[a-zA-Z]$/.test(char)) return `Key${char.toUpperCase()}`;
|
|
24
|
+
if (/^[0-9]$/.test(char)) return `Digit${char}`;
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
function describePressKey(input) {
|
|
28
|
+
if (typeof input !== "string") return null;
|
|
29
|
+
if (input === "Space") return { key: " ", code: "Space", windowsVirtualKeyCode: 32, text: " " };
|
|
30
|
+
const special = SPECIAL_KEYS[input];
|
|
31
|
+
if (special) return { key: input, ...special };
|
|
32
|
+
if (input.length === 1) {
|
|
33
|
+
return {
|
|
34
|
+
key: input,
|
|
35
|
+
code: codeForChar(input),
|
|
36
|
+
windowsVirtualKeyCode: input.toUpperCase().charCodeAt(0),
|
|
37
|
+
text: input
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
4
43
|
// ../../core/worker-runtime/src/dsl/mock_intercept.ts
|
|
5
44
|
function matchesUrlPattern(pattern, url) {
|
|
6
45
|
if (!pattern || pattern === "*" || pattern === "**" || pattern === "ALL") {
|
|
@@ -197,6 +236,8 @@ function mockResponseBodyText(body) {
|
|
|
197
236
|
|
|
198
237
|
// ../../core/worker-runtime/src/dsl/selector_resolver.ts
|
|
199
238
|
function parseElementSentinel(selector) {
|
|
239
|
+
const nth = /^(.*)::nth\((-?\d+)\)$/.exec(selector);
|
|
240
|
+
if (nth) return { kind: "nth", base: nth[1], arg: nth[2] };
|
|
200
241
|
const closest = /^(.*)::closest\((.+)\)$/.exec(selector);
|
|
201
242
|
if (closest) return { kind: "closest", base: closest[1], arg: closest[2] };
|
|
202
243
|
const children = /^(.*)::children\((.*)\)$/.exec(selector);
|
|
@@ -429,6 +470,10 @@ function matchesSelector(el, selector) {
|
|
|
429
470
|
function resolveSentinelList(raw, parent) {
|
|
430
471
|
const sentinel = parseElementSentinel(raw);
|
|
431
472
|
if (!sentinel) return void 0;
|
|
473
|
+
if (sentinel.kind === "nth") {
|
|
474
|
+
const el = resolveScopedEl(sentinel.base, Number.parseInt(sentinel.arg, 10));
|
|
475
|
+
return el ? [el] : [];
|
|
476
|
+
}
|
|
432
477
|
const baseTarget = parent ? { selector: sentinel.base, index: null, parent } : sentinel.base;
|
|
433
478
|
const base = resolveScopedEl(baseTarget, null);
|
|
434
479
|
if (sentinel.kind === "parent") return base?.parentElement ? [base.parentElement] : [];
|
|
@@ -809,6 +854,11 @@ var DomDriverBridge = class {
|
|
|
809
854
|
}
|
|
810
855
|
// ─── Gestures & Keys ─────────────────────────────────────────────────────
|
|
811
856
|
async pressKey(key) {
|
|
857
|
+
const desc = describePressKey(key);
|
|
858
|
+
if (desc) {
|
|
859
|
+
await getUser().keyboard(desc.code ? `{${desc.code}}` : desc.key);
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
812
862
|
const active = document.activeElement || document.body;
|
|
813
863
|
const keyName = String(key);
|
|
814
864
|
active.dispatchEvent(new KeyboardEvent("keydown", { key: keyName, bubbles: true }));
|