@vitest/browser-playwright 5.0.4 → 5.1.0-beta.1
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 +117 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -497,6 +497,114 @@ function selectAll() {
|
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
|
|
500
|
+
const pointer = async (context, input, state = {}) => {
|
|
501
|
+
const pressedKeys = new Set(state.unreleased);
|
|
502
|
+
let lastTarget = state.target;
|
|
503
|
+
let lastCoords = state.coords;
|
|
504
|
+
for (const option of input) {
|
|
505
|
+
let target = option.target;
|
|
506
|
+
let coords = option.coords;
|
|
507
|
+
if (target || coords) {
|
|
508
|
+
lastTarget = target;
|
|
509
|
+
lastCoords = coords;
|
|
510
|
+
} else {
|
|
511
|
+
target = lastTarget;
|
|
512
|
+
coords = lastCoords;
|
|
513
|
+
}
|
|
514
|
+
const pointerAction = {
|
|
515
|
+
...option,
|
|
516
|
+
target,
|
|
517
|
+
coords
|
|
518
|
+
};
|
|
519
|
+
const keys = "keys" in option ? option.keys : null;
|
|
520
|
+
const parsedKeys = keys === null ? null : groupKeyDefs(parseKeyDef(keys));
|
|
521
|
+
const hasOnlyClickActions = parsedKeys?.every(({ keyDef: { keyDef: { code }, releasePrevious, releaseSelf } }) => code === "MouseLeft" && !releasePrevious && releaseSelf);
|
|
522
|
+
// click has its own moving logic, no need to move twice
|
|
523
|
+
if (!hasOnlyClickActions) {
|
|
524
|
+
if (target) {
|
|
525
|
+
await hover(context, target, { position: coords });
|
|
526
|
+
} else if (coords) {
|
|
527
|
+
await context.page.mouse.move(coords.x, coords.y);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (parsedKeys) {
|
|
531
|
+
for (const key of parsedKeys) {
|
|
532
|
+
await keyDefHandler(key, pointerAction, pressedKeys, context);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return {
|
|
537
|
+
unreleased: Array.from(pressedKeys),
|
|
538
|
+
target: lastTarget,
|
|
539
|
+
coords: lastCoords
|
|
540
|
+
};
|
|
541
|
+
};
|
|
542
|
+
function groupKeyDefs(keyDefs) {
|
|
543
|
+
const output = [];
|
|
544
|
+
let last;
|
|
545
|
+
for (const keyDef of keyDefs) {
|
|
546
|
+
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) {
|
|
547
|
+
last.times += keyDef.repeat;
|
|
548
|
+
} else {
|
|
549
|
+
last = {
|
|
550
|
+
times: keyDef.repeat,
|
|
551
|
+
keyDef
|
|
552
|
+
};
|
|
553
|
+
output.push(last);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
return output;
|
|
557
|
+
}
|
|
558
|
+
const MOUSE_KEYS = [
|
|
559
|
+
"MouseLeft",
|
|
560
|
+
"MouseRight",
|
|
561
|
+
"MouseMiddle"
|
|
562
|
+
];
|
|
563
|
+
async function keyDefHandler({ keyDef: { keyDef, releasePrevious, releaseSelf }, times }, pointerAction, pressedKeys, context) {
|
|
564
|
+
const key = keyDef.key;
|
|
565
|
+
const code = keyDef.code;
|
|
566
|
+
if (MOUSE_KEYS.includes(code)) {
|
|
567
|
+
const button = code.replace("Mouse", "").toLowerCase();
|
|
568
|
+
const mouseOptions = {
|
|
569
|
+
button,
|
|
570
|
+
clickCount: times
|
|
571
|
+
};
|
|
572
|
+
if (releasePrevious) {
|
|
573
|
+
await context.page.mouse.up(mouseOptions);
|
|
574
|
+
} else if (releaseSelf) {
|
|
575
|
+
if (pointerAction.target) {
|
|
576
|
+
await click(context, pointerAction.target, {
|
|
577
|
+
...mouseOptions,
|
|
578
|
+
position: pointerAction.coords
|
|
579
|
+
});
|
|
580
|
+
} else {
|
|
581
|
+
const x = pointerAction.coords?.x ?? 0;
|
|
582
|
+
const y = pointerAction.coords?.y ?? 0;
|
|
583
|
+
await context.page.mouse.click(x, y, mouseOptions);
|
|
584
|
+
}
|
|
585
|
+
} else {
|
|
586
|
+
await context.page.mouse.down(mouseOptions);
|
|
587
|
+
}
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
if (key === "Unknown") {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
if (!releasePrevious) {
|
|
594
|
+
if (releaseSelf) {
|
|
595
|
+
for (let count = 0; count < times; count += 1) {
|
|
596
|
+
await context.page.keyboard.press(key);
|
|
597
|
+
}
|
|
598
|
+
} else {
|
|
599
|
+
await context.page.keyboard.down(key);
|
|
600
|
+
pressedKeys.add(key);
|
|
601
|
+
}
|
|
602
|
+
} else if (pressedKeys.has(key)) {
|
|
603
|
+
await context.page.keyboard.up(key);
|
|
604
|
+
pressedKeys.delete(key);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
500
608
|
const SCREENSHOT_STYLES = `
|
|
501
609
|
iframe[data-vitest="true"] {
|
|
502
610
|
position: absolute !important;
|
|
@@ -691,7 +799,7 @@ function parseLocation(context, stack) {
|
|
|
691
799
|
if (!stack) {
|
|
692
800
|
return;
|
|
693
801
|
}
|
|
694
|
-
const parsedStacks = context.project.browser.parseStacktrace(stack);
|
|
802
|
+
const parsedStacks = context.project.browser.parseStacktrace(stack, { firstOnly: true });
|
|
695
803
|
return parsedStacks[0];
|
|
696
804
|
}
|
|
697
805
|
function resolveTracesPath({ testPath, project }, name) {
|
|
@@ -809,6 +917,7 @@ var commands = {
|
|
|
809
917
|
__vitest_dblClick: dblClick,
|
|
810
918
|
__vitest_tripleClick: tripleClick,
|
|
811
919
|
__vitest_wheel: wheel,
|
|
920
|
+
__vitest_pointer: pointer,
|
|
812
921
|
__vitest_takeScreenshot: takeScreenshot,
|
|
813
922
|
__vitest_type: type,
|
|
814
923
|
__vitest_clear: clear,
|
|
@@ -960,6 +1069,13 @@ function resolveLaunchOptions(browser, inspector, providerOptions, browserName)
|
|
|
960
1069
|
...providerOptions.launchOptions,
|
|
961
1070
|
headless: browser.headless
|
|
962
1071
|
};
|
|
1072
|
+
if (browserName === "firefox") {
|
|
1073
|
+
// multiple import maps per document are behind a pref in Firefox 150+
|
|
1074
|
+
launchOptions.firefoxUserPrefs = {
|
|
1075
|
+
"dom.multiple_import_maps.enabled": true,
|
|
1076
|
+
...launchOptions.firefoxUserPrefs
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
963
1079
|
if (typeof browser.trace === "object" && browser.trace.tracesDir) {
|
|
964
1080
|
launchOptions.tracesDir = browser.trace.tracesDir;
|
|
965
1081
|
}
|
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-beta.1",
|
|
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-beta.1"
|
|
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-beta.1",
|
|
55
|
+
"@vitest/mocker": "5.1.0-beta.1",
|
|
56
56
|
"tinyrainbow": "^3.2.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"pathe": "^2.0.3",
|
|
60
|
-
"playwright": "^1.64.
|
|
60
|
+
"playwright": "^1.64.1",
|
|
61
61
|
"vite": "8.0.11",
|
|
62
|
-
"vitest": "5.0.
|
|
62
|
+
"vitest": "5.1.0-beta.1"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "premove dist && pnpm rollup -c",
|