@vitest/browser 1.0.0-beta.1 → 1.0.0-beta.2
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.
|
@@ -106,7 +106,7 @@ const random = Math.random.bind(Math);
|
|
|
106
106
|
function createBirpc(functions, options) {
|
|
107
107
|
const {
|
|
108
108
|
post,
|
|
109
|
-
on,
|
|
109
|
+
on: on2,
|
|
110
110
|
eventNames = [],
|
|
111
111
|
serialize = defaultSerialize,
|
|
112
112
|
deserialize = defaultDeserialize,
|
|
@@ -146,7 +146,7 @@ function createBirpc(functions, options) {
|
|
|
146
146
|
return sendCall;
|
|
147
147
|
}
|
|
148
148
|
});
|
|
149
|
-
_promise =
|
|
149
|
+
_promise = on2(async (data, ...extra) => {
|
|
150
150
|
const msg = deserialize(data);
|
|
151
151
|
if (msg.t === "q") {
|
|
152
152
|
const { m: method, a: args } = msg;
|
|
@@ -599,20 +599,16 @@ function createClient(url2, options = {}) {
|
|
|
599
599
|
}
|
|
600
600
|
const { get } = Reflect;
|
|
601
601
|
function withSafeTimers(getTimers, fn) {
|
|
602
|
-
|
|
603
|
-
const { setTimeout: setTimeout2, clearTimeout: clearTimeout2, nextTick, setImmediate, clearImmediate } = getTimers();
|
|
602
|
+
const { setTimeout: setTimeout2, clearTimeout: clearTimeout2, setImmediate, clearImmediate } = getTimers();
|
|
604
603
|
const currentSetTimeout = globalThis.setTimeout;
|
|
605
604
|
const currentClearTimeout = globalThis.clearTimeout;
|
|
606
605
|
const currentSetImmediate = globalThis.setImmediate;
|
|
607
606
|
const currentClearImmediate = globalThis.clearImmediate;
|
|
608
|
-
const currentNextTick = (_a = globalThis.process) == null ? void 0 : _a.nextTick;
|
|
609
607
|
try {
|
|
610
608
|
globalThis.setTimeout = setTimeout2;
|
|
611
609
|
globalThis.clearTimeout = clearTimeout2;
|
|
612
610
|
globalThis.setImmediate = setImmediate;
|
|
613
611
|
globalThis.clearImmediate = clearImmediate;
|
|
614
|
-
if (globalThis.process)
|
|
615
|
-
globalThis.process.nextTick = nextTick;
|
|
616
612
|
const result = fn();
|
|
617
613
|
return result;
|
|
618
614
|
} finally {
|
|
@@ -620,11 +616,6 @@ function withSafeTimers(getTimers, fn) {
|
|
|
620
616
|
globalThis.clearTimeout = currentClearTimeout;
|
|
621
617
|
globalThis.setImmediate = currentSetImmediate;
|
|
622
618
|
globalThis.clearImmediate = currentClearImmediate;
|
|
623
|
-
if (globalThis.process) {
|
|
624
|
-
nextTick(() => {
|
|
625
|
-
globalThis.process.nextTick = currentNextTick;
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
619
|
}
|
|
629
620
|
}
|
|
630
621
|
const promises = /* @__PURE__ */ new Set();
|
|
@@ -893,10 +884,37 @@ async function loadConfig() {
|
|
|
893
884
|
} while (--retries > 0);
|
|
894
885
|
throw new Error("cannot load configuration after 5 retries");
|
|
895
886
|
}
|
|
887
|
+
function on(event, listener) {
|
|
888
|
+
window.addEventListener(event, listener);
|
|
889
|
+
return () => window.removeEventListener(event, listener);
|
|
890
|
+
}
|
|
891
|
+
async function defaultErrorReport(type, unhandledError) {
|
|
892
|
+
const error = {
|
|
893
|
+
...unhandledError,
|
|
894
|
+
name: unhandledError.name,
|
|
895
|
+
message: unhandledError.message,
|
|
896
|
+
stack: unhandledError.stack
|
|
897
|
+
};
|
|
898
|
+
await client.rpc.onUnhandledError(error, type);
|
|
899
|
+
await client.rpc.onDone(testId);
|
|
900
|
+
}
|
|
901
|
+
const stopErrorHandler = on("error", (e) => defaultErrorReport("Error", e.error));
|
|
902
|
+
const stopRejectionHandler = on("unhandledrejection", (e) => defaultErrorReport("Unhandled Rejection", e.reason));
|
|
903
|
+
let runningTests = false;
|
|
904
|
+
async function reportUnexpectedError(rpc2, type, error) {
|
|
905
|
+
const { processError } = await importId("vitest/browser");
|
|
906
|
+
await rpc2.onUnhandledError(processError(error), type);
|
|
907
|
+
if (!runningTests)
|
|
908
|
+
await rpc2.onDone(testId);
|
|
909
|
+
}
|
|
896
910
|
ws.addEventListener("open", async () => {
|
|
897
911
|
await loadConfig();
|
|
898
912
|
const { getSafeTimers } = await importId("vitest/utils");
|
|
899
913
|
const safeRpc = createSafeRpc(client, getSafeTimers);
|
|
914
|
+
stopErrorHandler();
|
|
915
|
+
stopRejectionHandler();
|
|
916
|
+
on("error", (event) => reportUnexpectedError(safeRpc, "Error", event.error));
|
|
917
|
+
on("unhandledrejection", (event) => reportUnexpectedError(safeRpc, "Unhandled Rejection", event.reason));
|
|
900
918
|
globalThis.__vitest_browser__ = true;
|
|
901
919
|
globalThis.__vitest_worker__ = {
|
|
902
920
|
config,
|
|
@@ -952,9 +970,11 @@ async function runTests(paths, config2) {
|
|
|
952
970
|
});
|
|
953
971
|
const now = `${(/* @__PURE__ */ new Date()).getTime()}`;
|
|
954
972
|
files.forEach((i) => browserHashMap.set(i, [true, now]));
|
|
973
|
+
runningTests = true;
|
|
955
974
|
for (const file of files)
|
|
956
975
|
await startTests([file], runner);
|
|
957
976
|
} finally {
|
|
977
|
+
runningTests = false;
|
|
958
978
|
await rpcDone();
|
|
959
979
|
await rpc().onDone(testId);
|
|
960
980
|
}
|
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-a6988d73.js"></script>
|
|
25
25
|
</head>
|
|
26
26
|
<body>
|
|
27
27
|
<iframe id="vitest-ui" src=""></iframe>
|
package/dist/index.js
CHANGED
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.2",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -34,17 +34,17 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"estree-walker": "^3.0.3",
|
|
37
|
-
"magic-string": "^0.30.
|
|
37
|
+
"magic-string": "^0.30.4",
|
|
38
38
|
"sirv": "^2.0.3"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/estree": "^1.0.1",
|
|
42
42
|
"@types/ws": "^8.5.5",
|
|
43
43
|
"periscopic": "^3.1.0",
|
|
44
|
-
"@vitest/
|
|
45
|
-
"vitest": "1.0.0-beta.
|
|
46
|
-
"
|
|
47
|
-
"@vitest/
|
|
44
|
+
"@vitest/runner": "1.0.0-beta.2",
|
|
45
|
+
"@vitest/ui": "1.0.0-beta.2",
|
|
46
|
+
"vitest": "1.0.0-beta.2",
|
|
47
|
+
"@vitest/ws-client": "1.0.0-beta.2"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rimraf dist && pnpm build:node && pnpm build:client",
|