@vitest/browser 4.0.8 → 4.0.9
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/.vite/manifest.json +1 -1
- package/dist/client/__vitest__/assets/index-zBMt7UWw.js +57 -0
- package/dist/client/__vitest__/index.html +1 -1
- package/dist/client/__vitest_browser__/{tester-C3iDyL-N.js → tester-BLe1dg8x.js} +5 -5
- package/dist/client/tester/tester.html +1 -1
- package/dist/client.js +96 -77
- package/dist/index.js +98 -79
- package/package.json +7 -7
- package/dist/client/__vitest__/assets/index-l1rdxr0p.js +0 -57
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
})();
|
|
24
24
|
</script>
|
|
25
25
|
<!-- !LOAD_METADATA! -->
|
|
26
|
-
<script type="module" src="./assets/index-
|
|
26
|
+
<script type="module" src="./assets/index-zBMt7UWw.js"></script>
|
|
27
27
|
<link rel="stylesheet" href="./assets/index-VPnwgb7M.css">
|
|
28
28
|
</head>
|
|
29
29
|
<body>
|
|
@@ -257,7 +257,7 @@ var hasRequiredResolveUri_umd;
|
|
|
257
257
|
function requireResolveUri_umd() {
|
|
258
258
|
if (hasRequiredResolveUri_umd) return resolveUri_umd$1.exports;
|
|
259
259
|
hasRequiredResolveUri_umd = 1;
|
|
260
|
-
(function(module, exports) {
|
|
260
|
+
(function(module, exports$1) {
|
|
261
261
|
(function(global, factory) {
|
|
262
262
|
module.exports = factory();
|
|
263
263
|
})(resolveUri_umd, (function() {
|
|
@@ -1376,18 +1376,18 @@ class ManualMockedModule {
|
|
|
1376
1376
|
if (this.cache) {
|
|
1377
1377
|
return this.cache;
|
|
1378
1378
|
}
|
|
1379
|
-
let exports;
|
|
1379
|
+
let exports$1;
|
|
1380
1380
|
try {
|
|
1381
|
-
exports = await this.factory();
|
|
1381
|
+
exports$1 = await this.factory();
|
|
1382
1382
|
} catch (err) {
|
|
1383
1383
|
const vitestError = new Error('[vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/vi.html#vi-mock');
|
|
1384
1384
|
vitestError.cause = err;
|
|
1385
1385
|
throw vitestError;
|
|
1386
1386
|
}
|
|
1387
|
-
if (exports === null || typeof exports !== "object" || Array.isArray(exports)) {
|
|
1387
|
+
if (exports$1 === null || typeof exports$1 !== "object" || Array.isArray(exports$1)) {
|
|
1388
1388
|
throw new TypeError(`[vitest] vi.mock("${this.raw}", factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?`);
|
|
1389
1389
|
}
|
|
1390
|
-
return this.cache = exports;
|
|
1390
|
+
return this.cache = exports$1;
|
|
1391
1391
|
}
|
|
1392
1392
|
static fromJSON(data, factory) {
|
|
1393
1393
|
return new ManualMockedModule(data.raw, data.id, data.url, factory);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" href="{__VITEST_FAVICON__}" type="image/svg+xml">
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>Vitest Browser Tester</title>
|
|
8
|
-
<script type="module" crossorigin src="/__vitest_browser__/tester-
|
|
8
|
+
<script type="module" crossorigin src="/__vitest_browser__/tester-BLe1dg8x.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-uxqdqUz8.js">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
package/dist/client.js
CHANGED
|
@@ -7,7 +7,7 @@ function defaultSerialize(i) {
|
|
|
7
7
|
const defaultDeserialize = defaultSerialize;
|
|
8
8
|
const { clearTimeout: clearTimeout$1, setTimeout: setTimeout$1 } = globalThis;
|
|
9
9
|
const random = Math.random.bind(Math);
|
|
10
|
-
function createBirpc(functions, options) {
|
|
10
|
+
function createBirpc($functions, options) {
|
|
11
11
|
const {
|
|
12
12
|
post,
|
|
13
13
|
on,
|
|
@@ -20,83 +20,100 @@ function createBirpc(functions, options) {
|
|
|
20
20
|
bind = "rpc",
|
|
21
21
|
timeout = DEFAULT_TIMEOUT
|
|
22
22
|
} = options;
|
|
23
|
-
|
|
23
|
+
let $closed = false;
|
|
24
|
+
const _rpcPromiseMap = /* @__PURE__ */ new Map();
|
|
24
25
|
let _promiseInit;
|
|
25
|
-
|
|
26
|
+
async function _call(method, args, event, optional) {
|
|
27
|
+
if ($closed)
|
|
28
|
+
throw new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
|
29
|
+
const req = { m: method, a: args, t: TYPE_REQUEST };
|
|
30
|
+
if (optional)
|
|
31
|
+
req.o = true;
|
|
32
|
+
const send = async (_req) => post(serialize(_req));
|
|
33
|
+
if (event) {
|
|
34
|
+
await send(req);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (_promiseInit) {
|
|
38
|
+
try {
|
|
39
|
+
await _promiseInit;
|
|
40
|
+
} finally {
|
|
41
|
+
_promiseInit = void 0;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let { promise, resolve, reject } = createPromiseWithResolvers();
|
|
45
|
+
const id = nanoid();
|
|
46
|
+
req.i = id;
|
|
47
|
+
let timeoutId;
|
|
48
|
+
async function handler(newReq = req) {
|
|
49
|
+
if (timeout >= 0) {
|
|
50
|
+
timeoutId = setTimeout$1(() => {
|
|
51
|
+
try {
|
|
52
|
+
const handleResult = options.onTimeoutError?.(method, args);
|
|
53
|
+
if (handleResult !== true)
|
|
54
|
+
throw new Error(`[birpc] timeout on calling "${method}"`);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
reject(e);
|
|
57
|
+
}
|
|
58
|
+
_rpcPromiseMap.delete(id);
|
|
59
|
+
}, timeout);
|
|
60
|
+
if (typeof timeoutId === "object")
|
|
61
|
+
timeoutId = timeoutId.unref?.();
|
|
62
|
+
}
|
|
63
|
+
_rpcPromiseMap.set(id, { resolve, reject, timeoutId, method });
|
|
64
|
+
await send(newReq);
|
|
65
|
+
return promise;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
if (options.onRequest)
|
|
69
|
+
await options.onRequest(req, handler, resolve);
|
|
70
|
+
else
|
|
71
|
+
await handler();
|
|
72
|
+
} catch (e) {
|
|
73
|
+
if (options.onGeneralError?.(e) !== true)
|
|
74
|
+
throw e;
|
|
75
|
+
return;
|
|
76
|
+
} finally {
|
|
77
|
+
clearTimeout$1(timeoutId);
|
|
78
|
+
_rpcPromiseMap.delete(id);
|
|
79
|
+
}
|
|
80
|
+
return promise;
|
|
81
|
+
}
|
|
82
|
+
const $call = (method, ...args) => _call(method, args, false);
|
|
83
|
+
const $callOptional = (method, ...args) => _call(method, args, false, true);
|
|
84
|
+
const $callEvent = (method, ...args) => _call(method, args, true);
|
|
85
|
+
const $callRaw = (options2) => _call(options2.method, options2.args, options2.event, options2.optional);
|
|
86
|
+
const builtinMethods = {
|
|
87
|
+
$call,
|
|
88
|
+
$callOptional,
|
|
89
|
+
$callEvent,
|
|
90
|
+
$callRaw,
|
|
91
|
+
$rejectPendingCalls,
|
|
92
|
+
get $closed() {
|
|
93
|
+
return $closed;
|
|
94
|
+
},
|
|
95
|
+
$close,
|
|
96
|
+
$functions
|
|
97
|
+
};
|
|
26
98
|
const rpc = new Proxy({}, {
|
|
27
99
|
get(_, method) {
|
|
28
|
-
if (method
|
|
29
|
-
return
|
|
30
|
-
if (method === "
|
|
31
|
-
return close;
|
|
32
|
-
if (method === "$rejectPendingCalls") {
|
|
33
|
-
return rejectPendingCalls;
|
|
34
|
-
}
|
|
35
|
-
if (method === "$closed")
|
|
36
|
-
return closed;
|
|
37
|
-
if (method === "then" && !eventNames.includes("then") && !("then" in functions))
|
|
100
|
+
if (Object.prototype.hasOwnProperty.call(builtinMethods, method))
|
|
101
|
+
return builtinMethods[method];
|
|
102
|
+
if (method === "then" && !eventNames.includes("then") && !("then" in $functions))
|
|
38
103
|
return void 0;
|
|
39
|
-
const sendEvent =
|
|
40
|
-
await post(serialize({ m: method, a: args, t: TYPE_REQUEST }));
|
|
41
|
-
};
|
|
104
|
+
const sendEvent = (...args) => _call(method, args, true);
|
|
42
105
|
if (eventNames.includes(method)) {
|
|
43
106
|
sendEvent.asEvent = sendEvent;
|
|
44
107
|
return sendEvent;
|
|
45
108
|
}
|
|
46
|
-
const sendCall =
|
|
47
|
-
if (closed)
|
|
48
|
-
throw new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
|
49
|
-
if (_promiseInit) {
|
|
50
|
-
try {
|
|
51
|
-
await _promiseInit;
|
|
52
|
-
} finally {
|
|
53
|
-
_promiseInit = void 0;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
let { promise, resolve, reject } = createPromiseWithResolvers();
|
|
57
|
-
const id = nanoid();
|
|
58
|
-
let timeoutId;
|
|
59
|
-
const _req = { m: method, a: args, i: id, t: TYPE_REQUEST };
|
|
60
|
-
async function handler(req = _req) {
|
|
61
|
-
if (timeout >= 0) {
|
|
62
|
-
timeoutId = setTimeout$1(() => {
|
|
63
|
-
try {
|
|
64
|
-
const handleResult = options.onTimeoutError?.(method, args);
|
|
65
|
-
if (handleResult !== true)
|
|
66
|
-
throw new Error(`[birpc] timeout on calling "${method}"`);
|
|
67
|
-
} catch (e) {
|
|
68
|
-
reject(e);
|
|
69
|
-
}
|
|
70
|
-
rpcPromiseMap.delete(id);
|
|
71
|
-
}, timeout);
|
|
72
|
-
if (typeof timeoutId === "object")
|
|
73
|
-
timeoutId = timeoutId.unref?.();
|
|
74
|
-
}
|
|
75
|
-
rpcPromiseMap.set(id, { resolve, reject, timeoutId, method });
|
|
76
|
-
await post(serialize(req));
|
|
77
|
-
return promise;
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
if (options.onRequest)
|
|
81
|
-
await options.onRequest(_req, handler, resolve);
|
|
82
|
-
else
|
|
83
|
-
await handler();
|
|
84
|
-
} catch (e) {
|
|
85
|
-
clearTimeout$1(timeoutId);
|
|
86
|
-
rpcPromiseMap.delete(id);
|
|
87
|
-
if (options.onGeneralError?.(e) !== true)
|
|
88
|
-
throw e;
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
return promise;
|
|
92
|
-
};
|
|
109
|
+
const sendCall = (...args) => _call(method, args, false);
|
|
93
110
|
sendCall.asEvent = sendEvent;
|
|
94
111
|
return sendCall;
|
|
95
112
|
}
|
|
96
113
|
});
|
|
97
|
-
function close(customError) {
|
|
98
|
-
closed = true;
|
|
99
|
-
|
|
114
|
+
function $close(customError) {
|
|
115
|
+
$closed = true;
|
|
116
|
+
_rpcPromiseMap.forEach(({ reject, method }) => {
|
|
100
117
|
const error = new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
|
101
118
|
if (customError) {
|
|
102
119
|
customError.cause ??= error;
|
|
@@ -104,18 +121,18 @@ function createBirpc(functions, options) {
|
|
|
104
121
|
}
|
|
105
122
|
reject(error);
|
|
106
123
|
});
|
|
107
|
-
|
|
124
|
+
_rpcPromiseMap.clear();
|
|
108
125
|
off(onMessage);
|
|
109
126
|
}
|
|
110
|
-
function rejectPendingCalls(handler) {
|
|
111
|
-
const entries = Array.from(
|
|
127
|
+
function $rejectPendingCalls(handler) {
|
|
128
|
+
const entries = Array.from(_rpcPromiseMap.values());
|
|
112
129
|
const handlerResults = entries.map(({ method, reject }) => {
|
|
113
130
|
if (!handler) {
|
|
114
131
|
return reject(new Error(`[birpc]: rejected pending call "${method}".`));
|
|
115
132
|
}
|
|
116
133
|
return handler({ method, reject });
|
|
117
134
|
});
|
|
118
|
-
|
|
135
|
+
_rpcPromiseMap.clear();
|
|
119
136
|
return handlerResults;
|
|
120
137
|
}
|
|
121
138
|
async function onMessage(data, ...extra) {
|
|
@@ -128,14 +145,16 @@ function createBirpc(functions, options) {
|
|
|
128
145
|
return;
|
|
129
146
|
}
|
|
130
147
|
if (msg.t === TYPE_REQUEST) {
|
|
131
|
-
const { m: method, a: args } = msg;
|
|
148
|
+
const { m: method, a: args, o: optional } = msg;
|
|
132
149
|
let result, error;
|
|
133
|
-
|
|
150
|
+
let fn = await (resolver ? resolver(method, $functions[method]) : $functions[method]);
|
|
151
|
+
if (optional)
|
|
152
|
+
fn ||= () => void 0;
|
|
134
153
|
if (!fn) {
|
|
135
154
|
error = new Error(`[birpc] function "${method}" not found`);
|
|
136
155
|
} else {
|
|
137
156
|
try {
|
|
138
|
-
result = await fn.apply(bind === "rpc" ? rpc : functions, args);
|
|
157
|
+
result = await fn.apply(bind === "rpc" ? rpc : $functions, args);
|
|
139
158
|
} catch (e) {
|
|
140
159
|
error = e;
|
|
141
160
|
}
|
|
@@ -166,7 +185,7 @@ function createBirpc(functions, options) {
|
|
|
166
185
|
}
|
|
167
186
|
} else {
|
|
168
187
|
const { i: ack, r: result, e: error } = msg;
|
|
169
|
-
const promise =
|
|
188
|
+
const promise = _rpcPromiseMap.get(ack);
|
|
170
189
|
if (promise) {
|
|
171
190
|
clearTimeout$1(promise.timeoutId);
|
|
172
191
|
if (error)
|
|
@@ -174,7 +193,7 @@ function createBirpc(functions, options) {
|
|
|
174
193
|
else
|
|
175
194
|
promise.resolve(result);
|
|
176
195
|
}
|
|
177
|
-
|
|
196
|
+
_rpcPromiseMap.delete(ack);
|
|
178
197
|
}
|
|
179
198
|
}
|
|
180
199
|
_promiseInit = on(onMessage);
|
|
@@ -383,8 +402,8 @@ function createClient() {
|
|
|
383
402
|
responseId
|
|
384
403
|
};
|
|
385
404
|
}
|
|
386
|
-
const exports = await mocker.resolveFactoryModule(url);
|
|
387
|
-
const keys = Object.keys(exports);
|
|
405
|
+
const exports$1 = await mocker.resolveFactoryModule(url);
|
|
406
|
+
const keys = Object.keys(exports$1);
|
|
388
407
|
return {
|
|
389
408
|
url,
|
|
390
409
|
keys,
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import { PNG } from 'pngjs';
|
|
|
18
18
|
import pm from 'pixelmatch';
|
|
19
19
|
import { WebSocketServer } from 'ws';
|
|
20
20
|
|
|
21
|
-
var version = "4.0.
|
|
21
|
+
var version = "4.0.9";
|
|
22
22
|
|
|
23
23
|
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
24
24
|
function normalizeWindowsPath(input = "") {
|
|
@@ -716,7 +716,7 @@ async function resolveOrchestrator(globalServer, url, res) {
|
|
|
716
716
|
const manifestContent = globalServer.manifest instanceof Promise ? await globalServer.manifest : globalServer.manifest;
|
|
717
717
|
const jsEntry = manifestContent["orchestrator.html"].file;
|
|
718
718
|
const base = browserProject.parent.vite.config.base || "/";
|
|
719
|
-
baseHtml = baseHtml.replaceAll("./assets/", `${base}__vitest__/assets/`).replace("<!-- !LOAD_METADATA! -->", [
|
|
719
|
+
baseHtml = baseHtml.replace("href=\"./favicon.ico\"", `href="${base}__vitest__/favicon.ico"`).replace("href=\"./favicon.svg\"", `href="${base}__vitest__/favicon.svg"`).replaceAll("./assets/", `${base}__vitest__/assets/`).replace("<!-- !LOAD_METADATA! -->", [
|
|
720
720
|
"{__VITEST_INJECTOR__}",
|
|
721
721
|
"{__VITEST_ERROR_CATCHER__}",
|
|
722
722
|
"{__VITEST_SCRIPTS__}",
|
|
@@ -834,7 +834,7 @@ const ID_CONTEXT = "vitest/browser";
|
|
|
834
834
|
const DEPRECATED_ID_CONTEXT = "@vitest/browser/context";
|
|
835
835
|
const DEPRECATED_VIRTUAL_ID_UTILS = "\0@vitest/browser/utils";
|
|
836
836
|
const DEPRECATED_ID_UTILS = "@vitest/browser/utils";
|
|
837
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
837
|
+
const __dirname$1 = dirname(fileURLToPath(import.meta.url));
|
|
838
838
|
function BrowserContext(globalServer) {
|
|
839
839
|
return {
|
|
840
840
|
name: "vitest:browser:virtual-module:context",
|
|
@@ -877,7 +877,7 @@ async function generateContextFile(globalServer) {
|
|
|
877
877
|
return ` ["${command}"]: (...args) => __vitest_browser_runner__.commands.triggerCommand("${command}", args),`;
|
|
878
878
|
}).join("\n");
|
|
879
879
|
const userEventNonProviderImport = await getUserEventImport(provider, this.resolve.bind(this));
|
|
880
|
-
const distContextPath = slash$1(`/@fs/${resolve(__dirname, "context.js")}`);
|
|
880
|
+
const distContextPath = slash$1(`/@fs/${resolve(__dirname$1, "context.js")}`);
|
|
881
881
|
return `
|
|
882
882
|
import { page, createUserEvent, cdp, locators, utils } from '${distContextPath}'
|
|
883
883
|
${userEventNonProviderImport}
|
|
@@ -2673,7 +2673,7 @@ function defaultSerialize(i) {
|
|
|
2673
2673
|
const defaultDeserialize = defaultSerialize;
|
|
2674
2674
|
const { clearTimeout, setTimeout: setTimeout$1 } = globalThis;
|
|
2675
2675
|
const random = Math.random.bind(Math);
|
|
2676
|
-
function createBirpc(functions, options) {
|
|
2676
|
+
function createBirpc($functions, options) {
|
|
2677
2677
|
const {
|
|
2678
2678
|
post,
|
|
2679
2679
|
on,
|
|
@@ -2686,83 +2686,100 @@ function createBirpc(functions, options) {
|
|
|
2686
2686
|
bind = "rpc",
|
|
2687
2687
|
timeout = DEFAULT_TIMEOUT
|
|
2688
2688
|
} = options;
|
|
2689
|
-
|
|
2689
|
+
let $closed = false;
|
|
2690
|
+
const _rpcPromiseMap = /* @__PURE__ */ new Map();
|
|
2690
2691
|
let _promiseInit;
|
|
2691
|
-
|
|
2692
|
+
async function _call(method, args, event, optional) {
|
|
2693
|
+
if ($closed)
|
|
2694
|
+
throw new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
|
2695
|
+
const req = { m: method, a: args, t: TYPE_REQUEST };
|
|
2696
|
+
if (optional)
|
|
2697
|
+
req.o = true;
|
|
2698
|
+
const send = async (_req) => post(serialize(_req));
|
|
2699
|
+
if (event) {
|
|
2700
|
+
await send(req);
|
|
2701
|
+
return;
|
|
2702
|
+
}
|
|
2703
|
+
if (_promiseInit) {
|
|
2704
|
+
try {
|
|
2705
|
+
await _promiseInit;
|
|
2706
|
+
} finally {
|
|
2707
|
+
_promiseInit = void 0;
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
let { promise, resolve, reject } = createPromiseWithResolvers();
|
|
2711
|
+
const id = nanoid();
|
|
2712
|
+
req.i = id;
|
|
2713
|
+
let timeoutId;
|
|
2714
|
+
async function handler(newReq = req) {
|
|
2715
|
+
if (timeout >= 0) {
|
|
2716
|
+
timeoutId = setTimeout$1(() => {
|
|
2717
|
+
try {
|
|
2718
|
+
const handleResult = options.onTimeoutError?.(method, args);
|
|
2719
|
+
if (handleResult !== true)
|
|
2720
|
+
throw new Error(`[birpc] timeout on calling "${method}"`);
|
|
2721
|
+
} catch (e) {
|
|
2722
|
+
reject(e);
|
|
2723
|
+
}
|
|
2724
|
+
_rpcPromiseMap.delete(id);
|
|
2725
|
+
}, timeout);
|
|
2726
|
+
if (typeof timeoutId === "object")
|
|
2727
|
+
timeoutId = timeoutId.unref?.();
|
|
2728
|
+
}
|
|
2729
|
+
_rpcPromiseMap.set(id, { resolve, reject, timeoutId, method });
|
|
2730
|
+
await send(newReq);
|
|
2731
|
+
return promise;
|
|
2732
|
+
}
|
|
2733
|
+
try {
|
|
2734
|
+
if (options.onRequest)
|
|
2735
|
+
await options.onRequest(req, handler, resolve);
|
|
2736
|
+
else
|
|
2737
|
+
await handler();
|
|
2738
|
+
} catch (e) {
|
|
2739
|
+
if (options.onGeneralError?.(e) !== true)
|
|
2740
|
+
throw e;
|
|
2741
|
+
return;
|
|
2742
|
+
} finally {
|
|
2743
|
+
clearTimeout(timeoutId);
|
|
2744
|
+
_rpcPromiseMap.delete(id);
|
|
2745
|
+
}
|
|
2746
|
+
return promise;
|
|
2747
|
+
}
|
|
2748
|
+
const $call = (method, ...args) => _call(method, args, false);
|
|
2749
|
+
const $callOptional = (method, ...args) => _call(method, args, false, true);
|
|
2750
|
+
const $callEvent = (method, ...args) => _call(method, args, true);
|
|
2751
|
+
const $callRaw = (options2) => _call(options2.method, options2.args, options2.event, options2.optional);
|
|
2752
|
+
const builtinMethods = {
|
|
2753
|
+
$call,
|
|
2754
|
+
$callOptional,
|
|
2755
|
+
$callEvent,
|
|
2756
|
+
$callRaw,
|
|
2757
|
+
$rejectPendingCalls,
|
|
2758
|
+
get $closed() {
|
|
2759
|
+
return $closed;
|
|
2760
|
+
},
|
|
2761
|
+
$close,
|
|
2762
|
+
$functions
|
|
2763
|
+
};
|
|
2692
2764
|
const rpc = new Proxy({}, {
|
|
2693
2765
|
get(_, method) {
|
|
2694
|
-
if (method
|
|
2695
|
-
return
|
|
2696
|
-
if (method === "
|
|
2697
|
-
return close;
|
|
2698
|
-
if (method === "$rejectPendingCalls") {
|
|
2699
|
-
return rejectPendingCalls;
|
|
2700
|
-
}
|
|
2701
|
-
if (method === "$closed")
|
|
2702
|
-
return closed;
|
|
2703
|
-
if (method === "then" && !eventNames.includes("then") && !("then" in functions))
|
|
2766
|
+
if (Object.prototype.hasOwnProperty.call(builtinMethods, method))
|
|
2767
|
+
return builtinMethods[method];
|
|
2768
|
+
if (method === "then" && !eventNames.includes("then") && !("then" in $functions))
|
|
2704
2769
|
return void 0;
|
|
2705
|
-
const sendEvent =
|
|
2706
|
-
await post(serialize({ m: method, a: args, t: TYPE_REQUEST }));
|
|
2707
|
-
};
|
|
2770
|
+
const sendEvent = (...args) => _call(method, args, true);
|
|
2708
2771
|
if (eventNames.includes(method)) {
|
|
2709
2772
|
sendEvent.asEvent = sendEvent;
|
|
2710
2773
|
return sendEvent;
|
|
2711
2774
|
}
|
|
2712
|
-
const sendCall =
|
|
2713
|
-
if (closed)
|
|
2714
|
-
throw new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
|
2715
|
-
if (_promiseInit) {
|
|
2716
|
-
try {
|
|
2717
|
-
await _promiseInit;
|
|
2718
|
-
} finally {
|
|
2719
|
-
_promiseInit = void 0;
|
|
2720
|
-
}
|
|
2721
|
-
}
|
|
2722
|
-
let { promise, resolve, reject } = createPromiseWithResolvers();
|
|
2723
|
-
const id = nanoid();
|
|
2724
|
-
let timeoutId;
|
|
2725
|
-
const _req = { m: method, a: args, i: id, t: TYPE_REQUEST };
|
|
2726
|
-
async function handler(req = _req) {
|
|
2727
|
-
if (timeout >= 0) {
|
|
2728
|
-
timeoutId = setTimeout$1(() => {
|
|
2729
|
-
try {
|
|
2730
|
-
const handleResult = options.onTimeoutError?.(method, args);
|
|
2731
|
-
if (handleResult !== true)
|
|
2732
|
-
throw new Error(`[birpc] timeout on calling "${method}"`);
|
|
2733
|
-
} catch (e) {
|
|
2734
|
-
reject(e);
|
|
2735
|
-
}
|
|
2736
|
-
rpcPromiseMap.delete(id);
|
|
2737
|
-
}, timeout);
|
|
2738
|
-
if (typeof timeoutId === "object")
|
|
2739
|
-
timeoutId = timeoutId.unref?.();
|
|
2740
|
-
}
|
|
2741
|
-
rpcPromiseMap.set(id, { resolve, reject, timeoutId, method });
|
|
2742
|
-
await post(serialize(req));
|
|
2743
|
-
return promise;
|
|
2744
|
-
}
|
|
2745
|
-
try {
|
|
2746
|
-
if (options.onRequest)
|
|
2747
|
-
await options.onRequest(_req, handler, resolve);
|
|
2748
|
-
else
|
|
2749
|
-
await handler();
|
|
2750
|
-
} catch (e) {
|
|
2751
|
-
clearTimeout(timeoutId);
|
|
2752
|
-
rpcPromiseMap.delete(id);
|
|
2753
|
-
if (options.onGeneralError?.(e) !== true)
|
|
2754
|
-
throw e;
|
|
2755
|
-
return;
|
|
2756
|
-
}
|
|
2757
|
-
return promise;
|
|
2758
|
-
};
|
|
2775
|
+
const sendCall = (...args) => _call(method, args, false);
|
|
2759
2776
|
sendCall.asEvent = sendEvent;
|
|
2760
2777
|
return sendCall;
|
|
2761
2778
|
}
|
|
2762
2779
|
});
|
|
2763
|
-
function close(customError) {
|
|
2764
|
-
closed = true;
|
|
2765
|
-
|
|
2780
|
+
function $close(customError) {
|
|
2781
|
+
$closed = true;
|
|
2782
|
+
_rpcPromiseMap.forEach(({ reject, method }) => {
|
|
2766
2783
|
const error = new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
|
2767
2784
|
if (customError) {
|
|
2768
2785
|
customError.cause ??= error;
|
|
@@ -2770,18 +2787,18 @@ function createBirpc(functions, options) {
|
|
|
2770
2787
|
}
|
|
2771
2788
|
reject(error);
|
|
2772
2789
|
});
|
|
2773
|
-
|
|
2790
|
+
_rpcPromiseMap.clear();
|
|
2774
2791
|
off(onMessage);
|
|
2775
2792
|
}
|
|
2776
|
-
function rejectPendingCalls(handler) {
|
|
2777
|
-
const entries = Array.from(
|
|
2793
|
+
function $rejectPendingCalls(handler) {
|
|
2794
|
+
const entries = Array.from(_rpcPromiseMap.values());
|
|
2778
2795
|
const handlerResults = entries.map(({ method, reject }) => {
|
|
2779
2796
|
if (!handler) {
|
|
2780
2797
|
return reject(new Error(`[birpc]: rejected pending call "${method}".`));
|
|
2781
2798
|
}
|
|
2782
2799
|
return handler({ method, reject });
|
|
2783
2800
|
});
|
|
2784
|
-
|
|
2801
|
+
_rpcPromiseMap.clear();
|
|
2785
2802
|
return handlerResults;
|
|
2786
2803
|
}
|
|
2787
2804
|
async function onMessage(data, ...extra) {
|
|
@@ -2794,14 +2811,16 @@ function createBirpc(functions, options) {
|
|
|
2794
2811
|
return;
|
|
2795
2812
|
}
|
|
2796
2813
|
if (msg.t === TYPE_REQUEST) {
|
|
2797
|
-
const { m: method, a: args } = msg;
|
|
2814
|
+
const { m: method, a: args, o: optional } = msg;
|
|
2798
2815
|
let result, error;
|
|
2799
|
-
|
|
2816
|
+
let fn = await (resolver ? resolver(method, $functions[method]) : $functions[method]);
|
|
2817
|
+
if (optional)
|
|
2818
|
+
fn ||= () => void 0;
|
|
2800
2819
|
if (!fn) {
|
|
2801
2820
|
error = new Error(`[birpc] function "${method}" not found`);
|
|
2802
2821
|
} else {
|
|
2803
2822
|
try {
|
|
2804
|
-
result = await fn.apply(bind === "rpc" ? rpc : functions, args);
|
|
2823
|
+
result = await fn.apply(bind === "rpc" ? rpc : $functions, args);
|
|
2805
2824
|
} catch (e) {
|
|
2806
2825
|
error = e;
|
|
2807
2826
|
}
|
|
@@ -2832,7 +2851,7 @@ function createBirpc(functions, options) {
|
|
|
2832
2851
|
}
|
|
2833
2852
|
} else {
|
|
2834
2853
|
const { i: ack, r: result, e: error } = msg;
|
|
2835
|
-
const promise =
|
|
2854
|
+
const promise = _rpcPromiseMap.get(ack);
|
|
2836
2855
|
if (promise) {
|
|
2837
2856
|
clearTimeout(promise.timeoutId);
|
|
2838
2857
|
if (error)
|
|
@@ -2840,7 +2859,7 @@ function createBirpc(functions, options) {
|
|
|
2840
2859
|
else
|
|
2841
2860
|
promise.resolve(result);
|
|
2842
2861
|
}
|
|
2843
|
-
|
|
2862
|
+
_rpcPromiseMap.delete(ack);
|
|
2844
2863
|
}
|
|
2845
2864
|
}
|
|
2846
2865
|
_promiseInit = on(onMessage);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.9",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"providers"
|
|
52
52
|
],
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"vitest": "4.0.
|
|
54
|
+
"vitest": "4.0.9"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"magic-string": "^0.30.21",
|
|
@@ -60,20 +60,20 @@
|
|
|
60
60
|
"sirv": "^3.0.2",
|
|
61
61
|
"tinyrainbow": "^3.0.3",
|
|
62
62
|
"ws": "^8.18.3",
|
|
63
|
-
"@vitest/mocker": "4.0.
|
|
64
|
-
"@vitest/utils": "4.0.
|
|
63
|
+
"@vitest/mocker": "4.0.9",
|
|
64
|
+
"@vitest/utils": "4.0.9"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@testing-library/user-event": "^14.6.1",
|
|
68
68
|
"@types/pngjs": "^6.0.5",
|
|
69
69
|
"@types/ws": "^8.18.1",
|
|
70
|
-
"birpc": "^2.
|
|
70
|
+
"birpc": "^2.8.0",
|
|
71
71
|
"flatted": "^3.3.3",
|
|
72
72
|
"ivya": "^1.7.0",
|
|
73
73
|
"mime": "^4.1.0",
|
|
74
74
|
"pathe": "^2.0.3",
|
|
75
|
-
"
|
|
76
|
-
"vitest": "4.0.
|
|
75
|
+
"vitest": "4.0.9",
|
|
76
|
+
"@vitest/runner": "4.0.9"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"typecheck": "tsc -p ./src/client/tsconfig.json --noEmit",
|