@vitest/browser-playwright 5.0.5 → 5.1.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/dist/index.js +129 -8
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -169,6 +169,14 @@ const basename = function(p, extension) {
|
|
|
169
169
|
return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
|
|
170
170
|
};
|
|
171
171
|
|
|
172
|
+
async function focusIframe(context) {
|
|
173
|
+
const frame = await context.frame();
|
|
174
|
+
await frame.evaluate(() => {
|
|
175
|
+
if (!document.activeElement || document.activeElement.ownerDocument !== document || document.activeElement === document.body) {
|
|
176
|
+
window.focus();
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
172
180
|
// strip iframe locator part from the trace description e.g.
|
|
173
181
|
// - locator('[data-vitest="true"]').contentFrame().getByRole('button')
|
|
174
182
|
// ⇓
|
|
@@ -184,12 +192,15 @@ const clear = async (context, selector) => {
|
|
|
184
192
|
};
|
|
185
193
|
|
|
186
194
|
const click = async (context, selector, options = {}) => {
|
|
195
|
+
await focusIframe(context);
|
|
187
196
|
await getDescribedLocator(context, selector).click(options);
|
|
188
197
|
};
|
|
189
198
|
const dblClick = async (context, selector, options = {}) => {
|
|
199
|
+
await focusIframe(context);
|
|
190
200
|
await getDescribedLocator(context, selector).dblclick(options);
|
|
191
201
|
};
|
|
192
202
|
const tripleClick = async (context, selector, options = {}) => {
|
|
203
|
+
await focusIframe(context);
|
|
193
204
|
await getDescribedLocator(context, selector).click({
|
|
194
205
|
...options,
|
|
195
206
|
clickCount: 3
|
|
@@ -211,8 +222,7 @@ const hover = async (context, selector, options = {}) => {
|
|
|
211
222
|
};
|
|
212
223
|
|
|
213
224
|
const keyboard = async (context, text, state) => {
|
|
214
|
-
|
|
215
|
-
await frame.evaluate(focusIframe);
|
|
225
|
+
await focusIframe(context);
|
|
216
226
|
const pressed = new Set(state.unreleased);
|
|
217
227
|
await keyboardImplementation(pressed, context.provider, context.sessionId, text, async () => {
|
|
218
228
|
const frame = await context.frame();
|
|
@@ -485,11 +495,6 @@ async function keyboardImplementation(pressed, provider, sessionId, text, select
|
|
|
485
495
|
}
|
|
486
496
|
return { pressed };
|
|
487
497
|
}
|
|
488
|
-
function focusIframe() {
|
|
489
|
-
if (!document.activeElement || document.activeElement.ownerDocument !== document || document.activeElement === document.body) {
|
|
490
|
-
window.focus();
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
498
|
function selectAll() {
|
|
494
499
|
const element = document.activeElement;
|
|
495
500
|
if (element && typeof element.select === "function") {
|
|
@@ -497,6 +502,114 @@ function selectAll() {
|
|
|
497
502
|
}
|
|
498
503
|
}
|
|
499
504
|
|
|
505
|
+
const pointer = async (context, input, state = {}) => {
|
|
506
|
+
const pressedKeys = new Set(state.unreleased);
|
|
507
|
+
let lastTarget = state.target;
|
|
508
|
+
let lastCoords = state.coords;
|
|
509
|
+
for (const option of input) {
|
|
510
|
+
let target = option.target;
|
|
511
|
+
let coords = option.coords;
|
|
512
|
+
if (target || coords) {
|
|
513
|
+
lastTarget = target;
|
|
514
|
+
lastCoords = coords;
|
|
515
|
+
} else {
|
|
516
|
+
target = lastTarget;
|
|
517
|
+
coords = lastCoords;
|
|
518
|
+
}
|
|
519
|
+
const pointerAction = {
|
|
520
|
+
...option,
|
|
521
|
+
target,
|
|
522
|
+
coords
|
|
523
|
+
};
|
|
524
|
+
const keys = "keys" in option ? option.keys : null;
|
|
525
|
+
const parsedKeys = keys === null ? null : groupKeyDefs(parseKeyDef(keys));
|
|
526
|
+
const hasOnlyClickActions = parsedKeys?.every(({ keyDef: { keyDef: { code }, releasePrevious, releaseSelf } }) => code === "MouseLeft" && !releasePrevious && releaseSelf);
|
|
527
|
+
// click has its own moving logic, no need to move twice
|
|
528
|
+
if (!hasOnlyClickActions) {
|
|
529
|
+
if (target) {
|
|
530
|
+
await hover(context, target, { position: coords });
|
|
531
|
+
} else if (coords) {
|
|
532
|
+
await context.page.mouse.move(coords.x, coords.y);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
if (parsedKeys) {
|
|
536
|
+
for (const key of parsedKeys) {
|
|
537
|
+
await keyDefHandler(key, pointerAction, pressedKeys, context);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
unreleased: Array.from(pressedKeys),
|
|
543
|
+
target: lastTarget,
|
|
544
|
+
coords: lastCoords
|
|
545
|
+
};
|
|
546
|
+
};
|
|
547
|
+
function groupKeyDefs(keyDefs) {
|
|
548
|
+
const output = [];
|
|
549
|
+
let last;
|
|
550
|
+
for (const keyDef of keyDefs) {
|
|
551
|
+
if (last !== undefined && last.keyDef.releasePrevious === keyDef.releasePrevious && last.keyDef.releaseSelf === keyDef.releaseSelf && last.keyDef.keyDef.key === keyDef.keyDef.key && last.keyDef.keyDef.code === keyDef.keyDef.code && last.keyDef.keyDef.location === keyDef.keyDef.location) {
|
|
552
|
+
last.times += keyDef.repeat;
|
|
553
|
+
} else {
|
|
554
|
+
last = {
|
|
555
|
+
times: keyDef.repeat,
|
|
556
|
+
keyDef
|
|
557
|
+
};
|
|
558
|
+
output.push(last);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return output;
|
|
562
|
+
}
|
|
563
|
+
const MOUSE_KEYS = [
|
|
564
|
+
"MouseLeft",
|
|
565
|
+
"MouseRight",
|
|
566
|
+
"MouseMiddle"
|
|
567
|
+
];
|
|
568
|
+
async function keyDefHandler({ keyDef: { keyDef, releasePrevious, releaseSelf }, times }, pointerAction, pressedKeys, context) {
|
|
569
|
+
const key = keyDef.key;
|
|
570
|
+
const code = keyDef.code;
|
|
571
|
+
if (MOUSE_KEYS.includes(code)) {
|
|
572
|
+
const button = code.replace("Mouse", "").toLowerCase();
|
|
573
|
+
const mouseOptions = {
|
|
574
|
+
button,
|
|
575
|
+
clickCount: times
|
|
576
|
+
};
|
|
577
|
+
if (releasePrevious) {
|
|
578
|
+
await context.page.mouse.up(mouseOptions);
|
|
579
|
+
} else if (releaseSelf) {
|
|
580
|
+
if (pointerAction.target) {
|
|
581
|
+
await click(context, pointerAction.target, {
|
|
582
|
+
...mouseOptions,
|
|
583
|
+
position: pointerAction.coords
|
|
584
|
+
});
|
|
585
|
+
} else {
|
|
586
|
+
const x = pointerAction.coords?.x ?? 0;
|
|
587
|
+
const y = pointerAction.coords?.y ?? 0;
|
|
588
|
+
await context.page.mouse.click(x, y, mouseOptions);
|
|
589
|
+
}
|
|
590
|
+
} else {
|
|
591
|
+
await context.page.mouse.down(mouseOptions);
|
|
592
|
+
}
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
if (key === "Unknown") {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
if (!releasePrevious) {
|
|
599
|
+
if (releaseSelf) {
|
|
600
|
+
for (let count = 0; count < times; count += 1) {
|
|
601
|
+
await context.page.keyboard.press(key);
|
|
602
|
+
}
|
|
603
|
+
} else {
|
|
604
|
+
await context.page.keyboard.down(key);
|
|
605
|
+
pressedKeys.add(key);
|
|
606
|
+
}
|
|
607
|
+
} else if (pressedKeys.has(key)) {
|
|
608
|
+
await context.page.keyboard.up(key);
|
|
609
|
+
pressedKeys.delete(key);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
500
613
|
const SCREENSHOT_STYLES = `
|
|
501
614
|
iframe[data-vitest="true"] {
|
|
502
615
|
position: absolute !important;
|
|
@@ -691,7 +804,7 @@ function parseLocation(context, stack) {
|
|
|
691
804
|
if (!stack) {
|
|
692
805
|
return;
|
|
693
806
|
}
|
|
694
|
-
const parsedStacks = context.project.browser.parseStacktrace(stack);
|
|
807
|
+
const parsedStacks = context.project.browser.parseStacktrace(stack, { firstOnly: true });
|
|
695
808
|
return parsedStacks[0];
|
|
696
809
|
}
|
|
697
810
|
function resolveTracesPath({ testPath, project }, name) {
|
|
@@ -809,6 +922,7 @@ var commands = {
|
|
|
809
922
|
__vitest_dblClick: dblClick,
|
|
810
923
|
__vitest_tripleClick: tripleClick,
|
|
811
924
|
__vitest_wheel: wheel,
|
|
925
|
+
__vitest_pointer: pointer,
|
|
812
926
|
__vitest_takeScreenshot: takeScreenshot,
|
|
813
927
|
__vitest_type: type,
|
|
814
928
|
__vitest_clear: clear,
|
|
@@ -960,6 +1074,13 @@ function resolveLaunchOptions(browser, inspector, providerOptions, browserName)
|
|
|
960
1074
|
...providerOptions.launchOptions,
|
|
961
1075
|
headless: browser.headless
|
|
962
1076
|
};
|
|
1077
|
+
if (browserName === "firefox") {
|
|
1078
|
+
// multiple import maps per document are behind a pref in Firefox 150+
|
|
1079
|
+
launchOptions.firefoxUserPrefs = {
|
|
1080
|
+
"dom.multiple_import_maps.enabled": true,
|
|
1081
|
+
...launchOptions.firefoxUserPrefs
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
963
1084
|
if (typeof browser.trace === "object" && browser.trace.tracesDir) {
|
|
964
1085
|
launchOptions.tracesDir = browser.trace.tracesDir;
|
|
965
1086
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser-playwright",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.0
|
|
4
|
+
"version": "5.1.0",
|
|
5
5
|
"description": "Browser running for Vitest using playwright",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
],
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"playwright": "*",
|
|
46
|
-
"vitest": "5.0
|
|
46
|
+
"vitest": "5.1.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
49
49
|
"playwright": {
|
|
@@ -51,15 +51,15 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@vitest/browser": "5.0
|
|
55
|
-
"@vitest/mocker": "5.0
|
|
54
|
+
"@vitest/browser": "5.1.0",
|
|
55
|
+
"@vitest/mocker": "5.1.0",
|
|
56
56
|
"tinyrainbow": "^3.2.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"pathe": "^2.0.3",
|
|
60
|
-
"playwright": "^1.64.
|
|
61
|
-
"vite": "8.
|
|
62
|
-
"vitest": "5.0
|
|
60
|
+
"playwright": "^1.64.1",
|
|
61
|
+
"vite": "8.3.5",
|
|
62
|
+
"vitest": "5.1.0"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "premove dist && pnpm rollup -c",
|