aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/vitest/dist/chunks/rpc.BoxB0q7B.js
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-13 21:34:48 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-13 21:34:48 -0800
commit76cb9c2a39d477a64824a985ade40507e3bbade1 (patch)
tree41e997aa9c6f538d3a136af61dae9424db2005a9 /vanilla/node_modules/vitest/dist/chunks/rpc.BoxB0q7B.js
parent819a39a21ac992b1393244a4c283bbb125208c69 (diff)
downloadneko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.gz
neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.bz2
neko-76cb9c2a39d477a64824a985ade40507e3bbade1.zip
feat(vanilla): add testing infrastructure and tests (NK-wjnczv)
Diffstat (limited to 'vanilla/node_modules/vitest/dist/chunks/rpc.BoxB0q7B.js')
-rw-r--r--vanilla/node_modules/vitest/dist/chunks/rpc.BoxB0q7B.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/vanilla/node_modules/vitest/dist/chunks/rpc.BoxB0q7B.js b/vanilla/node_modules/vitest/dist/chunks/rpc.BoxB0q7B.js
new file mode 100644
index 0000000..0e6d395
--- /dev/null
+++ b/vanilla/node_modules/vitest/dist/chunks/rpc.BoxB0q7B.js
@@ -0,0 +1,76 @@
+import { getSafeTimers } from '@vitest/utils/timers';
+import { c as createBirpc } from './index.Chj8NDwU.js';
+import { g as getWorkerState } from './utils.DvEY5TfP.js';
+
+const { get } = Reflect;
+function withSafeTimers(fn) {
+ const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
+ const currentSetTimeout = globalThis.setTimeout;
+ const currentClearTimeout = globalThis.clearTimeout;
+ const currentSetImmediate = globalThis.setImmediate;
+ const currentClearImmediate = globalThis.clearImmediate;
+ const currentNextTick = globalThis.process?.nextTick;
+ try {
+ globalThis.setTimeout = setTimeout;
+ globalThis.clearTimeout = clearTimeout;
+ if (setImmediate) globalThis.setImmediate = setImmediate;
+ if (clearImmediate) globalThis.clearImmediate = clearImmediate;
+ if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
+ return fn();
+ } finally {
+ globalThis.setTimeout = currentSetTimeout;
+ globalThis.clearTimeout = currentClearTimeout;
+ globalThis.setImmediate = currentSetImmediate;
+ globalThis.clearImmediate = currentClearImmediate;
+ if (globalThis.process && nextTick) nextTick(() => {
+ globalThis.process.nextTick = currentNextTick;
+ });
+ }
+}
+const promises = /* @__PURE__ */ new Set();
+async function rpcDone() {
+ if (!promises.size) return;
+ const awaitable = Array.from(promises);
+ return Promise.all(awaitable);
+}
+const onCancelCallbacks = [];
+function onCancel(callback) {
+ onCancelCallbacks.push(callback);
+}
+function createRuntimeRpc(options) {
+ return createSafeRpc(createBirpc({ async onCancel(reason) {
+ await Promise.all(onCancelCallbacks.map((fn) => fn(reason)));
+ } }, {
+ eventNames: [
+ "onUserConsoleLog",
+ "onCollected",
+ "onCancel"
+ ],
+ timeout: -1,
+ ...options
+ }));
+}
+function createSafeRpc(rpc) {
+ return new Proxy(rpc, { get(target, p, handler) {
+ // keep $rejectPendingCalls as sync function
+ if (p === "$rejectPendingCalls") return rpc.$rejectPendingCalls;
+ const sendCall = get(target, p, handler);
+ const safeSendCall = (...args) => withSafeTimers(async () => {
+ const result = sendCall(...args);
+ promises.add(result);
+ try {
+ return await result;
+ } finally {
+ promises.delete(result);
+ }
+ });
+ safeSendCall.asEvent = sendCall.asEvent;
+ return safeSendCall;
+ } });
+}
+function rpc() {
+ const { rpc } = getWorkerState();
+ return rpc;
+}
+
+export { rpcDone as a, createRuntimeRpc as c, onCancel as o, rpc as r };