@vitest/browser 0.27.3 → 0.28.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/client/__vitest__/assets/{index-9672ec12.css → index-57d38fc4.css} +1 -1
- package/dist/client/__vitest__/assets/index-5f86a2aa.js +37 -0
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/assets/{index-2a0b4312.js → index-79af63dc.js} +68 -53
- package/dist/client/index.html +1 -1
- package/dist/index.js +5 -20
- package/package.json +5 -4
- package/dist/client/__vitest__/assets/index-fc39214a.js +0 -37
- package/stubs/console.js +0 -1
- package/stubs/fs.js +0 -7
- package/stubs/local-pkg.js +0 -2
- package/stubs/module.js +0 -1
- package/stubs/noop.js +0 -5
- package/stubs/perf_hooks.js +0 -1
- package/stubs/tty.js +0 -3
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
})()
|
|
18
18
|
</script>
|
|
19
19
|
<!-- !LOAD_METADATA! -->
|
|
20
|
-
<script type="module" crossorigin src="/__vitest__/assets/index-
|
|
21
|
-
<link rel="stylesheet" href="/__vitest__/assets/index-
|
|
20
|
+
<script type="module" crossorigin src="/__vitest__/assets/index-5f86a2aa.js"></script>
|
|
21
|
+
<link rel="stylesheet" href="/__vitest__/assets/index-57d38fc4.css">
|
|
22
22
|
</head>
|
|
23
23
|
<body>
|
|
24
24
|
<div id="app"></div>
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
1
7
|
(function polyfill() {
|
|
2
8
|
const relList = document.createElement("link").relList;
|
|
3
9
|
if (relList && relList.supports && relList.supports("modulepreload")) {
|
|
@@ -249,21 +255,7 @@ class StateManager {
|
|
|
249
255
|
getUnhandledErrors() {
|
|
250
256
|
return Array.from(this.errorsSet.values());
|
|
251
257
|
}
|
|
252
|
-
|
|
253
|
-
let _resolve;
|
|
254
|
-
const promise = new Promise((resolve) => {
|
|
255
|
-
_resolve = resolve;
|
|
256
|
-
});
|
|
257
|
-
this.collectingPromise = { promise, resolve: _resolve };
|
|
258
|
-
}
|
|
259
|
-
finishCollectingPaths() {
|
|
260
|
-
var _a;
|
|
261
|
-
(_a = this.collectingPromise) == null ? void 0 : _a.resolve();
|
|
262
|
-
this.collectingPromise = void 0;
|
|
263
|
-
}
|
|
264
|
-
async getPaths() {
|
|
265
|
-
var _a;
|
|
266
|
-
await ((_a = this.collectingPromise) == null ? void 0 : _a.promise);
|
|
258
|
+
getPaths() {
|
|
267
259
|
return Array.from(this.pathsSet);
|
|
268
260
|
}
|
|
269
261
|
getFiles(keys2) {
|
|
@@ -321,40 +313,6 @@ class StateManager {
|
|
|
321
313
|
}
|
|
322
314
|
}
|
|
323
315
|
}
|
|
324
|
-
const RealDate = Date;
|
|
325
|
-
class MockDate extends RealDate {
|
|
326
|
-
constructor(y, m, d, h, M, s, ms) {
|
|
327
|
-
super();
|
|
328
|
-
let date;
|
|
329
|
-
switch (arguments.length) {
|
|
330
|
-
case 0:
|
|
331
|
-
date = new RealDate();
|
|
332
|
-
break;
|
|
333
|
-
case 1:
|
|
334
|
-
date = new RealDate(y);
|
|
335
|
-
break;
|
|
336
|
-
default:
|
|
337
|
-
d = typeof d === "undefined" ? 1 : d;
|
|
338
|
-
h = h || 0;
|
|
339
|
-
M = M || 0;
|
|
340
|
-
s = s || 0;
|
|
341
|
-
ms = ms || 0;
|
|
342
|
-
date = new RealDate(y, m, d, h, M, s, ms);
|
|
343
|
-
break;
|
|
344
|
-
}
|
|
345
|
-
return date;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
MockDate.UTC = RealDate.UTC;
|
|
349
|
-
MockDate.now = function() {
|
|
350
|
-
return new MockDate().valueOf();
|
|
351
|
-
};
|
|
352
|
-
MockDate.parse = function(dateString) {
|
|
353
|
-
return RealDate.parse(dateString);
|
|
354
|
-
};
|
|
355
|
-
MockDate.toString = function() {
|
|
356
|
-
return RealDate.toString();
|
|
357
|
-
};
|
|
358
316
|
function createClient(url, options = {}) {
|
|
359
317
|
const {
|
|
360
318
|
handlers = {},
|
|
@@ -437,6 +395,51 @@ function createClient(url, options = {}) {
|
|
|
437
395
|
}
|
|
438
396
|
return ctx;
|
|
439
397
|
}
|
|
398
|
+
function createBrowserRunner(original) {
|
|
399
|
+
return class BrowserTestRunner extends original {
|
|
400
|
+
constructor(options) {
|
|
401
|
+
super(options.config);
|
|
402
|
+
__publicField(this, "config");
|
|
403
|
+
__publicField(this, "hasMap", /* @__PURE__ */ new Map());
|
|
404
|
+
__publicField(this, "client");
|
|
405
|
+
this.config = options.config;
|
|
406
|
+
this.hasMap = options.browserHashMap;
|
|
407
|
+
this.client = options.client;
|
|
408
|
+
}
|
|
409
|
+
onCollected(files) {
|
|
410
|
+
return this.client.rpc.onCollected(files);
|
|
411
|
+
}
|
|
412
|
+
onTaskUpdate(task) {
|
|
413
|
+
return this.client.rpc.onTaskUpdate(task);
|
|
414
|
+
}
|
|
415
|
+
async importFile(filepath) {
|
|
416
|
+
const match = filepath.match(/^(\w:\/)/);
|
|
417
|
+
const hash = this.hasMap.get(filepath);
|
|
418
|
+
const importpath = match ? `/@fs/${filepath.slice(match[1].length)}?v=${hash}` : `${filepath}?v=${hash}`;
|
|
419
|
+
await __vitePreload(() => import(importpath), true ? [] : void 0);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
class BrowserSnapshotEnvironment {
|
|
424
|
+
constructor(client2) {
|
|
425
|
+
this.client = client2;
|
|
426
|
+
}
|
|
427
|
+
readSnapshotFile(filepath) {
|
|
428
|
+
return this.client.rpc.readFile(filepath);
|
|
429
|
+
}
|
|
430
|
+
saveSnapshotFile(filepath, snapshot) {
|
|
431
|
+
return this.client.rpc.writeFile(filepath, snapshot);
|
|
432
|
+
}
|
|
433
|
+
resolvePath(filepath) {
|
|
434
|
+
return this.client.rpc.resolveSnapshotPath(filepath);
|
|
435
|
+
}
|
|
436
|
+
removeSnapshotFile(filepath) {
|
|
437
|
+
return this.client.rpc.removeFile(filepath);
|
|
438
|
+
}
|
|
439
|
+
async prepareDirectory(filepath) {
|
|
440
|
+
await this.client.rpc.createDirectory(filepath);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
440
443
|
globalThis.process = { env: {}, argv: [], stdout: { write: () => {
|
|
441
444
|
} } };
|
|
442
445
|
globalThis.global = globalThis;
|
|
@@ -444,6 +447,7 @@ const PORT = location.port;
|
|
|
444
447
|
const HOST = [location.hostname, PORT].filter(Boolean).join(":");
|
|
445
448
|
const ENTRY_URL = `${location.protocol === "https:" ? "wss:" : "ws:"}//${HOST}/__vitest_api__`;
|
|
446
449
|
let config;
|
|
450
|
+
let runner;
|
|
447
451
|
const browserHashMap = /* @__PURE__ */ new Map();
|
|
448
452
|
const client = createClient(ENTRY_URL, {
|
|
449
453
|
handlers: {
|
|
@@ -486,11 +490,22 @@ ws.addEventListener("open", async () => {
|
|
|
486
490
|
iFrame.setAttribute("src", "/__vitest__/");
|
|
487
491
|
await runTests(paths, config, client);
|
|
488
492
|
});
|
|
493
|
+
let hasSnapshot = false;
|
|
489
494
|
async function runTests(paths, config2, client2) {
|
|
490
|
-
const
|
|
491
|
-
const { startTests,
|
|
492
|
-
|
|
493
|
-
|
|
495
|
+
const path = "/__vitest_index__";
|
|
496
|
+
const { startTests, setupCommonEnv, setupSnapshotEnvironment } = await __vitePreload(() => import(path), true ? [] : void 0);
|
|
497
|
+
if (!runner) {
|
|
498
|
+
const runnerPath = "/__vitest_runners__";
|
|
499
|
+
const { VitestTestRunner } = await __vitePreload(() => import(runnerPath), true ? [] : void 0);
|
|
500
|
+
const BrowserRunner = createBrowserRunner(VitestTestRunner);
|
|
501
|
+
runner = new BrowserRunner({ config: config2, client: client2, browserHashMap });
|
|
502
|
+
}
|
|
503
|
+
if (!hasSnapshot) {
|
|
504
|
+
setupSnapshotEnvironment(new BrowserSnapshotEnvironment(client2));
|
|
505
|
+
hasSnapshot = true;
|
|
506
|
+
}
|
|
507
|
+
await setupCommonEnv(config2);
|
|
508
|
+
await startTests(paths, runner);
|
|
494
509
|
await client2.rpc.onFinished();
|
|
495
510
|
await client2.rpc.onWatcherStart();
|
|
496
511
|
}
|
package/dist/client/index.html
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,22 +3,9 @@ import { resolve } from 'path';
|
|
|
3
3
|
import { builtinModules } from 'module';
|
|
4
4
|
import { polyfillPath } from 'modern-node-polyfills';
|
|
5
5
|
import sirv from 'sirv';
|
|
6
|
-
import { resolvePath } from 'mlly';
|
|
7
6
|
|
|
8
|
-
const stubs = [
|
|
9
|
-
"fs",
|
|
10
|
-
"local-pkg",
|
|
11
|
-
"module",
|
|
12
|
-
"noop",
|
|
13
|
-
"perf_hooks",
|
|
14
|
-
"console"
|
|
15
|
-
];
|
|
16
7
|
const polyfills = [
|
|
17
|
-
"util"
|
|
18
|
-
"tty",
|
|
19
|
-
"process",
|
|
20
|
-
"path",
|
|
21
|
-
"buffer"
|
|
8
|
+
"util"
|
|
22
9
|
];
|
|
23
10
|
var index = (base = "/") => {
|
|
24
11
|
const pkgRoot = resolve(fileURLToPath(import.meta.url), "../..");
|
|
@@ -30,12 +17,10 @@ var index = (base = "/") => {
|
|
|
30
17
|
async resolveId(id, _, ctx) {
|
|
31
18
|
if (ctx.ssr)
|
|
32
19
|
return;
|
|
33
|
-
if (id === "/__vitest_index__")
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (stubs.includes(id))
|
|
38
|
-
return resolve(pkgRoot, "stubs", id);
|
|
20
|
+
if (id === "/__vitest_index__")
|
|
21
|
+
return this.resolve("vitest/browser");
|
|
22
|
+
if (id === "/__vitest_runners__")
|
|
23
|
+
return this.resolve("vitest/runners");
|
|
39
24
|
if (polyfills.includes(id))
|
|
40
25
|
return polyfillPath(normalizeId(id));
|
|
41
26
|
return null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.28.1",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -28,13 +28,14 @@
|
|
|
28
28
|
"mlly": "^1.1.0",
|
|
29
29
|
"modern-node-polyfills": "0.0.9",
|
|
30
30
|
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
31
|
-
"sirv": "^2.0.2"
|
|
31
|
+
"sirv": "^2.0.2",
|
|
32
|
+
"@vitest/runner": "0.28.1"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/ws": "^8.5.4",
|
|
35
36
|
"rollup": "^2.79.1",
|
|
36
|
-
"@vitest/ws-client": "0.
|
|
37
|
-
"vitest": "0.
|
|
37
|
+
"@vitest/ws-client": "0.28.1",
|
|
38
|
+
"vitest": "0.28.1"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
41
|
"build": "rimraf dist && pnpm build:node && pnpm build:client && pnpm copy",
|