@vitest/browser 1.0.0-beta.3 → 1.0.0-beta.5
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/client/__vitest__/assets/index-BXn2hHMA.css +1 -0
- package/dist/client/__vitest__/assets/index-pErXFFfx.js +33 -0
- package/dist/client/__vitest__/index.html +2 -3
- package/dist/client/__vitest_browser__/{index-393df1b9.js → index-FC-iEk-V.js} +56 -13
- package/dist/client/index.html +1 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +26 -21
- package/dist/providers.js +36 -11
- package/package.json +12 -12
- package/dist/client/__vitest__/assets/index-58267aa9.js +0 -33
- package/dist/client/__vitest__/assets/index-eb3b6871.css +0 -1
|
@@ -17,11 +17,10 @@
|
|
|
17
17
|
})()
|
|
18
18
|
</script>
|
|
19
19
|
<!-- !LOAD_METADATA! -->
|
|
20
|
-
<script type="module" crossorigin src="./assets/index-
|
|
21
|
-
<link rel="stylesheet" href="./assets/index-
|
|
20
|
+
<script type="module" crossorigin src="./assets/index-pErXFFfx.js"></script>
|
|
21
|
+
<link rel="stylesheet" crossorigin href="./assets/index-BXn2hHMA.css">
|
|
22
22
|
</head>
|
|
23
23
|
<body>
|
|
24
24
|
<div id="app"></div>
|
|
25
|
-
|
|
26
25
|
</body>
|
|
27
26
|
</html>
|
|
@@ -495,7 +495,7 @@ class StateManager {
|
|
|
495
495
|
return ((_a = t.result) == null ? void 0 : _a.state) === "fail";
|
|
496
496
|
}).length;
|
|
497
497
|
}
|
|
498
|
-
cancelFiles(files, root) {
|
|
498
|
+
cancelFiles(files, root, projectName) {
|
|
499
499
|
this.collectFiles(files.map((filepath) => ({
|
|
500
500
|
filepath,
|
|
501
501
|
name: relative(root, filepath),
|
|
@@ -507,7 +507,8 @@ class StateManager {
|
|
|
507
507
|
},
|
|
508
508
|
meta: {},
|
|
509
509
|
// Cancelled files have not yet collected tests
|
|
510
|
-
tasks: []
|
|
510
|
+
tasks: [],
|
|
511
|
+
projectName
|
|
511
512
|
})));
|
|
512
513
|
}
|
|
513
514
|
}
|
|
@@ -695,13 +696,25 @@ function createBrowserRunner(original, coverageModule) {
|
|
|
695
696
|
this.hashMap.set(filepath, [false, hash]);
|
|
696
697
|
}
|
|
697
698
|
const importpath = /^\w:/.test(filepath) ? `/@fs/${filepath}?${test ? "browserv" : "v"}=${hash}` : `${filepath}?${test ? "browserv" : "v"}=${hash}`;
|
|
698
|
-
await __vitePreload(() => import(importpath), true ? [] : void 0);
|
|
699
|
+
await __vitePreload(() => import(importpath), true ? __vite__mapDeps([]) : void 0);
|
|
699
700
|
}
|
|
700
701
|
};
|
|
701
702
|
}
|
|
702
|
-
function
|
|
703
|
+
async function tryImport(id, tries = 20) {
|
|
704
|
+
try {
|
|
705
|
+
return await __vitePreload(() => import(id), true ? __vite__mapDeps([]) : void 0);
|
|
706
|
+
} catch (cause) {
|
|
707
|
+
if (tries <= 0) {
|
|
708
|
+
location.reload();
|
|
709
|
+
throw new Error(`Failed to import ${id}.`, { cause });
|
|
710
|
+
}
|
|
711
|
+
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
712
|
+
return await tryImport(id, tries - 1);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
async function importId(id) {
|
|
703
716
|
const name = `/@id/${id}`;
|
|
704
|
-
return __vi_wrap_module__(
|
|
717
|
+
return __vi_wrap_module__(tryImport(name));
|
|
705
718
|
}
|
|
706
719
|
const { Date: Date$1, console: console$1 } = globalThis;
|
|
707
720
|
async function setupConsoleLogSpy() {
|
|
@@ -919,8 +932,14 @@ async function reportUnexpectedError(rpc2, type, error) {
|
|
|
919
932
|
}
|
|
920
933
|
ws.addEventListener("open", async () => {
|
|
921
934
|
await loadConfig();
|
|
922
|
-
|
|
923
|
-
|
|
935
|
+
let safeRpc;
|
|
936
|
+
try {
|
|
937
|
+
const { getSafeTimers } = await importId("vitest/utils");
|
|
938
|
+
safeRpc = createSafeRpc(client, getSafeTimers);
|
|
939
|
+
} catch (err) {
|
|
940
|
+
location.reload();
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
924
943
|
stopErrorHandler();
|
|
925
944
|
stopRejectionHandler();
|
|
926
945
|
on("error", (event) => reportUnexpectedError(safeRpc, "Error", event.error));
|
|
@@ -939,7 +958,8 @@ ws.addEventListener("open", async () => {
|
|
|
939
958
|
durations: {
|
|
940
959
|
environment: 0,
|
|
941
960
|
prepare: 0
|
|
942
|
-
}
|
|
961
|
+
},
|
|
962
|
+
providedContext: await client.rpc.getProvidedContext()
|
|
943
963
|
};
|
|
944
964
|
globalThis.__vitest_mocker__ = new VitestBrowserClientMocker();
|
|
945
965
|
const paths = getQueryPaths();
|
|
@@ -949,9 +969,9 @@ ws.addEventListener("open", async () => {
|
|
|
949
969
|
setupDialogsSpy();
|
|
950
970
|
await runTests(paths, config);
|
|
951
971
|
});
|
|
952
|
-
async function
|
|
972
|
+
async function prepareTestEnvironment(config2) {
|
|
953
973
|
const viteClientPath = "/@vite/client";
|
|
954
|
-
await __vitePreload(() => import(viteClientPath), true ? [] : void 0);
|
|
974
|
+
await __vitePreload(() => import(viteClientPath), true ? __vite__mapDeps([]) : void 0);
|
|
955
975
|
const {
|
|
956
976
|
startTests,
|
|
957
977
|
setupCommonEnv,
|
|
@@ -966,14 +986,31 @@ async function runTests(paths, config2) {
|
|
|
966
986
|
const BrowserRunner = createBrowserRunner(VitestTestRunner, { takeCoverage: () => takeCoverageInsideWorker(config2.coverage, executor) });
|
|
967
987
|
runner = new BrowserRunner({ config: config2, browserHashMap });
|
|
968
988
|
}
|
|
989
|
+
return {
|
|
990
|
+
startTests,
|
|
991
|
+
setupCommonEnv,
|
|
992
|
+
loadDiffConfig,
|
|
993
|
+
executor,
|
|
994
|
+
runner
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
async function runTests(paths, config2) {
|
|
998
|
+
let preparedData;
|
|
999
|
+
try {
|
|
1000
|
+
preparedData = await prepareTestEnvironment(config2);
|
|
1001
|
+
} catch (err) {
|
|
1002
|
+
location.reload();
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
const { startTests, setupCommonEnv, loadDiffConfig, executor, runner: runner2 } = preparedData;
|
|
969
1006
|
onCancel.then((reason) => {
|
|
970
1007
|
var _a;
|
|
971
|
-
(_a =
|
|
1008
|
+
(_a = runner2 == null ? void 0 : runner2.onCancel) == null ? void 0 : _a.call(runner2, reason);
|
|
972
1009
|
});
|
|
973
1010
|
if (!config2.snapshotOptions.snapshotEnvironment)
|
|
974
1011
|
config2.snapshotOptions.snapshotEnvironment = new BrowserSnapshotEnvironment();
|
|
975
1012
|
try {
|
|
976
|
-
|
|
1013
|
+
runner2.config.diffOptions = await loadDiffConfig(config2, executor);
|
|
977
1014
|
await setupCommonEnv(config2);
|
|
978
1015
|
const files = paths.map((path) => {
|
|
979
1016
|
return `${config2.root}/${path}`.replace(/\/+/g, "/");
|
|
@@ -982,10 +1019,16 @@ async function runTests(paths, config2) {
|
|
|
982
1019
|
files.forEach((i) => browserHashMap.set(i, [true, now]));
|
|
983
1020
|
runningTests = true;
|
|
984
1021
|
for (const file of files)
|
|
985
|
-
await startTests([file],
|
|
1022
|
+
await startTests([file], runner2);
|
|
986
1023
|
} finally {
|
|
987
1024
|
runningTests = false;
|
|
988
1025
|
await rpcDone();
|
|
989
1026
|
await rpc().onDone(testId);
|
|
990
1027
|
}
|
|
991
1028
|
}
|
|
1029
|
+
function __vite__mapDeps(indexes) {
|
|
1030
|
+
if (!__vite__mapDeps.viteFileDeps) {
|
|
1031
|
+
__vite__mapDeps.viteFileDeps = []
|
|
1032
|
+
}
|
|
1033
|
+
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
1034
|
+
}
|
package/dist/client/index.html
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
border: none;
|
|
22
22
|
}
|
|
23
23
|
</style>
|
|
24
|
-
<script type="module" crossorigin src="/__vitest_browser__/index-
|
|
24
|
+
<script type="module" crossorigin src="/__vitest_browser__/index-FC-iEk-V.js"></script>
|
|
25
25
|
</head>
|
|
26
26
|
<body>
|
|
27
27
|
<iframe id="vitest-ui" src=""></iframe>
|
|
@@ -75,6 +75,5 @@
|
|
|
75
75
|
window.__vi_module_cache__ = moduleCache
|
|
76
76
|
window.__vi_wrap_module__ = wrapModule
|
|
77
77
|
</script>
|
|
78
|
-
|
|
79
78
|
</body>
|
|
80
79
|
</html>
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
+
import { WorkspaceProject } from 'vitest/node';
|
|
2
3
|
|
|
3
|
-
declare const _default: (project:
|
|
4
|
+
declare const _default: (project: WorkspaceProject, base?: string) => Plugin[];
|
|
4
5
|
|
|
5
6
|
export { _default as default };
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { walk } from 'estree-walker';
|
|
|
10
10
|
* @returns {string[]}
|
|
11
11
|
*/
|
|
12
12
|
function extract_names(param) {
|
|
13
|
-
return extract_identifiers(param).map(node => node.name);
|
|
13
|
+
return extract_identifiers(param).map((node) => node.name);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -33,29 +33,21 @@ function extract_identifiers(param, nodes = []) {
|
|
|
33
33
|
break;
|
|
34
34
|
|
|
35
35
|
case 'ObjectPattern':
|
|
36
|
-
|
|
37
|
-
const handle_prop = (prop) => {
|
|
36
|
+
for (const prop of param.properties) {
|
|
38
37
|
if (prop.type === 'RestElement') {
|
|
39
38
|
extract_identifiers(prop.argument, nodes);
|
|
40
39
|
} else {
|
|
41
40
|
extract_identifiers(prop.value, nodes);
|
|
42
41
|
}
|
|
43
|
-
}
|
|
42
|
+
}
|
|
44
43
|
|
|
45
|
-
param.properties.forEach(handle_prop);
|
|
46
44
|
break;
|
|
47
45
|
|
|
48
46
|
case 'ArrayPattern':
|
|
49
|
-
|
|
50
|
-
const handle_element = (element) => {
|
|
47
|
+
for (const element of param.elements) {
|
|
51
48
|
if (element) extract_identifiers(element, nodes);
|
|
52
|
-
}
|
|
49
|
+
}
|
|
53
50
|
|
|
54
|
-
param.elements.forEach((element) => {
|
|
55
|
-
if (element) {
|
|
56
|
-
handle_element(element);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
51
|
break;
|
|
60
52
|
|
|
61
53
|
case 'RestElement':
|
|
@@ -245,11 +237,7 @@ function injectVitestModule(code, id, parse) {
|
|
|
245
237
|
const s = new MagicString(code);
|
|
246
238
|
let ast;
|
|
247
239
|
try {
|
|
248
|
-
ast = parse(code
|
|
249
|
-
sourceType: "module",
|
|
250
|
-
ecmaVersion: "latest",
|
|
251
|
-
locations: true
|
|
252
|
-
});
|
|
240
|
+
ast = parse(code);
|
|
253
241
|
} catch (err) {
|
|
254
242
|
console.error(`Cannot parse ${id}:
|
|
255
243
|
${err.message}`);
|
|
@@ -440,8 +428,10 @@ var index = (project, base = "/") => {
|
|
|
440
428
|
name: "vitest:browser",
|
|
441
429
|
async config(viteConfig) {
|
|
442
430
|
// Enables using ignore hint for coverage providers with @preserve keyword
|
|
443
|
-
viteConfig.esbuild
|
|
444
|
-
|
|
431
|
+
if (viteConfig.esbuild !== false) {
|
|
432
|
+
viteConfig.esbuild ||= {};
|
|
433
|
+
viteConfig.esbuild.legalComments = "inline";
|
|
434
|
+
}
|
|
445
435
|
},
|
|
446
436
|
async configureServer(server) {
|
|
447
437
|
server.middlewares.use(
|
|
@@ -456,9 +446,24 @@ var index = (project, base = "/") => {
|
|
|
456
446
|
{
|
|
457
447
|
name: "vitest:browser:tests",
|
|
458
448
|
enforce: "pre",
|
|
459
|
-
config() {
|
|
449
|
+
async config() {
|
|
450
|
+
const {
|
|
451
|
+
include,
|
|
452
|
+
exclude,
|
|
453
|
+
includeSource,
|
|
454
|
+
dir,
|
|
455
|
+
root
|
|
456
|
+
} = project.config;
|
|
457
|
+
const projectRoot = dir || root;
|
|
458
|
+
const entries = await project.globAllTestFiles(include, exclude, includeSource, projectRoot);
|
|
460
459
|
return {
|
|
461
460
|
optimizeDeps: {
|
|
461
|
+
entries: [
|
|
462
|
+
...entries,
|
|
463
|
+
"vitest/utils",
|
|
464
|
+
"vitest/browser",
|
|
465
|
+
"vitest/runners"
|
|
466
|
+
],
|
|
462
467
|
exclude: [
|
|
463
468
|
...builtinModules,
|
|
464
469
|
"vitest",
|
package/dist/providers.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ensurePackageInstalled } from 'vitest/node';
|
|
2
|
-
|
|
3
1
|
const playwrightBrowsers = ["firefox", "webkit", "chromium"];
|
|
4
2
|
class PlaywrightBrowserProvider {
|
|
5
3
|
name = "playwright";
|
|
@@ -15,9 +13,6 @@ class PlaywrightBrowserProvider {
|
|
|
15
13
|
this.ctx = ctx;
|
|
16
14
|
this.browser = browser;
|
|
17
15
|
this.options = options;
|
|
18
|
-
const root = this.ctx.config.root;
|
|
19
|
-
if (!await ensurePackageInstalled("playwright", root))
|
|
20
|
-
throw new Error('Cannot find "playwright" package. Please install it manually.');
|
|
21
16
|
}
|
|
22
17
|
async openBrowserPage() {
|
|
23
18
|
if (this.cachedPage)
|
|
@@ -67,11 +62,6 @@ class WebdriverBrowserProvider {
|
|
|
67
62
|
this.ctx = ctx;
|
|
68
63
|
this.browser = browser;
|
|
69
64
|
this.options = options;
|
|
70
|
-
const root = this.ctx.config.root;
|
|
71
|
-
if (!await ensurePackageInstalled("webdriverio", root))
|
|
72
|
-
throw new Error('Cannot find "webdriverio" package. Please install it manually.');
|
|
73
|
-
if (browser === "safari" && !await ensurePackageInstalled("safaridriver", root))
|
|
74
|
-
throw new Error('Cannot find "safaridriver" package. Please install it manually.');
|
|
75
65
|
}
|
|
76
66
|
async openBrowser() {
|
|
77
67
|
if (this.cachedBrowser)
|
|
@@ -133,7 +123,42 @@ class WebdriverBrowserProvider {
|
|
|
133
123
|
}
|
|
134
124
|
}
|
|
135
125
|
|
|
126
|
+
class NoneBrowserProvider {
|
|
127
|
+
name = "none";
|
|
128
|
+
ctx;
|
|
129
|
+
open = false;
|
|
130
|
+
getSupportedBrowsers() {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
isOpen() {
|
|
134
|
+
return this.open;
|
|
135
|
+
}
|
|
136
|
+
async initialize(ctx) {
|
|
137
|
+
this.ctx = ctx;
|
|
138
|
+
this.open = false;
|
|
139
|
+
if (ctx.config.browser.headless)
|
|
140
|
+
throw new Error(`You've enabled headless mode for "none" provider but it doesn't support it.`);
|
|
141
|
+
}
|
|
142
|
+
catchError(_cb) {
|
|
143
|
+
return () => {
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
async openPage(_url) {
|
|
147
|
+
this.open = true;
|
|
148
|
+
if (!this.ctx.browser)
|
|
149
|
+
throw new Error("Browser is not initialized");
|
|
150
|
+
const options = this.ctx.browser.config.server;
|
|
151
|
+
const _open = options.open;
|
|
152
|
+
options.open = _url;
|
|
153
|
+
this.ctx.browser.openBrowser();
|
|
154
|
+
options.open = _open;
|
|
155
|
+
}
|
|
156
|
+
async close() {
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
136
160
|
const webdriverio = WebdriverBrowserProvider;
|
|
137
161
|
const playwright = PlaywrightBrowserProvider;
|
|
162
|
+
const none = NoneBrowserProvider;
|
|
138
163
|
|
|
139
|
-
export { playwright, webdriverio };
|
|
164
|
+
export { none, playwright, webdriverio };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.5",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
|
-
"
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
22
|
},
|
|
23
23
|
"./providers": {
|
|
24
24
|
"types": "./providers.d.ts",
|
|
25
|
-
"
|
|
25
|
+
"default": "./dist/providers.js"
|
|
26
26
|
},
|
|
27
27
|
"./providers/webdriverio": {
|
|
28
28
|
"types": "./dist/providers/webdriverio.d.ts"
|
|
@@ -62,18 +62,18 @@
|
|
|
62
62
|
"sirv": "^2.0.3"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@types/estree": "^1.0.
|
|
66
|
-
"@types/ws": "^8.5.
|
|
67
|
-
"@wdio/protocols": "^8.
|
|
68
|
-
"periscopic": "^
|
|
65
|
+
"@types/estree": "^1.0.5",
|
|
66
|
+
"@types/ws": "^8.5.9",
|
|
67
|
+
"@wdio/protocols": "^8.22.0",
|
|
68
|
+
"periscopic": "^4.0.2",
|
|
69
69
|
"playwright": "^1.39.0",
|
|
70
70
|
"playwright-core": "^1.39.0",
|
|
71
71
|
"safaridriver": "^0.1.0",
|
|
72
|
-
"webdriverio": "^8.
|
|
73
|
-
"@vitest/runner": "1.0.0-beta.
|
|
74
|
-
"
|
|
75
|
-
"vitest": "1.0.0-beta.
|
|
76
|
-
"@vitest/ws-client": "1.0.0-beta.
|
|
72
|
+
"webdriverio": "^8.22.1",
|
|
73
|
+
"@vitest/runner": "1.0.0-beta.5",
|
|
74
|
+
"vitest": "1.0.0-beta.5",
|
|
75
|
+
"@vitest/ui": "1.0.0-beta.5",
|
|
76
|
+
"@vitest/ws-client": "1.0.0-beta.5"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build": "rimraf dist && pnpm build:node && pnpm build:client",
|