@vitest/browser 2.0.4 → 2.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/aria-role.d.ts +96 -0
- package/context.d.ts +232 -20
- package/dist/client/.vite/manifest.json +2 -2
- package/dist/client/__vitest__/assets/index-JTfsnJeu.css +1 -0
- package/dist/client/__vitest__/assets/index-uh8h5Yzr.js +52 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/index.html +4 -3
- package/dist/client/__vitest_browser__/{orchestrator-CNOAigTE.js → orchestrator-BObhEEvc.js} +4 -4
- package/dist/client/__vitest_browser__/{tester-BSSDPE9E.js → tester-CRcWWhrn.js} +19 -5
- package/dist/client/error-catcher.js +10 -16
- package/dist/client/orchestrator.html +1 -1
- package/dist/client/tester/tester.html +3 -11
- package/dist/context.js +260 -111
- package/dist/index-BRfqvYVY.js +5722 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +100 -62
- package/dist/locators/index.d.ts +261 -0
- package/dist/locators/index.js +2 -0
- package/dist/locators/playwright.js +42 -0
- package/dist/locators/preview.js +86 -0
- package/dist/locators/webdriverio.js +83 -0
- package/jest-dom.d.ts +1 -97
- package/matchers.d.ts +2 -1
- package/package.json +19 -14
- package/providers/playwright.d.ts +2 -1
- package/providers/webdriverio.d.ts +10 -1
- package/dist/client/__vitest__/assets/index--tE7Z8jQ.js +0 -52
- package/dist/client/__vitest__/assets/index-C0SwoDYm.css +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CDPSession, BrowserServerState as BrowserServerState$1, BrowserServerStateContext, BrowserServer as BrowserServer$1, WorkspaceProject, Vite, BrowserProvider, BrowserScript, Vitest, ProcessPool } from 'vitest/node';
|
|
2
2
|
import { Plugin } from 'vitest/config';
|
|
3
3
|
import * as vitest from 'vitest';
|
|
4
|
-
import { File, TaskResultPack, AfterSuiteRunMeta, CancelReason, UserConsoleLog, SnapshotResult,
|
|
4
|
+
import { File, TaskResultPack, AfterSuiteRunMeta, CancelReason, UserConsoleLog, SnapshotResult, SerializedConfig } from 'vitest';
|
|
5
5
|
import { ErrorWithDiff } from '@vitest/utils';
|
|
6
6
|
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
7
7
|
|
|
@@ -38,6 +38,8 @@ interface WebSocketBrowserHandlers {
|
|
|
38
38
|
debug: (...args: string[]) => void;
|
|
39
39
|
resolveId: (id: string, importer?: string) => Promise<{
|
|
40
40
|
id: string;
|
|
41
|
+
url: string;
|
|
42
|
+
optimized: boolean;
|
|
41
43
|
} | null>;
|
|
42
44
|
triggerCommand: <T>(contextId: string, command: string, testPath: string | undefined, payload: unknown[]) => Promise<T>;
|
|
43
45
|
resolveMock: (id: string, importer: string, hasFactory: boolean) => Promise<{
|
|
@@ -103,7 +105,8 @@ declare class BrowserServer implements BrowserServer$1 {
|
|
|
103
105
|
testerHtml: Promise<string> | string;
|
|
104
106
|
orchestratorHtml: Promise<string> | string;
|
|
105
107
|
injectorJs: Promise<string> | string;
|
|
106
|
-
|
|
108
|
+
errorCatcherUrl: string;
|
|
109
|
+
locatorsUrl: string | undefined;
|
|
107
110
|
stateJs: Promise<string> | string;
|
|
108
111
|
state: BrowserServerState;
|
|
109
112
|
provider: BrowserProvider;
|
|
@@ -111,7 +114,7 @@ declare class BrowserServer implements BrowserServer$1 {
|
|
|
111
114
|
private stackTraceOptions;
|
|
112
115
|
constructor(project: WorkspaceProject, base: string);
|
|
113
116
|
setServer(server: Vite.ViteDevServer): void;
|
|
114
|
-
getSerializableConfig():
|
|
117
|
+
getSerializableConfig(): SerializedConfig;
|
|
115
118
|
resolveTesterUrl(pathname: string): {
|
|
116
119
|
contextId: string;
|
|
117
120
|
testFile: string;
|
package/dist/index.js
CHANGED
|
@@ -525,6 +525,7 @@ function getDepsCacheDir(config) {
|
|
|
525
525
|
|
|
526
526
|
const debug$1 = createDebugger("vitest:browser:api");
|
|
527
527
|
const BROWSER_API_PATH = "/__vitest_browser_api__";
|
|
528
|
+
const VALID_ID_PREFIX = "/@id/";
|
|
528
529
|
function setupBrowserRpc(server) {
|
|
529
530
|
const project = server.project;
|
|
530
531
|
const vite = server.vite;
|
|
@@ -565,10 +566,14 @@ function setupBrowserRpc(server) {
|
|
|
565
566
|
const rpc = createBirpc(
|
|
566
567
|
{
|
|
567
568
|
async onUnhandledError(error, type) {
|
|
569
|
+
if (error && typeof error === "object") {
|
|
570
|
+
const _error = error;
|
|
571
|
+
_error.stacks = server.parseErrorStacktrace(_error);
|
|
572
|
+
}
|
|
568
573
|
ctx.state.catchError(error, type);
|
|
569
574
|
},
|
|
570
575
|
async onCollected(files) {
|
|
571
|
-
ctx.state.collectFiles(files);
|
|
576
|
+
ctx.state.collectFiles(project, files);
|
|
572
577
|
await ctx.report("onCollected", files);
|
|
573
578
|
},
|
|
574
579
|
async onTaskUpdate(packs) {
|
|
@@ -617,14 +622,34 @@ function setupBrowserRpc(server) {
|
|
|
617
622
|
ctx.cancelCurrentRun(reason);
|
|
618
623
|
},
|
|
619
624
|
async resolveId(id, importer) {
|
|
620
|
-
const
|
|
625
|
+
const resolved = await vite.pluginContainer.resolveId(
|
|
621
626
|
id,
|
|
622
627
|
importer,
|
|
623
628
|
{
|
|
624
629
|
ssr: false
|
|
625
630
|
}
|
|
626
631
|
);
|
|
627
|
-
|
|
632
|
+
if (!resolved) {
|
|
633
|
+
return null;
|
|
634
|
+
}
|
|
635
|
+
const isOptimized = resolved.id.startsWith(withTrailingSlash(vite.config.cacheDir));
|
|
636
|
+
let url;
|
|
637
|
+
const root = vite.config.root;
|
|
638
|
+
if (resolved.id.startsWith(withTrailingSlash(root))) {
|
|
639
|
+
url = resolved.id.slice(root.length);
|
|
640
|
+
} else if (resolved.id !== "/@react-refresh" && isAbsolute(resolved.id) && existsSync(cleanUrl(resolved.id))) {
|
|
641
|
+
url = join("/@fs/", resolved.id);
|
|
642
|
+
} else {
|
|
643
|
+
url = resolved.id;
|
|
644
|
+
}
|
|
645
|
+
if (url[0] !== "." && url[0] !== "/") {
|
|
646
|
+
url = id.startsWith(VALID_ID_PREFIX) ? id : VALID_ID_PREFIX + id.replace("\0", "__x00__");
|
|
647
|
+
}
|
|
648
|
+
return {
|
|
649
|
+
id: resolved.id,
|
|
650
|
+
url,
|
|
651
|
+
optimized: isOptimized
|
|
652
|
+
};
|
|
628
653
|
},
|
|
629
654
|
debug(...args) {
|
|
630
655
|
ctx.logger.console.debug(...args);
|
|
@@ -727,6 +752,12 @@ function stringifyReplace(key, value) {
|
|
|
727
752
|
return value;
|
|
728
753
|
}
|
|
729
754
|
}
|
|
755
|
+
function withTrailingSlash(path) {
|
|
756
|
+
if (path[path.length - 1] !== "/") {
|
|
757
|
+
return `${path}/`;
|
|
758
|
+
}
|
|
759
|
+
return path;
|
|
760
|
+
}
|
|
730
761
|
|
|
731
762
|
class BrowserServerState {
|
|
732
763
|
orchestrators = /* @__PURE__ */ new Map();
|
|
@@ -867,7 +898,12 @@ class BrowserServer {
|
|
|
867
898
|
resolve(distRoot, "client/esm-client-injector.js"),
|
|
868
899
|
"utf8"
|
|
869
900
|
).then((js) => this.injectorJs = js);
|
|
870
|
-
this.
|
|
901
|
+
this.errorCatcherUrl = join("/@fs/", resolve(distRoot, "client/error-catcher.js"));
|
|
902
|
+
const builtinProviders = ["playwright", "webdriverio", "preview"];
|
|
903
|
+
const providerName = project.config.browser.provider || "preview";
|
|
904
|
+
if (builtinProviders.includes(providerName)) {
|
|
905
|
+
this.locatorsUrl = join("/@fs/", distRoot, "locators", `${providerName}.js`);
|
|
906
|
+
}
|
|
871
907
|
this.stateJs = readFile$1(
|
|
872
908
|
resolve(distRoot, "state.js"),
|
|
873
909
|
"utf-8"
|
|
@@ -881,7 +917,8 @@ class BrowserServer {
|
|
|
881
917
|
testerHtml;
|
|
882
918
|
orchestratorHtml;
|
|
883
919
|
injectorJs;
|
|
884
|
-
|
|
920
|
+
errorCatcherUrl;
|
|
921
|
+
locatorsUrl;
|
|
885
922
|
stateJs;
|
|
886
923
|
state;
|
|
887
924
|
provider;
|
|
@@ -998,7 +1035,7 @@ const click = async (context, selector, options = {}) => {
|
|
|
998
1035
|
const provider = context.provider;
|
|
999
1036
|
if (provider instanceof PlaywrightBrowserProvider) {
|
|
1000
1037
|
const tester = context.iframe;
|
|
1001
|
-
await tester.locator(
|
|
1038
|
+
await tester.locator(selector).click({
|
|
1002
1039
|
timeout: 1e3,
|
|
1003
1040
|
...options
|
|
1004
1041
|
});
|
|
@@ -1013,7 +1050,7 @@ const dblClick = async (context, selector, options = {}) => {
|
|
|
1013
1050
|
const provider = context.provider;
|
|
1014
1051
|
if (provider instanceof PlaywrightBrowserProvider) {
|
|
1015
1052
|
const tester = context.iframe;
|
|
1016
|
-
await tester.locator(
|
|
1053
|
+
await tester.locator(selector).dblclick(options);
|
|
1017
1054
|
} else if (provider instanceof WebdriverBrowserProvider) {
|
|
1018
1055
|
const browser = context.browser;
|
|
1019
1056
|
await browser.$(selector).doubleClick();
|
|
@@ -1025,7 +1062,7 @@ const tripleClick = async (context, selector, options = {}) => {
|
|
|
1025
1062
|
const provider = context.provider;
|
|
1026
1063
|
if (provider instanceof PlaywrightBrowserProvider) {
|
|
1027
1064
|
const tester = context.iframe;
|
|
1028
|
-
await tester.locator(
|
|
1065
|
+
await tester.locator(selector).click({
|
|
1029
1066
|
timeout: 1e3,
|
|
1030
1067
|
...options,
|
|
1031
1068
|
clickCount: 3
|
|
@@ -1050,28 +1087,6 @@ var clickableInputTypes;
|
|
|
1050
1087
|
clickableInputTypes["radio"] = "radio";
|
|
1051
1088
|
})(clickableInputTypes || (clickableInputTypes = {}));
|
|
1052
1089
|
|
|
1053
|
-
const ClipboardStubControl = Symbol('Manage ClipboardSub');
|
|
1054
|
-
function isClipboardStub(clipboard) {
|
|
1055
|
-
return !!(clipboard === null || clipboard === void 0 ? void 0 : clipboard[ClipboardStubControl]);
|
|
1056
|
-
}
|
|
1057
|
-
function resetClipboardStubOnView(window) {
|
|
1058
|
-
if (isClipboardStub(window.navigator.clipboard)) {
|
|
1059
|
-
window.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
function detachClipboardStubFromView(window) {
|
|
1063
|
-
if (isClipboardStub(window.navigator.clipboard)) {
|
|
1064
|
-
window.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
const g = globalThis;
|
|
1068
|
-
/* istanbul ignore else */ if (typeof g.afterEach === 'function') {
|
|
1069
|
-
g.afterEach(()=>resetClipboardStubOnView(globalThis.window));
|
|
1070
|
-
}
|
|
1071
|
-
/* istanbul ignore else */ if (typeof g.afterAll === 'function') {
|
|
1072
|
-
g.afterAll(()=>detachClipboardStubFromView(globalThis.window));
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
1090
|
var editableInputTypes;
|
|
1076
1091
|
(function(editableInputTypes) {
|
|
1077
1092
|
editableInputTypes["text"] = "text";
|
|
@@ -1402,7 +1417,7 @@ var DOM_KEY_LOCATION;
|
|
|
1402
1417
|
}
|
|
1403
1418
|
];
|
|
1404
1419
|
|
|
1405
|
-
const keyboard = async (context, text) => {
|
|
1420
|
+
const keyboard = async (context, text, state) => {
|
|
1406
1421
|
function focusIframe() {
|
|
1407
1422
|
if (!document.activeElement || document.activeElement.ownerDocument !== document || document.activeElement === document.body) {
|
|
1408
1423
|
window.focus();
|
|
@@ -1414,7 +1429,9 @@ const keyboard = async (context, text) => {
|
|
|
1414
1429
|
} else if (context.provider instanceof WebdriverBrowserProvider) {
|
|
1415
1430
|
await context.browser.execute(focusIframe);
|
|
1416
1431
|
}
|
|
1432
|
+
const pressed = new Set(state.unreleased);
|
|
1417
1433
|
await keyboardImplementation(
|
|
1434
|
+
pressed,
|
|
1418
1435
|
context.provider,
|
|
1419
1436
|
context.contextId,
|
|
1420
1437
|
text,
|
|
@@ -1436,9 +1453,11 @@ const keyboard = async (context, text) => {
|
|
|
1436
1453
|
},
|
|
1437
1454
|
true
|
|
1438
1455
|
);
|
|
1456
|
+
return {
|
|
1457
|
+
unreleased: Array.from(pressed)
|
|
1458
|
+
};
|
|
1439
1459
|
};
|
|
1440
|
-
async function keyboardImplementation(provider, contextId, text, selectAll, skipRelease) {
|
|
1441
|
-
const pressed = /* @__PURE__ */ new Set();
|
|
1460
|
+
async function keyboardImplementation(pressed, provider, contextId, text, selectAll, skipRelease) {
|
|
1442
1461
|
if (provider instanceof PlaywrightBrowserProvider) {
|
|
1443
1462
|
const page = provider.getPage(contextId);
|
|
1444
1463
|
const actions = parseKeyDef(defaultKeyMap, text);
|
|
@@ -1501,7 +1520,8 @@ async function keyboardImplementation(provider, contextId, text, selectAll, skip
|
|
|
1501
1520
|
}
|
|
1502
1521
|
}
|
|
1503
1522
|
}
|
|
1504
|
-
|
|
1523
|
+
const allRelease = keyboard2.toJSON().actions.every((action) => action.type === "keyUp");
|
|
1524
|
+
await keyboard2.perform(allRelease ? false : skipRelease);
|
|
1505
1525
|
}
|
|
1506
1526
|
return {
|
|
1507
1527
|
pressed
|
|
@@ -1510,13 +1530,15 @@ async function keyboardImplementation(provider, contextId, text, selectAll, skip
|
|
|
1510
1530
|
|
|
1511
1531
|
const type = async (context, selector, text, options = {}) => {
|
|
1512
1532
|
const { skipClick = false, skipAutoClose = false } = options;
|
|
1533
|
+
const unreleased = new Set(Reflect.get(options, "unreleased") ?? []);
|
|
1513
1534
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1514
1535
|
const { iframe } = context;
|
|
1515
|
-
const element = iframe.locator(
|
|
1536
|
+
const element = iframe.locator(selector);
|
|
1516
1537
|
if (!skipClick) {
|
|
1517
1538
|
await element.focus();
|
|
1518
1539
|
}
|
|
1519
1540
|
await keyboardImplementation(
|
|
1541
|
+
unreleased,
|
|
1520
1542
|
context.provider,
|
|
1521
1543
|
context.contextId,
|
|
1522
1544
|
text,
|
|
@@ -1530,6 +1552,7 @@ const type = async (context, selector, text, options = {}) => {
|
|
|
1530
1552
|
await element.click();
|
|
1531
1553
|
}
|
|
1532
1554
|
await keyboardImplementation(
|
|
1555
|
+
unreleased,
|
|
1533
1556
|
context.provider,
|
|
1534
1557
|
context.contextId,
|
|
1535
1558
|
text,
|
|
@@ -1544,12 +1567,15 @@ const type = async (context, selector, text, options = {}) => {
|
|
|
1544
1567
|
} else {
|
|
1545
1568
|
throw new TypeError(`Provider "${context.provider.name}" does not support typing`);
|
|
1546
1569
|
}
|
|
1570
|
+
return {
|
|
1571
|
+
unreleased: Array.from(unreleased)
|
|
1572
|
+
};
|
|
1547
1573
|
};
|
|
1548
1574
|
|
|
1549
1575
|
const clear = async (context, selector) => {
|
|
1550
1576
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1551
1577
|
const { iframe } = context;
|
|
1552
|
-
const element = iframe.locator(
|
|
1578
|
+
const element = iframe.locator(selector);
|
|
1553
1579
|
await element.clear({
|
|
1554
1580
|
timeout: 1e3
|
|
1555
1581
|
});
|
|
@@ -1565,7 +1591,7 @@ const clear = async (context, selector) => {
|
|
|
1565
1591
|
const fill = async (context, selector, text, options = {}) => {
|
|
1566
1592
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1567
1593
|
const { iframe } = context;
|
|
1568
|
-
const element = iframe.locator(
|
|
1594
|
+
const element = iframe.locator(selector);
|
|
1569
1595
|
await element.fill(text, { timeout: 1e3, ...options });
|
|
1570
1596
|
} else if (context.provider instanceof WebdriverBrowserProvider) {
|
|
1571
1597
|
const browser = context.browser;
|
|
@@ -1579,12 +1605,12 @@ const selectOptions = async (context, selector, userValues, options = {}) => {
|
|
|
1579
1605
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1580
1606
|
const value = userValues;
|
|
1581
1607
|
const { iframe } = context;
|
|
1582
|
-
const selectElement = iframe.locator(
|
|
1608
|
+
const selectElement = iframe.locator(selector);
|
|
1583
1609
|
const values = await Promise.all(value.map(async (v) => {
|
|
1584
1610
|
if (typeof v === "string") {
|
|
1585
1611
|
return v;
|
|
1586
1612
|
}
|
|
1587
|
-
const elementHandler = await iframe.locator(
|
|
1613
|
+
const elementHandler = await iframe.locator(v.element).elementHandle();
|
|
1588
1614
|
if (!elementHandler) {
|
|
1589
1615
|
throw new Error(`Element not found: ${v.element}`);
|
|
1590
1616
|
}
|
|
@@ -1627,22 +1653,23 @@ const tab = async (context, options = {}) => {
|
|
|
1627
1653
|
throw new Error(`Provider "${provider.name}" doesn't support tab command`);
|
|
1628
1654
|
};
|
|
1629
1655
|
|
|
1630
|
-
const dragAndDrop = async (context, source, target,
|
|
1656
|
+
const dragAndDrop = async (context, source, target, options_) => {
|
|
1631
1657
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1632
1658
|
const frame = await context.frame();
|
|
1633
1659
|
await frame.dragAndDrop(
|
|
1634
|
-
|
|
1635
|
-
|
|
1660
|
+
source,
|
|
1661
|
+
target,
|
|
1636
1662
|
{
|
|
1637
1663
|
timeout: 1e3,
|
|
1638
|
-
...
|
|
1664
|
+
...options_
|
|
1639
1665
|
}
|
|
1640
1666
|
);
|
|
1641
1667
|
} else if (context.provider instanceof WebdriverBrowserProvider) {
|
|
1642
1668
|
const $source = context.browser.$(source);
|
|
1643
1669
|
const $target = context.browser.$(target);
|
|
1644
|
-
const
|
|
1645
|
-
|
|
1670
|
+
const options = options_ || {};
|
|
1671
|
+
const duration = options.duration ?? 10;
|
|
1672
|
+
await context.browser.action("pointer").move({ duration: 0, origin: $source, x: options.sourceX ?? 0, y: options.sourceY ?? 0 }).down({ button: 0 }).move({ duration: 0, origin: "pointer", x: 0, y: 0 }).pause(duration).move({ duration: 0, origin: $target, x: options.targetX ?? 0, y: options.targetY ?? 0 }).move({ duration: 0, origin: "pointer", x: 1, y: 0 }).move({ duration: 0, origin: "pointer", x: -1, y: 0 }).up({ button: 0 }).perform();
|
|
1646
1673
|
} else {
|
|
1647
1674
|
throw new TypeError(`Provider "${context.provider.name}" does not support dragging elements`);
|
|
1648
1675
|
}
|
|
@@ -1650,7 +1677,7 @@ const dragAndDrop = async (context, source, target, options) => {
|
|
|
1650
1677
|
|
|
1651
1678
|
const hover = async (context, selector, options = {}) => {
|
|
1652
1679
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1653
|
-
await context.iframe.locator(
|
|
1680
|
+
await context.iframe.locator(selector).hover({
|
|
1654
1681
|
timeout: 1e3,
|
|
1655
1682
|
...options
|
|
1656
1683
|
});
|
|
@@ -1696,7 +1723,7 @@ const screenshot = async (context, name, options = {}) => {
|
|
|
1696
1723
|
if (!context.testPath) {
|
|
1697
1724
|
throw new Error(`Cannot take a screenshot without a test path`);
|
|
1698
1725
|
}
|
|
1699
|
-
const path = resolveScreenshotPath(
|
|
1726
|
+
const path = options.path ? resolve(context.testPath, options.path) : resolveScreenshotPath(
|
|
1700
1727
|
context.testPath,
|
|
1701
1728
|
name,
|
|
1702
1729
|
context.project.config
|
|
@@ -1705,8 +1732,8 @@ const screenshot = async (context, name, options = {}) => {
|
|
|
1705
1732
|
await mkdir(dirname(path), { recursive: true });
|
|
1706
1733
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1707
1734
|
if (options.element) {
|
|
1708
|
-
const { element:
|
|
1709
|
-
const element = context.iframe.locator(
|
|
1735
|
+
const { element: selector, ...config } = options;
|
|
1736
|
+
const element = context.iframe.locator(`${selector}`);
|
|
1710
1737
|
const buffer2 = await element.screenshot({
|
|
1711
1738
|
timeout: 1e3,
|
|
1712
1739
|
...config,
|
|
@@ -1830,7 +1857,8 @@ export const server = {
|
|
|
1830
1857
|
browser: ${JSON.stringify(server.project.config.browser.name)},
|
|
1831
1858
|
commands: {
|
|
1832
1859
|
${commandsCode}
|
|
1833
|
-
}
|
|
1860
|
+
},
|
|
1861
|
+
config: __vitest_browser_runner__.config,
|
|
1834
1862
|
}
|
|
1835
1863
|
export const commands = server.commands
|
|
1836
1864
|
export const userEvent = ${getUserEvent(provider)}
|
|
@@ -1842,10 +1870,17 @@ function getUserEvent(provider) {
|
|
|
1842
1870
|
return "__userEvent_CDP__";
|
|
1843
1871
|
}
|
|
1844
1872
|
return `{
|
|
1845
|
-
...
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1873
|
+
..._userEventSetup,
|
|
1874
|
+
setup() {
|
|
1875
|
+
const userEvent = __vitest_user_event__.setup()
|
|
1876
|
+
userEvent.setup = this.setup
|
|
1877
|
+
userEvent.fill = this.fill.bind(userEvent)
|
|
1878
|
+
userEvent.dragAndDrop = this.dragAndDrop
|
|
1879
|
+
return userEvent
|
|
1880
|
+
},
|
|
1881
|
+
async fill(element, text) {
|
|
1882
|
+
await this.clear(element)
|
|
1883
|
+
await this.type(element, text)
|
|
1849
1884
|
},
|
|
1850
1885
|
dragAndDrop: async () => {
|
|
1851
1886
|
throw new Error('Provider "preview" does not support dragging elements')
|
|
@@ -1862,7 +1897,9 @@ async function getUserEventImport(provider, resolve2) {
|
|
|
1862
1897
|
}
|
|
1863
1898
|
return `import { userEvent as __vitest_user_event__ } from '${slash(
|
|
1864
1899
|
`/@fs/${resolved.id}`
|
|
1865
|
-
)}'
|
|
1900
|
+
)}'
|
|
1901
|
+
const _userEventSetup = __vitest_user_event__.setup()
|
|
1902
|
+
`;
|
|
1866
1903
|
}
|
|
1867
1904
|
|
|
1868
1905
|
function injectDynamicImport(code, id, parse) {
|
|
@@ -1920,11 +1957,10 @@ async function resolveOrchestrator(server, url, res) {
|
|
|
1920
1957
|
contextId = contexts[contexts.length - 1] ?? "none";
|
|
1921
1958
|
}
|
|
1922
1959
|
const files = server.state.getContext(contextId)?.files ?? [];
|
|
1923
|
-
const config = server.getSerializableConfig();
|
|
1924
1960
|
const injectorJs = typeof server.injectorJs === "string" ? server.injectorJs : await server.injectorJs;
|
|
1925
1961
|
const injector = replacer(injectorJs, {
|
|
1926
1962
|
__VITEST_PROVIDER__: JSON.stringify(server.provider.name),
|
|
1927
|
-
__VITEST_CONFIG__: JSON.stringify(
|
|
1963
|
+
__VITEST_CONFIG__: JSON.stringify(server.getSerializableConfig()),
|
|
1928
1964
|
__VITEST_VITE_CONFIG__: JSON.stringify({
|
|
1929
1965
|
root: server.vite.config.root
|
|
1930
1966
|
}),
|
|
@@ -1960,7 +1996,7 @@ async function resolveOrchestrator(server, url, res) {
|
|
|
1960
1996
|
__VITEST_TITLE__: "Vitest Browser Runner",
|
|
1961
1997
|
__VITEST_SCRIPTS__: server.orchestratorScripts,
|
|
1962
1998
|
__VITEST_INJECTOR__: `<script type="module">${injector}<\/script>`,
|
|
1963
|
-
__VITEST_ERROR_CATCHER__: `<script type="module" src="${server.
|
|
1999
|
+
__VITEST_ERROR_CATCHER__: `<script type="module" src="${server.errorCatcherUrl}"><\/script>`,
|
|
1964
2000
|
__VITEST_CONTEXT_ID__: JSON.stringify(contextId)
|
|
1965
2001
|
});
|
|
1966
2002
|
}
|
|
@@ -1983,10 +2019,9 @@ async function resolveTester(server, url, res) {
|
|
|
1983
2019
|
const files = context?.files ?? [];
|
|
1984
2020
|
const method = context?.method ?? "run";
|
|
1985
2021
|
const injectorJs = typeof server.injectorJs === "string" ? server.injectorJs : await server.injectorJs;
|
|
1986
|
-
const config = server.getSerializableConfig();
|
|
1987
2022
|
const injector = replacer(injectorJs, {
|
|
1988
2023
|
__VITEST_PROVIDER__: JSON.stringify(server.provider.name),
|
|
1989
|
-
__VITEST_CONFIG__: JSON.stringify(
|
|
2024
|
+
__VITEST_CONFIG__: JSON.stringify(server.getSerializableConfig()),
|
|
1990
2025
|
__VITEST_FILES__: JSON.stringify(files),
|
|
1991
2026
|
__VITEST_VITE_CONFIG__: JSON.stringify({
|
|
1992
2027
|
root: server.vite.config.root
|
|
@@ -2000,7 +2035,7 @@ async function resolveTester(server, url, res) {
|
|
|
2000
2035
|
const testerScripts = await server.formatScripts(
|
|
2001
2036
|
project.config.browser.testerScripts
|
|
2002
2037
|
);
|
|
2003
|
-
const clientScript = `<script type="module" src="${config.base || "/"}@vite/client"><\/script>`;
|
|
2038
|
+
const clientScript = `<script type="module" src="${server.project.config.base || "/"}@vite/client"><\/script>`;
|
|
2004
2039
|
const stateJs = typeof server.stateJs === "string" ? server.stateJs : await server.stateJs;
|
|
2005
2040
|
const stateScript = `<script type="module">${stateJs}<\/script>`;
|
|
2006
2041
|
server.testerScripts = `${stateScript}${clientScript}${testerScripts}`;
|
|
@@ -2011,7 +2046,10 @@ async function resolveTester(server, url, res) {
|
|
|
2011
2046
|
__VITEST_TITLE__: "Vitest Browser Tester",
|
|
2012
2047
|
__VITEST_SCRIPTS__: server.testerScripts,
|
|
2013
2048
|
__VITEST_INJECTOR__: `<script type="module">${injector}<\/script>`,
|
|
2014
|
-
|
|
2049
|
+
__VITEST_INTERNAL_SCRIPTS__: [
|
|
2050
|
+
`<script type="module" src="${server.errorCatcherUrl}"><\/script>`,
|
|
2051
|
+
server.locatorsUrl ? `<script type="module" src="${server.locatorsUrl}"><\/script>` : ""
|
|
2052
|
+
].join("\n"),
|
|
2015
2053
|
__VITEST_APPEND__: `<script type="module">
|
|
2016
2054
|
__vitest_browser_runner__.runningFiles = ${tests}
|
|
2017
2055
|
__vitest_browser_runner__.iframeId = ${iframeId}
|