@vitest/browser 2.0.0-beta.12 → 2.0.0-beta.13
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/context.d.ts +21 -5
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/index-C-LD6Fid.js +52 -0
- package/dist/client/__vitest__/assets/{index-goqgbqVs.css → index-DEM1IsBG.css} +1 -1
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{client-Dz5Ebwug.js → client-dLyjuL0K.js} +10 -72
- package/dist/client/__vitest_browser__/{orchestrator-DJ6H4qlM.js → orchestrator-x0A1t8rC.js} +6 -8
- package/dist/client/__vitest_browser__/{tester-DHXll_4H.js → tester-BdcP5piS.js} +272 -366
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- package/dist/context.js +78 -50
- package/dist/index.d.ts +8 -1
- package/dist/index.js +144 -63
- package/dist/providers.js +2 -2
- package/dist/{webdriver-CJA71Bgl.js → webdriver-BdVqnfdE.js} +26 -4
- package/package.json +11 -11
- package/dist/client/__vitest__/assets/index-BcWipdNi.js +0 -52
package/dist/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { createDebugger, isFileServingAllowed as isFileServingAllowed$1, getFilePoolName, resolveApiServerConfig, resolveFsAllow, distDir, createServer } from 'vitest/node';
|
|
2
|
-
import fs, { existsSync, readdirSync,
|
|
2
|
+
import fs, { existsSync, readdirSync, readFileSync, promises } from 'node:fs';
|
|
3
3
|
import { WebSocketServer } from 'ws';
|
|
4
4
|
import { isFileServingAllowed } from 'vite';
|
|
5
5
|
import { builtinModules, createRequire } from 'node:module';
|
|
6
6
|
import { readFile as readFile$1, mkdir } from 'node:fs/promises';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
import { createDefer, slash, toArray } from '@vitest/utils';
|
|
9
|
+
import { parseErrorStacktrace, parseStacktrace } from '@vitest/utils/source-map';
|
|
9
10
|
import sirv from 'sirv';
|
|
10
11
|
import { defaultBrowserPort, coverageConfigDefaults } from 'vitest/config';
|
|
11
|
-
import { P as PlaywrightBrowserProvider, W as WebdriverBrowserProvider } from './webdriver-
|
|
12
|
+
import { P as PlaywrightBrowserProvider, W as WebdriverBrowserProvider } from './webdriver-BdVqnfdE.js';
|
|
12
13
|
import { resolve as resolve$1, dirname as dirname$1, normalize as normalize$1 } from 'node:path';
|
|
13
14
|
import MagicString from 'magic-string';
|
|
14
15
|
import { esmWalker } from '@vitest/utils/ast';
|
|
@@ -406,7 +407,9 @@ const stringify = (value, replacer, space) => {
|
|
|
406
407
|
async function resolveMock(project, rawId, importer, hasFactory) {
|
|
407
408
|
const { id, fsPath, external } = await resolveId(project, rawId, importer);
|
|
408
409
|
if (hasFactory) {
|
|
409
|
-
|
|
410
|
+
const needsInteropMap = viteDepsInteropMap(project.browser.vite.config);
|
|
411
|
+
const needsInterop = needsInteropMap?.get(fsPath) ?? false;
|
|
412
|
+
return { type: "factory", resolvedId: id, needsInterop };
|
|
410
413
|
}
|
|
411
414
|
const mockPath = resolveMockPath(project.config.root, fsPath, external);
|
|
412
415
|
return {
|
|
@@ -497,6 +500,29 @@ const postfixRE = /[?#].*$/;
|
|
|
497
500
|
function cleanUrl(url) {
|
|
498
501
|
return url.replace(postfixRE, "");
|
|
499
502
|
}
|
|
503
|
+
const metadata = /* @__PURE__ */ new WeakMap();
|
|
504
|
+
function viteDepsInteropMap(config) {
|
|
505
|
+
if (metadata.has(config)) {
|
|
506
|
+
return metadata.get(config);
|
|
507
|
+
}
|
|
508
|
+
const cacheDirPath = getDepsCacheDir(config);
|
|
509
|
+
const metadataPath = resolve(cacheDirPath, "_metadata.json");
|
|
510
|
+
if (!existsSync(metadataPath)) {
|
|
511
|
+
return null;
|
|
512
|
+
}
|
|
513
|
+
const { optimized } = JSON.parse(readFileSync(metadataPath, "utf-8"));
|
|
514
|
+
const needsInteropMap = /* @__PURE__ */ new Map();
|
|
515
|
+
for (const name in optimized) {
|
|
516
|
+
const dep = optimized[name];
|
|
517
|
+
const file = resolve(cacheDirPath, dep.file);
|
|
518
|
+
needsInteropMap.set(file, dep.needsInterop);
|
|
519
|
+
}
|
|
520
|
+
metadata.set(config, needsInteropMap);
|
|
521
|
+
return needsInteropMap;
|
|
522
|
+
}
|
|
523
|
+
function getDepsCacheDir(config) {
|
|
524
|
+
return resolve(config.cacheDir, "deps");
|
|
525
|
+
}
|
|
500
526
|
|
|
501
527
|
const debug$1 = createDebugger("vitest:browser:api");
|
|
502
528
|
const BROWSER_API_PATH = "/__vitest_browser_api__";
|
|
@@ -711,10 +737,11 @@ class BrowserServerState {
|
|
|
711
737
|
getContext(contextId) {
|
|
712
738
|
return this.contexts.get(contextId);
|
|
713
739
|
}
|
|
714
|
-
createAsyncContext(contextId, files) {
|
|
740
|
+
createAsyncContext(method, contextId, files) {
|
|
715
741
|
const defer = createDefer();
|
|
716
742
|
this.contexts.set(contextId, {
|
|
717
743
|
files,
|
|
744
|
+
method,
|
|
718
745
|
resolve: () => {
|
|
719
746
|
defer.resolve();
|
|
720
747
|
this.contexts.delete(contextId);
|
|
@@ -804,6 +831,24 @@ class BrowserServer {
|
|
|
804
831
|
constructor(project, base) {
|
|
805
832
|
this.project = project;
|
|
806
833
|
this.base = base;
|
|
834
|
+
this.stackTraceOptions = {
|
|
835
|
+
frameFilter: project.config.onStackTrace,
|
|
836
|
+
getSourceMap: (id) => {
|
|
837
|
+
const result = this.vite.moduleGraph.getModuleById(id)?.transformResult;
|
|
838
|
+
return result?.map;
|
|
839
|
+
},
|
|
840
|
+
getFileName: (id) => {
|
|
841
|
+
const mod = this.vite.moduleGraph.getModuleById(id);
|
|
842
|
+
if (mod?.file) {
|
|
843
|
+
return mod.file;
|
|
844
|
+
}
|
|
845
|
+
const modUrl = this.vite.moduleGraph.urlToModuleMap.get(id);
|
|
846
|
+
if (modUrl?.file) {
|
|
847
|
+
return modUrl.file;
|
|
848
|
+
}
|
|
849
|
+
return id;
|
|
850
|
+
}
|
|
851
|
+
};
|
|
807
852
|
this.state = new BrowserServerState();
|
|
808
853
|
const pkgRoot = resolve(fileURLToPath(import.meta.url), "../..");
|
|
809
854
|
const distRoot = resolve(pkgRoot, "dist");
|
|
@@ -840,6 +885,7 @@ class BrowserServer {
|
|
|
840
885
|
state;
|
|
841
886
|
provider;
|
|
842
887
|
vite;
|
|
888
|
+
stackTraceOptions;
|
|
843
889
|
setServer(server) {
|
|
844
890
|
this.vite = server;
|
|
845
891
|
}
|
|
@@ -894,6 +940,18 @@ class BrowserServer {
|
|
|
894
940
|
options: providerOptions
|
|
895
941
|
});
|
|
896
942
|
}
|
|
943
|
+
parseErrorStacktrace(e, options = {}) {
|
|
944
|
+
return parseErrorStacktrace(e, {
|
|
945
|
+
...this.stackTraceOptions,
|
|
946
|
+
...options
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
parseStacktrace(trace, options = {}) {
|
|
950
|
+
return parseStacktrace(trace, {
|
|
951
|
+
...this.stackTraceOptions,
|
|
952
|
+
...options
|
|
953
|
+
});
|
|
954
|
+
}
|
|
897
955
|
cdpSessions = /* @__PURE__ */ new Map();
|
|
898
956
|
async ensureCDPHandler(contextId, sessionId) {
|
|
899
957
|
const cachedHandler = this.state.cdps.get(sessionId);
|
|
@@ -935,35 +993,49 @@ function wrapConfig(config) {
|
|
|
935
993
|
};
|
|
936
994
|
}
|
|
937
995
|
|
|
938
|
-
const click = async (context,
|
|
996
|
+
const click = async (context, selector, options = {}) => {
|
|
939
997
|
const provider = context.provider;
|
|
940
998
|
if (provider instanceof PlaywrightBrowserProvider) {
|
|
941
999
|
const tester = context.iframe;
|
|
942
|
-
await tester.locator(`
|
|
1000
|
+
await tester.locator(`css=${selector}`).click({
|
|
943
1001
|
timeout: 1e3,
|
|
944
1002
|
...options
|
|
945
1003
|
});
|
|
946
1004
|
} else if (provider instanceof WebdriverBrowserProvider) {
|
|
947
1005
|
const browser = context.browser;
|
|
948
|
-
|
|
949
|
-
await browser.$(markedXpath).click(options);
|
|
1006
|
+
await browser.$(selector).click(options);
|
|
950
1007
|
} else {
|
|
951
1008
|
throw new TypeError(`Provider "${provider.name}" doesn't support click command`);
|
|
952
1009
|
}
|
|
953
1010
|
};
|
|
954
|
-
const dblClick = async (context,
|
|
1011
|
+
const dblClick = async (context, selector, options = {}) => {
|
|
955
1012
|
const provider = context.provider;
|
|
956
1013
|
if (provider instanceof PlaywrightBrowserProvider) {
|
|
957
1014
|
const tester = context.iframe;
|
|
958
|
-
await tester.locator(`
|
|
1015
|
+
await tester.locator(`css=${selector}`).dblclick(options);
|
|
959
1016
|
} else if (provider instanceof WebdriverBrowserProvider) {
|
|
960
1017
|
const browser = context.browser;
|
|
961
|
-
|
|
962
|
-
await browser.$(markedXpath).doubleClick();
|
|
1018
|
+
await browser.$(selector).doubleClick();
|
|
963
1019
|
} else {
|
|
964
1020
|
throw new TypeError(`Provider "${provider.name}" doesn't support dblClick command`);
|
|
965
1021
|
}
|
|
966
1022
|
};
|
|
1023
|
+
const tripleClick = async (context, selector, options = {}) => {
|
|
1024
|
+
const provider = context.provider;
|
|
1025
|
+
if (provider instanceof PlaywrightBrowserProvider) {
|
|
1026
|
+
const tester = context.iframe;
|
|
1027
|
+
await tester.locator(`css=${selector}`).click({
|
|
1028
|
+
timeout: 1e3,
|
|
1029
|
+
...options,
|
|
1030
|
+
clickCount: 3
|
|
1031
|
+
});
|
|
1032
|
+
} else if (provider instanceof WebdriverBrowserProvider) {
|
|
1033
|
+
const browser = context.browser;
|
|
1034
|
+
await browser.action("pointer", { parameters: { pointerType: "mouse" } }).move({ origin: await browser.$(selector) }).down().up().pause(50).down().up().pause(50).down().up().pause(50).perform();
|
|
1035
|
+
} else {
|
|
1036
|
+
throw new TypeError(`Provider "${provider.name}" doesn't support tripleClick command`);
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
967
1039
|
|
|
968
1040
|
var clickableInputTypes;
|
|
969
1041
|
(function(clickableInputTypes) {
|
|
@@ -1435,11 +1507,11 @@ async function keyboardImplementation(provider, contextId, text, selectAll, skip
|
|
|
1435
1507
|
};
|
|
1436
1508
|
}
|
|
1437
1509
|
|
|
1438
|
-
const type = async (context,
|
|
1510
|
+
const type = async (context, selector, text, options = {}) => {
|
|
1439
1511
|
const { skipClick = false, skipAutoClose = false } = options;
|
|
1440
1512
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1441
1513
|
const { iframe } = context;
|
|
1442
|
-
const element = iframe.locator(`
|
|
1514
|
+
const element = iframe.locator(`css=${selector}`);
|
|
1443
1515
|
if (!skipClick) {
|
|
1444
1516
|
await element.focus();
|
|
1445
1517
|
}
|
|
@@ -1452,8 +1524,7 @@ const type = async (context, xpath, text, options = {}) => {
|
|
|
1452
1524
|
);
|
|
1453
1525
|
} else if (context.provider instanceof WebdriverBrowserProvider) {
|
|
1454
1526
|
const browser = context.browser;
|
|
1455
|
-
const
|
|
1456
|
-
const element = browser.$(markedXpath);
|
|
1527
|
+
const element = browser.$(selector);
|
|
1457
1528
|
if (!skipClick && !await element.isFocused()) {
|
|
1458
1529
|
await element.click();
|
|
1459
1530
|
}
|
|
@@ -1474,47 +1545,45 @@ const type = async (context, xpath, text, options = {}) => {
|
|
|
1474
1545
|
}
|
|
1475
1546
|
};
|
|
1476
1547
|
|
|
1477
|
-
const clear = async (context,
|
|
1548
|
+
const clear = async (context, selector) => {
|
|
1478
1549
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1479
1550
|
const { iframe } = context;
|
|
1480
|
-
const element = iframe.locator(`
|
|
1551
|
+
const element = iframe.locator(`css=${selector}`);
|
|
1481
1552
|
await element.clear({
|
|
1482
1553
|
timeout: 1e3
|
|
1483
1554
|
});
|
|
1484
1555
|
} else if (context.provider instanceof WebdriverBrowserProvider) {
|
|
1485
1556
|
const browser = context.browser;
|
|
1486
|
-
const
|
|
1487
|
-
const element = await browser.$(markedXpath);
|
|
1557
|
+
const element = await browser.$(selector);
|
|
1488
1558
|
await element.clearValue();
|
|
1489
1559
|
} else {
|
|
1490
1560
|
throw new TypeError(`Provider "${context.provider.name}" does not support clearing elements`);
|
|
1491
1561
|
}
|
|
1492
1562
|
};
|
|
1493
1563
|
|
|
1494
|
-
const fill = async (context,
|
|
1564
|
+
const fill = async (context, selector, text, options = {}) => {
|
|
1495
1565
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1496
1566
|
const { iframe } = context;
|
|
1497
|
-
const element = iframe.locator(`
|
|
1567
|
+
const element = iframe.locator(`css=${selector}`);
|
|
1498
1568
|
await element.fill(text, { timeout: 1e3, ...options });
|
|
1499
1569
|
} else if (context.provider instanceof WebdriverBrowserProvider) {
|
|
1500
1570
|
const browser = context.browser;
|
|
1501
|
-
|
|
1502
|
-
await browser.$(markedXpath).setValue(text);
|
|
1571
|
+
await browser.$(selector).setValue(text);
|
|
1503
1572
|
} else {
|
|
1504
1573
|
throw new TypeError(`Provider "${context.provider.name}" does not support clearing elements`);
|
|
1505
1574
|
}
|
|
1506
1575
|
};
|
|
1507
1576
|
|
|
1508
|
-
const selectOptions = async (context,
|
|
1577
|
+
const selectOptions = async (context, selector, userValues, options = {}) => {
|
|
1509
1578
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1510
1579
|
const value = userValues;
|
|
1511
1580
|
const { iframe } = context;
|
|
1512
|
-
const selectElement = iframe.locator(`
|
|
1581
|
+
const selectElement = iframe.locator(`css=${selector}`);
|
|
1513
1582
|
const values = await Promise.all(value.map(async (v) => {
|
|
1514
1583
|
if (typeof v === "string") {
|
|
1515
1584
|
return v;
|
|
1516
1585
|
}
|
|
1517
|
-
const elementHandler = await iframe.locator(`
|
|
1586
|
+
const elementHandler = await iframe.locator(`css=${v.element}`).elementHandle();
|
|
1518
1587
|
if (!elementHandler) {
|
|
1519
1588
|
throw new Error(`Element not found: ${v.element}`);
|
|
1520
1589
|
}
|
|
@@ -1529,10 +1598,9 @@ const selectOptions = async (context, xpath, userValues, options = {}) => {
|
|
|
1529
1598
|
if (!values.length) {
|
|
1530
1599
|
return;
|
|
1531
1600
|
}
|
|
1532
|
-
const markedXpath = `//${xpath}`;
|
|
1533
1601
|
const browser = context.browser;
|
|
1534
1602
|
if (values.length === 1 && "index" in values[0]) {
|
|
1535
|
-
const selectElement = browser.$(
|
|
1603
|
+
const selectElement = browser.$(selector);
|
|
1536
1604
|
await selectElement.selectByIndex(values[0].index);
|
|
1537
1605
|
} else {
|
|
1538
1606
|
throw new Error(`Provider "webdriverio" doesn't support selecting multiple values at once`);
|
|
@@ -1562,18 +1630,16 @@ const dragAndDrop = async (context, source, target, options) => {
|
|
|
1562
1630
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1563
1631
|
const frame = await context.frame();
|
|
1564
1632
|
await frame.dragAndDrop(
|
|
1565
|
-
`
|
|
1566
|
-
`
|
|
1633
|
+
`css=${source}`,
|
|
1634
|
+
`css=${target}`,
|
|
1567
1635
|
{
|
|
1568
1636
|
timeout: 1e3,
|
|
1569
1637
|
...options
|
|
1570
1638
|
}
|
|
1571
1639
|
);
|
|
1572
1640
|
} else if (context.provider instanceof WebdriverBrowserProvider) {
|
|
1573
|
-
const
|
|
1574
|
-
const
|
|
1575
|
-
const $source = context.browser.$(sourceXpath);
|
|
1576
|
-
const $target = context.browser.$(targetXpath);
|
|
1641
|
+
const $source = context.browser.$(source);
|
|
1642
|
+
const $target = context.browser.$(target);
|
|
1577
1643
|
const duration = options?.duration ?? 10;
|
|
1578
1644
|
await context.browser.action("pointer").move({ duration: 0, origin: $source, x: 0, y: 0 }).down({ button: 0 }).move({ duration: 0, origin: "pointer", x: 0, y: 0 }).pause(duration).move({ duration: 0, origin: $target, x: 0, y: 0 }).move({ duration: 0, origin: "pointer", x: 1, y: 0 }).move({ duration: 0, origin: "pointer", x: -1, y: 0 }).up({ button: 0 }).perform();
|
|
1579
1645
|
} else {
|
|
@@ -1581,16 +1647,15 @@ const dragAndDrop = async (context, source, target, options) => {
|
|
|
1581
1647
|
}
|
|
1582
1648
|
};
|
|
1583
1649
|
|
|
1584
|
-
const hover = async (context,
|
|
1650
|
+
const hover = async (context, selector, options = {}) => {
|
|
1585
1651
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1586
|
-
await context.iframe.locator(`
|
|
1652
|
+
await context.iframe.locator(`css=${selector}`).hover({
|
|
1587
1653
|
timeout: 1e3,
|
|
1588
1654
|
...options
|
|
1589
1655
|
});
|
|
1590
1656
|
} else if (context.provider instanceof WebdriverBrowserProvider) {
|
|
1591
1657
|
const browser = context.browser;
|
|
1592
|
-
|
|
1593
|
-
await browser.$(markedXpath).moveTo(options);
|
|
1658
|
+
await browser.$(selector).moveTo(options);
|
|
1594
1659
|
} else {
|
|
1595
1660
|
throw new TypeError(`Provider "${context.provider.name}" does not support hover`);
|
|
1596
1661
|
}
|
|
@@ -1639,28 +1704,31 @@ const screenshot = async (context, name, options = {}) => {
|
|
|
1639
1704
|
await mkdir(dirname(path), { recursive: true });
|
|
1640
1705
|
if (context.provider instanceof PlaywrightBrowserProvider) {
|
|
1641
1706
|
if (options.element) {
|
|
1642
|
-
const { element:
|
|
1643
|
-
const element = context.iframe.locator(`
|
|
1644
|
-
await element.screenshot({
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
...options,
|
|
1707
|
+
const { element: css, ...config } = options;
|
|
1708
|
+
const element = context.iframe.locator(`css=${css}`);
|
|
1709
|
+
const buffer2 = await element.screenshot({
|
|
1710
|
+
timeout: 1e3,
|
|
1711
|
+
...config,
|
|
1648
1712
|
path: savePath
|
|
1649
1713
|
});
|
|
1714
|
+
return returnResult(options, path, buffer2);
|
|
1650
1715
|
}
|
|
1651
|
-
|
|
1716
|
+
const buffer = await context.iframe.locator("body").screenshot({
|
|
1717
|
+
...options,
|
|
1718
|
+
path: savePath
|
|
1719
|
+
});
|
|
1720
|
+
return returnResult(options, path, buffer);
|
|
1652
1721
|
}
|
|
1653
1722
|
if (context.provider instanceof WebdriverBrowserProvider) {
|
|
1654
1723
|
const page = context.provider.browser;
|
|
1655
1724
|
if (!options.element) {
|
|
1656
1725
|
const body = await page.$("body");
|
|
1657
|
-
await body.saveScreenshot(savePath);
|
|
1658
|
-
return path;
|
|
1726
|
+
const buffer2 = await body.saveScreenshot(savePath);
|
|
1727
|
+
return returnResult(options, path, buffer2);
|
|
1659
1728
|
}
|
|
1660
|
-
const
|
|
1661
|
-
const
|
|
1662
|
-
|
|
1663
|
-
return path;
|
|
1729
|
+
const element = await page.$(`${options.element}`);
|
|
1730
|
+
const buffer = await element.saveScreenshot(savePath);
|
|
1731
|
+
return returnResult(options, path, buffer);
|
|
1664
1732
|
}
|
|
1665
1733
|
throw new Error(
|
|
1666
1734
|
`Provider "${context.provider.name}" does not support screenshots`
|
|
@@ -1679,6 +1747,12 @@ function resolveScreenshotPath(testPath, name, config) {
|
|
|
1679
1747
|
}
|
|
1680
1748
|
return resolve(dir, "__screenshots__", base, name);
|
|
1681
1749
|
}
|
|
1750
|
+
function returnResult(options, path, buffer) {
|
|
1751
|
+
if (options.base64) {
|
|
1752
|
+
return { path, base64: buffer.toString("base64") };
|
|
1753
|
+
}
|
|
1754
|
+
return path;
|
|
1755
|
+
}
|
|
1682
1756
|
|
|
1683
1757
|
var builtinCommands = {
|
|
1684
1758
|
readFile,
|
|
@@ -1686,6 +1760,7 @@ var builtinCommands = {
|
|
|
1686
1760
|
writeFile,
|
|
1687
1761
|
__vitest_click: click,
|
|
1688
1762
|
__vitest_dblClick: dblClick,
|
|
1763
|
+
__vitest_tripleClick: tripleClick,
|
|
1689
1764
|
__vitest_screenshot: screenshot,
|
|
1690
1765
|
__vitest_type: type,
|
|
1691
1766
|
__vitest_clear: clear,
|
|
@@ -1900,7 +1975,9 @@ async function resolveTester(server, url, res) {
|
|
|
1900
1975
|
const testFiles = await project.globTestFiles();
|
|
1901
1976
|
const tests = testFile === "__vitest_all__" || !testFiles.includes(testFile) ? "__vitest_browser_runner__.files" : JSON.stringify([testFile]);
|
|
1902
1977
|
const iframeId = JSON.stringify(testFile);
|
|
1903
|
-
const
|
|
1978
|
+
const context = state.getContext(contextId);
|
|
1979
|
+
const files = context?.files ?? [];
|
|
1980
|
+
const method = context?.method ?? "run";
|
|
1904
1981
|
const injectorJs = typeof server.injectorJs === "string" ? server.injectorJs : await server.injectorJs;
|
|
1905
1982
|
const config = server.getSerializableConfig();
|
|
1906
1983
|
const injector = replacer(injectorJs, {
|
|
@@ -1932,7 +2009,7 @@ async function resolveTester(server, url, res) {
|
|
|
1932
2009
|
__VITEST_APPEND__: `<script type="module">
|
|
1933
2010
|
__vitest_browser_runner__.runningFiles = ${tests}
|
|
1934
2011
|
__vitest_browser_runner__.iframeId = ${iframeId}
|
|
1935
|
-
__vitest_browser_runner__
|
|
2012
|
+
__vitest_browser_runner__.${method === "run" ? "runTests" : "collectTests"}(__vitest_browser_runner__.runningFiles)
|
|
1936
2013
|
<\/script>`
|
|
1937
2014
|
});
|
|
1938
2015
|
}
|
|
@@ -2057,6 +2134,9 @@ var BrowserPlugin = (browserServer, base = "/") => {
|
|
|
2057
2134
|
}
|
|
2058
2135
|
return {
|
|
2059
2136
|
define,
|
|
2137
|
+
resolve: {
|
|
2138
|
+
dedupe: ["vitest"]
|
|
2139
|
+
},
|
|
2060
2140
|
optimizeDeps: {
|
|
2061
2141
|
entries,
|
|
2062
2142
|
exclude: [
|
|
@@ -2087,7 +2167,7 @@ var BrowserPlugin = (browserServer, base = "/") => {
|
|
|
2087
2167
|
"vitest > pretty-format > ansi-regex",
|
|
2088
2168
|
"vitest > chai",
|
|
2089
2169
|
"vitest > chai > loupe",
|
|
2090
|
-
"vitest > @vitest/runner >
|
|
2170
|
+
"vitest > @vitest/runner > pretty-format",
|
|
2091
2171
|
"vitest > @vitest/utils > diff-sequences",
|
|
2092
2172
|
"vitest > @vitest/utils > loupe",
|
|
2093
2173
|
"@vitest/browser > @testing-library/user-event",
|
|
@@ -2265,11 +2345,11 @@ function resolveCoverageFolder(project) {
|
|
|
2265
2345
|
const debug = createDebugger("vitest:browser:pool");
|
|
2266
2346
|
function createBrowserPool(ctx) {
|
|
2267
2347
|
const providers = /* @__PURE__ */ new Set();
|
|
2268
|
-
const waitForTests = async (contextId, project, files) => {
|
|
2269
|
-
const context = project.browser.state.createAsyncContext(contextId, files);
|
|
2348
|
+
const waitForTests = async (method, contextId, project, files) => {
|
|
2349
|
+
const context = project.browser.state.createAsyncContext(method, contextId, files);
|
|
2270
2350
|
return await context;
|
|
2271
2351
|
};
|
|
2272
|
-
const
|
|
2352
|
+
const executeTests = async (method, project, files) => {
|
|
2273
2353
|
ctx.state.clearFiles(project, files);
|
|
2274
2354
|
const browser = project.browser;
|
|
2275
2355
|
const threadsCount = getThreadsCount(project);
|
|
@@ -2305,12 +2385,12 @@ function createBrowserPool(ctx) {
|
|
|
2305
2385
|
contextId,
|
|
2306
2386
|
[...files2.map((f) => relative(project.config.root, f))].join(", ")
|
|
2307
2387
|
);
|
|
2308
|
-
const promise = waitForTests(contextId, project, files2);
|
|
2388
|
+
const promise = waitForTests(method, contextId, project, files2);
|
|
2309
2389
|
promises.push(promise);
|
|
2310
2390
|
orchestrator.createTesters(files2);
|
|
2311
2391
|
} else {
|
|
2312
2392
|
const contextId = crypto.randomUUID();
|
|
2313
|
-
const waitPromise = waitForTests(contextId, project, files2);
|
|
2393
|
+
const waitPromise = waitForTests(method, contextId, project, files2);
|
|
2314
2394
|
debug?.(
|
|
2315
2395
|
"Opening a new context %s for files: %s",
|
|
2316
2396
|
contextId,
|
|
@@ -2324,7 +2404,7 @@ function createBrowserPool(ctx) {
|
|
|
2324
2404
|
});
|
|
2325
2405
|
await Promise.all(promises);
|
|
2326
2406
|
};
|
|
2327
|
-
const runWorkspaceTests = async (specs) => {
|
|
2407
|
+
const runWorkspaceTests = async (method, specs) => {
|
|
2328
2408
|
const groupedFiles = /* @__PURE__ */ new Map();
|
|
2329
2409
|
for (const [project, file] of specs) {
|
|
2330
2410
|
const files = groupedFiles.get(project) || [];
|
|
@@ -2339,7 +2419,7 @@ function createBrowserPool(ctx) {
|
|
|
2339
2419
|
if (isCancelled) {
|
|
2340
2420
|
break;
|
|
2341
2421
|
}
|
|
2342
|
-
await
|
|
2422
|
+
await executeTests(method, project, files);
|
|
2343
2423
|
}
|
|
2344
2424
|
};
|
|
2345
2425
|
const numCpus = typeof nodeos.availableParallelism === "function" ? nodeos.availableParallelism() : nodeos.cpus().length;
|
|
@@ -2359,7 +2439,8 @@ function createBrowserPool(ctx) {
|
|
|
2359
2439
|
await Promise.all([...providers].map((provider) => provider.close()));
|
|
2360
2440
|
providers.clear();
|
|
2361
2441
|
},
|
|
2362
|
-
runTests: runWorkspaceTests
|
|
2442
|
+
runTests: (files) => runWorkspaceTests("run", files),
|
|
2443
|
+
collectTests: (files) => runWorkspaceTests("collect", files)
|
|
2363
2444
|
};
|
|
2364
2445
|
}
|
|
2365
2446
|
|
package/dist/providers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { W as WebdriverBrowserProvider, P as PlaywrightBrowserProvider } from './webdriver-
|
|
1
|
+
import { W as WebdriverBrowserProvider, P as PlaywrightBrowserProvider } from './webdriver-BdVqnfdE.js';
|
|
2
2
|
|
|
3
3
|
class PreviewBrowserProvider {
|
|
4
4
|
name = "preview";
|
|
@@ -19,7 +19,7 @@ class PreviewBrowserProvider {
|
|
|
19
19
|
this.open = false;
|
|
20
20
|
if (ctx.config.browser.headless) {
|
|
21
21
|
throw new Error(
|
|
22
|
-
`You've enabled headless mode for "preview" provider but it doesn't support it. Use "playwright" or "webdriverio" instead: https://vitest.dev/guide/browser
|
|
22
|
+
`You've enabled headless mode for "preview" provider but it doesn't support it. Use "playwright" or "webdriverio" instead: https://vitest.dev/guide/browser/#configuration`
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -27,10 +27,19 @@ class PlaywrightBrowserProvider {
|
|
|
27
27
|
this.browserPromise = (async () => {
|
|
28
28
|
const options = this.ctx.config.browser;
|
|
29
29
|
const playwright = await import('playwright');
|
|
30
|
-
const
|
|
30
|
+
const launchOptions = {
|
|
31
31
|
...this.options?.launch,
|
|
32
32
|
headless: options.headless
|
|
33
|
-
}
|
|
33
|
+
};
|
|
34
|
+
if (this.ctx.config.browser.ui && this.browserName === "chromium") {
|
|
35
|
+
if (!launchOptions.args) {
|
|
36
|
+
launchOptions.args = [];
|
|
37
|
+
}
|
|
38
|
+
if (!launchOptions.args.includes("--start-maximized") && !launchOptions.args.includes("--start-fullscreen")) {
|
|
39
|
+
launchOptions.args.push("--start-maximized");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const browser = await playwright[this.browserName].launch(launchOptions);
|
|
34
43
|
this.browser = browser;
|
|
35
44
|
this.browserPromise = null;
|
|
36
45
|
return this.browser;
|
|
@@ -42,11 +51,15 @@ class PlaywrightBrowserProvider {
|
|
|
42
51
|
return this.contexts.get(contextId);
|
|
43
52
|
}
|
|
44
53
|
const browser = await this.openBrowser();
|
|
45
|
-
const
|
|
54
|
+
const options = {
|
|
46
55
|
...this.options?.context,
|
|
47
56
|
ignoreHTTPSErrors: true,
|
|
48
57
|
serviceWorkers: "allow"
|
|
49
|
-
}
|
|
58
|
+
};
|
|
59
|
+
if (this.ctx.config.browser.ui) {
|
|
60
|
+
options.viewport = null;
|
|
61
|
+
}
|
|
62
|
+
const context = await browser.newContext(options);
|
|
50
63
|
this.contexts.set(contextId, context);
|
|
51
64
|
return context;
|
|
52
65
|
}
|
|
@@ -210,6 +223,15 @@ class WebdriverBrowserProvider {
|
|
|
210
223
|
const newArgs = [...currentValues.args || [], ...args];
|
|
211
224
|
capabilities[key] = { ...currentValues, args: newArgs };
|
|
212
225
|
}
|
|
226
|
+
if (options.ui && (browser === "chrome" || browser === "edge")) {
|
|
227
|
+
const key = browser === "chrome" ? "goog:chromeOptions" : "ms:edgeOptions";
|
|
228
|
+
const args = capabilities[key]?.args || [];
|
|
229
|
+
if (!args.includes("--start-maximized") && !args.includes("--start-fullscreen")) {
|
|
230
|
+
args.push("--start-maximized");
|
|
231
|
+
}
|
|
232
|
+
capabilities[key] ??= {};
|
|
233
|
+
capabilities[key].args = args;
|
|
234
|
+
}
|
|
213
235
|
return capabilities;
|
|
214
236
|
}
|
|
215
237
|
async openPage(_contextId, url) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.13",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"playwright": "*",
|
|
53
53
|
"webdriverio": "*",
|
|
54
|
-
"vitest": "2.0.0-beta.
|
|
54
|
+
"vitest": "2.0.0-beta.13"
|
|
55
55
|
},
|
|
56
56
|
"peerDependenciesMeta": {
|
|
57
57
|
"playwright": {
|
|
@@ -65,13 +65,13 @@
|
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@testing-library/dom": "^10.
|
|
68
|
+
"@testing-library/dom": "^10.2.0",
|
|
69
69
|
"@testing-library/user-event": "^14.5.2",
|
|
70
70
|
"magic-string": "^0.30.10",
|
|
71
71
|
"msw": "^2.3.1",
|
|
72
72
|
"sirv": "^2.0.4",
|
|
73
73
|
"ws": "^8.17.1",
|
|
74
|
-
"@vitest/utils": "2.0.0-beta.
|
|
74
|
+
"@vitest/utils": "2.0.0-beta.13"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@testing-library/jest-dom": "^6.4.6",
|
|
@@ -81,14 +81,14 @@
|
|
|
81
81
|
"flatted": "^3.3.1",
|
|
82
82
|
"pathe": "^1.1.2",
|
|
83
83
|
"periscopic": "^4.0.2",
|
|
84
|
-
"playwright": "^1.
|
|
85
|
-
"playwright-core": "^1.
|
|
84
|
+
"playwright": "^1.45.0",
|
|
85
|
+
"playwright-core": "^1.45.0",
|
|
86
86
|
"safaridriver": "^0.1.2",
|
|
87
|
-
"webdriverio": "^8.
|
|
88
|
-
"@vitest/
|
|
89
|
-
"@vitest/
|
|
90
|
-
"@vitest/
|
|
91
|
-
"vitest": "2.0.0-beta.
|
|
87
|
+
"webdriverio": "^8.39.0",
|
|
88
|
+
"@vitest/ws-client": "2.0.0-beta.13",
|
|
89
|
+
"@vitest/runner": "2.0.0-beta.13",
|
|
90
|
+
"@vitest/ui": "2.0.0-beta.13",
|
|
91
|
+
"vitest": "2.0.0-beta.13"
|
|
92
92
|
},
|
|
93
93
|
"scripts": {
|
|
94
94
|
"build": "rimraf dist && pnpm build:node && pnpm build:client",
|