@cloudflare/vitest-plugin 0.0.0 → 1.0.0
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/README.md +12 -0
- package/dist/pool/chunk-Q72B4Q5Z-izl5Qmnx.mjs +70 -0
- package/dist/pool/chunk-Q72B4Q5Z-izl5Qmnx.mjs.map +1 -0
- package/dist/pool/index.d.mts +105 -0
- package/dist/pool/index.mjs +61142 -0
- package/dist/pool/index.mjs.map +1 -0
- package/dist/pool/open-PBXRGS4R-D05rCV0x.mjs +529 -0
- package/dist/pool/open-PBXRGS4R-D05rCV0x.mjs.map +1 -0
- package/dist/worker/index.mjs +885 -0
- package/dist/worker/index.mjs.map +1 -0
- package/dist/worker/lib/cloudflare/snapshot.mjs +39 -0
- package/dist/worker/lib/cloudflare/snapshot.mjs.map +1 -0
- package/dist/worker/lib/cloudflare/test-internal.mjs +1065 -0
- package/dist/worker/lib/cloudflare/test-internal.mjs.map +1 -0
- package/dist/worker/lib/cloudflare/test.mjs +3 -0
- package/dist/worker/node/console.mjs +99 -0
- package/dist/worker/node/console.mjs.map +1 -0
- package/dist/worker/node/vm.mjs +16 -0
- package/dist/worker/node/vm.mjs.map +1 -0
- package/package.json +92 -6
- package/types/cloudflare-test.d.ts +861 -0
|
@@ -0,0 +1,885 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import * as vm from "node:vm";
|
|
3
|
+
import defines from "__VITEST_POOL_WORKERS_DEFINES";
|
|
4
|
+
import { createWorkerEntrypointWrapper, maybeHandleRunRequest, registerHandlerAndGlobalWaitUntil, runInRunnerObject } from "cloudflare:test-internal";
|
|
5
|
+
import { DurableObject } from "cloudflare:workers";
|
|
6
|
+
import { Buffer } from "node:buffer";
|
|
7
|
+
|
|
8
|
+
export * from "__VITEST_POOL_WORKERS_USER_OBJECT"
|
|
9
|
+
|
|
10
|
+
//#region ../../node_modules/.pnpm/devalue@5.6.3/node_modules/devalue/src/utils.js
|
|
11
|
+
var DevalueError = class extends Error {
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} message
|
|
14
|
+
* @param {string[]} keys
|
|
15
|
+
* @param {any} [value] - The value that failed to be serialized
|
|
16
|
+
* @param {any} [root] - The root value being serialized
|
|
17
|
+
*/
|
|
18
|
+
constructor(message, keys, value, root) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "DevalueError";
|
|
21
|
+
this.path = keys.join("");
|
|
22
|
+
this.value = value;
|
|
23
|
+
this.root = root;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/** @param {any} thing */
|
|
27
|
+
function is_primitive(thing) {
|
|
28
|
+
return Object(thing) !== thing;
|
|
29
|
+
}
|
|
30
|
+
const object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
|
|
31
|
+
/** @param {any} thing */
|
|
32
|
+
function is_plain_object(thing) {
|
|
33
|
+
const proto = Object.getPrototypeOf(thing);
|
|
34
|
+
return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null || Object.getOwnPropertyNames(proto).sort().join("\0") === object_proto_names;
|
|
35
|
+
}
|
|
36
|
+
/** @param {any} thing */
|
|
37
|
+
function get_type(thing) {
|
|
38
|
+
return Object.prototype.toString.call(thing).slice(8, -1);
|
|
39
|
+
}
|
|
40
|
+
/** @param {string} char */
|
|
41
|
+
function get_escaped_char(char) {
|
|
42
|
+
switch (char) {
|
|
43
|
+
case "\"": return "\\\"";
|
|
44
|
+
case "<": return "\\u003C";
|
|
45
|
+
case "\\": return "\\\\";
|
|
46
|
+
case "\n": return "\\n";
|
|
47
|
+
case "\r": return "\\r";
|
|
48
|
+
case " ": return "\\t";
|
|
49
|
+
case "\b": return "\\b";
|
|
50
|
+
case "\f": return "\\f";
|
|
51
|
+
case "\u2028": return "\\u2028";
|
|
52
|
+
case "\u2029": return "\\u2029";
|
|
53
|
+
default: return char < " " ? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}` : "";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** @param {string} str */
|
|
57
|
+
function stringify_string(str) {
|
|
58
|
+
let result = "";
|
|
59
|
+
let last_pos = 0;
|
|
60
|
+
const len = str.length;
|
|
61
|
+
for (let i = 0; i < len; i += 1) {
|
|
62
|
+
const char = str[i];
|
|
63
|
+
const replacement = get_escaped_char(char);
|
|
64
|
+
if (replacement) {
|
|
65
|
+
result += str.slice(last_pos, i) + replacement;
|
|
66
|
+
last_pos = i + 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return `"${last_pos === 0 ? str : result + str.slice(last_pos)}"`;
|
|
70
|
+
}
|
|
71
|
+
/** @param {Record<string | symbol, any>} object */
|
|
72
|
+
function enumerable_symbols(object) {
|
|
73
|
+
return Object.getOwnPropertySymbols(object).filter((symbol) => Object.getOwnPropertyDescriptor(object, symbol).enumerable);
|
|
74
|
+
}
|
|
75
|
+
const is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
|
|
76
|
+
/** @param {string} key */
|
|
77
|
+
function stringify_key(key) {
|
|
78
|
+
return is_identifier.test(key) ? "." + key : "[" + JSON.stringify(key) + "]";
|
|
79
|
+
}
|
|
80
|
+
/** @param {string} s */
|
|
81
|
+
function is_valid_array_index(s) {
|
|
82
|
+
if (s.length === 0) return false;
|
|
83
|
+
if (s.length > 1 && s.charCodeAt(0) === 48) return false;
|
|
84
|
+
for (let i = 0; i < s.length; i++) {
|
|
85
|
+
const c = s.charCodeAt(i);
|
|
86
|
+
if (c < 48 || c > 57) return false;
|
|
87
|
+
}
|
|
88
|
+
const n = +s;
|
|
89
|
+
if (n >= 2 ** 32 - 1) return false;
|
|
90
|
+
if (n < 0) return false;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Finds the populated indices of an array.
|
|
95
|
+
* @param {unknown[]} array
|
|
96
|
+
*/
|
|
97
|
+
function valid_array_indices(array) {
|
|
98
|
+
const keys = Object.keys(array);
|
|
99
|
+
for (var i = keys.length - 1; i >= 0; i--) if (is_valid_array_index(keys[i])) break;
|
|
100
|
+
keys.length = i + 1;
|
|
101
|
+
return keys;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region ../../node_modules/.pnpm/devalue@5.6.3/node_modules/devalue/src/base64.js
|
|
106
|
+
/**
|
|
107
|
+
* Base64 Encodes an arraybuffer
|
|
108
|
+
* @param {ArrayBuffer} arraybuffer
|
|
109
|
+
* @returns {string}
|
|
110
|
+
*/
|
|
111
|
+
function encode64(arraybuffer) {
|
|
112
|
+
const dv = new DataView(arraybuffer);
|
|
113
|
+
let binaryString = "";
|
|
114
|
+
for (let i = 0; i < arraybuffer.byteLength; i++) binaryString += String.fromCharCode(dv.getUint8(i));
|
|
115
|
+
return binaryToAscii(binaryString);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Decodes a base64 string into an arraybuffer
|
|
119
|
+
* @param {string} string
|
|
120
|
+
* @returns {ArrayBuffer}
|
|
121
|
+
*/
|
|
122
|
+
function decode64(string) {
|
|
123
|
+
const binaryString = asciiToBinary(string);
|
|
124
|
+
const arraybuffer = new ArrayBuffer(binaryString.length);
|
|
125
|
+
const dv = new DataView(arraybuffer);
|
|
126
|
+
for (let i = 0; i < arraybuffer.byteLength; i++) dv.setUint8(i, binaryString.charCodeAt(i));
|
|
127
|
+
return arraybuffer;
|
|
128
|
+
}
|
|
129
|
+
const KEY_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
130
|
+
/**
|
|
131
|
+
* Substitute for atob since it's deprecated in node.
|
|
132
|
+
* Does not do any input validation.
|
|
133
|
+
*
|
|
134
|
+
* @see https://github.com/jsdom/abab/blob/master/lib/atob.js
|
|
135
|
+
*
|
|
136
|
+
* @param {string} data
|
|
137
|
+
* @returns {string}
|
|
138
|
+
*/
|
|
139
|
+
function asciiToBinary(data) {
|
|
140
|
+
if (data.length % 4 === 0) data = data.replace(/==?$/, "");
|
|
141
|
+
let output = "";
|
|
142
|
+
let buffer = 0;
|
|
143
|
+
let accumulatedBits = 0;
|
|
144
|
+
for (let i = 0; i < data.length; i++) {
|
|
145
|
+
buffer <<= 6;
|
|
146
|
+
buffer |= KEY_STRING.indexOf(data[i]);
|
|
147
|
+
accumulatedBits += 6;
|
|
148
|
+
if (accumulatedBits === 24) {
|
|
149
|
+
output += String.fromCharCode((buffer & 16711680) >> 16);
|
|
150
|
+
output += String.fromCharCode((buffer & 65280) >> 8);
|
|
151
|
+
output += String.fromCharCode(buffer & 255);
|
|
152
|
+
buffer = accumulatedBits = 0;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (accumulatedBits === 12) {
|
|
156
|
+
buffer >>= 4;
|
|
157
|
+
output += String.fromCharCode(buffer);
|
|
158
|
+
} else if (accumulatedBits === 18) {
|
|
159
|
+
buffer >>= 2;
|
|
160
|
+
output += String.fromCharCode((buffer & 65280) >> 8);
|
|
161
|
+
output += String.fromCharCode(buffer & 255);
|
|
162
|
+
}
|
|
163
|
+
return output;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Substitute for btoa since it's deprecated in node.
|
|
167
|
+
* Does not do any input validation.
|
|
168
|
+
*
|
|
169
|
+
* @see https://github.com/jsdom/abab/blob/master/lib/btoa.js
|
|
170
|
+
*
|
|
171
|
+
* @param {string} str
|
|
172
|
+
* @returns {string}
|
|
173
|
+
*/
|
|
174
|
+
function binaryToAscii(str) {
|
|
175
|
+
let out = "";
|
|
176
|
+
for (let i = 0; i < str.length; i += 3) {
|
|
177
|
+
/** @type {[number, number, number, number]} */
|
|
178
|
+
const groupsOfSix = [
|
|
179
|
+
void 0,
|
|
180
|
+
void 0,
|
|
181
|
+
void 0,
|
|
182
|
+
void 0
|
|
183
|
+
];
|
|
184
|
+
groupsOfSix[0] = str.charCodeAt(i) >> 2;
|
|
185
|
+
groupsOfSix[1] = (str.charCodeAt(i) & 3) << 4;
|
|
186
|
+
if (str.length > i + 1) {
|
|
187
|
+
groupsOfSix[1] |= str.charCodeAt(i + 1) >> 4;
|
|
188
|
+
groupsOfSix[2] = (str.charCodeAt(i + 1) & 15) << 2;
|
|
189
|
+
}
|
|
190
|
+
if (str.length > i + 2) {
|
|
191
|
+
groupsOfSix[2] |= str.charCodeAt(i + 2) >> 6;
|
|
192
|
+
groupsOfSix[3] = str.charCodeAt(i + 2) & 63;
|
|
193
|
+
}
|
|
194
|
+
for (let j = 0; j < groupsOfSix.length; j++) if (typeof groupsOfSix[j] === "undefined") out += "=";
|
|
195
|
+
else out += KEY_STRING[groupsOfSix[j]];
|
|
196
|
+
}
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region ../../node_modules/.pnpm/devalue@5.6.3/node_modules/devalue/src/constants.js
|
|
202
|
+
const UNDEFINED = -1;
|
|
203
|
+
const HOLE = -2;
|
|
204
|
+
const NAN = -3;
|
|
205
|
+
const POSITIVE_INFINITY = -4;
|
|
206
|
+
const NEGATIVE_INFINITY = -5;
|
|
207
|
+
const NEGATIVE_ZERO = -6;
|
|
208
|
+
const SPARSE = -7;
|
|
209
|
+
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region ../../node_modules/.pnpm/devalue@5.6.3/node_modules/devalue/src/parse.js
|
|
212
|
+
/**
|
|
213
|
+
* Revive a value serialized with `devalue.stringify`
|
|
214
|
+
* @param {string} serialized
|
|
215
|
+
* @param {Record<string, (value: any) => any>} [revivers]
|
|
216
|
+
*/
|
|
217
|
+
function parse(serialized, revivers) {
|
|
218
|
+
return unflatten(JSON.parse(serialized), revivers);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Revive a value flattened with `devalue.stringify`
|
|
222
|
+
* @param {number | any[]} parsed
|
|
223
|
+
* @param {Record<string, (value: any) => any>} [revivers]
|
|
224
|
+
*/
|
|
225
|
+
function unflatten(parsed, revivers) {
|
|
226
|
+
if (typeof parsed === "number") return hydrate(parsed, true);
|
|
227
|
+
if (!Array.isArray(parsed) || parsed.length === 0) throw new Error("Invalid input");
|
|
228
|
+
const values = parsed;
|
|
229
|
+
const hydrated = Array(values.length);
|
|
230
|
+
/**
|
|
231
|
+
* A set of values currently being hydrated with custom revivers,
|
|
232
|
+
* used to detect invalid cyclical dependencies
|
|
233
|
+
* @type {Set<number> | null}
|
|
234
|
+
*/
|
|
235
|
+
let hydrating = null;
|
|
236
|
+
/**
|
|
237
|
+
* @param {number} index
|
|
238
|
+
* @returns {any}
|
|
239
|
+
*/
|
|
240
|
+
function hydrate(index, standalone = false) {
|
|
241
|
+
if (index === UNDEFINED) return void 0;
|
|
242
|
+
if (index === NAN) return NaN;
|
|
243
|
+
if (index === POSITIVE_INFINITY) return Infinity;
|
|
244
|
+
if (index === NEGATIVE_INFINITY) return -Infinity;
|
|
245
|
+
if (index === NEGATIVE_ZERO) return -0;
|
|
246
|
+
if (standalone || typeof index !== "number") throw new Error(`Invalid input`);
|
|
247
|
+
if (index in hydrated) return hydrated[index];
|
|
248
|
+
const value = values[index];
|
|
249
|
+
if (!value || typeof value !== "object") hydrated[index] = value;
|
|
250
|
+
else if (Array.isArray(value)) if (typeof value[0] === "string") {
|
|
251
|
+
const type = value[0];
|
|
252
|
+
const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : void 0;
|
|
253
|
+
if (reviver) {
|
|
254
|
+
let i = value[1];
|
|
255
|
+
if (typeof i !== "number") i = values.push(value[1]) - 1;
|
|
256
|
+
hydrating ??= /* @__PURE__ */ new Set();
|
|
257
|
+
if (hydrating.has(i)) throw new Error("Invalid circular reference");
|
|
258
|
+
hydrating.add(i);
|
|
259
|
+
hydrated[index] = reviver(hydrate(i));
|
|
260
|
+
hydrating.delete(i);
|
|
261
|
+
return hydrated[index];
|
|
262
|
+
}
|
|
263
|
+
switch (type) {
|
|
264
|
+
case "Date":
|
|
265
|
+
hydrated[index] = new Date(value[1]);
|
|
266
|
+
break;
|
|
267
|
+
case "Set":
|
|
268
|
+
const set = /* @__PURE__ */ new Set();
|
|
269
|
+
hydrated[index] = set;
|
|
270
|
+
for (let i = 1; i < value.length; i += 1) set.add(hydrate(value[i]));
|
|
271
|
+
break;
|
|
272
|
+
case "Map":
|
|
273
|
+
const map = /* @__PURE__ */ new Map();
|
|
274
|
+
hydrated[index] = map;
|
|
275
|
+
for (let i = 1; i < value.length; i += 2) map.set(hydrate(value[i]), hydrate(value[i + 1]));
|
|
276
|
+
break;
|
|
277
|
+
case "RegExp":
|
|
278
|
+
hydrated[index] = new RegExp(value[1], value[2]);
|
|
279
|
+
break;
|
|
280
|
+
case "Object":
|
|
281
|
+
hydrated[index] = Object(value[1]);
|
|
282
|
+
break;
|
|
283
|
+
case "BigInt":
|
|
284
|
+
hydrated[index] = BigInt(value[1]);
|
|
285
|
+
break;
|
|
286
|
+
case "null":
|
|
287
|
+
const obj = Object.create(null);
|
|
288
|
+
hydrated[index] = obj;
|
|
289
|
+
for (let i = 1; i < value.length; i += 2) obj[value[i]] = hydrate(value[i + 1]);
|
|
290
|
+
break;
|
|
291
|
+
case "Int8Array":
|
|
292
|
+
case "Uint8Array":
|
|
293
|
+
case "Uint8ClampedArray":
|
|
294
|
+
case "Int16Array":
|
|
295
|
+
case "Uint16Array":
|
|
296
|
+
case "Int32Array":
|
|
297
|
+
case "Uint32Array":
|
|
298
|
+
case "Float32Array":
|
|
299
|
+
case "Float64Array":
|
|
300
|
+
case "BigInt64Array":
|
|
301
|
+
case "BigUint64Array": {
|
|
302
|
+
if (values[value[1]][0] !== "ArrayBuffer") throw new Error("Invalid data");
|
|
303
|
+
const TypedArrayConstructor = globalThis[type];
|
|
304
|
+
const typedArray = new TypedArrayConstructor(hydrate(value[1]));
|
|
305
|
+
hydrated[index] = value[2] !== void 0 ? typedArray.subarray(value[2], value[3]) : typedArray;
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
case "ArrayBuffer": {
|
|
309
|
+
const base64 = value[1];
|
|
310
|
+
if (typeof base64 !== "string") throw new Error("Invalid ArrayBuffer encoding");
|
|
311
|
+
hydrated[index] = decode64(base64);
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
case "Temporal.Duration":
|
|
315
|
+
case "Temporal.Instant":
|
|
316
|
+
case "Temporal.PlainDate":
|
|
317
|
+
case "Temporal.PlainTime":
|
|
318
|
+
case "Temporal.PlainDateTime":
|
|
319
|
+
case "Temporal.PlainMonthDay":
|
|
320
|
+
case "Temporal.PlainYearMonth":
|
|
321
|
+
case "Temporal.ZonedDateTime": {
|
|
322
|
+
const temporalName = type.slice(9);
|
|
323
|
+
hydrated[index] = Temporal[temporalName].from(value[1]);
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
case "URL":
|
|
327
|
+
hydrated[index] = new URL(value[1]);
|
|
328
|
+
break;
|
|
329
|
+
case "URLSearchParams":
|
|
330
|
+
hydrated[index] = new URLSearchParams(value[1]);
|
|
331
|
+
break;
|
|
332
|
+
default: throw new Error(`Unknown type ${type}`);
|
|
333
|
+
}
|
|
334
|
+
} else if (value[0] === SPARSE) {
|
|
335
|
+
const len = value[1];
|
|
336
|
+
const array = new Array(len);
|
|
337
|
+
hydrated[index] = array;
|
|
338
|
+
for (let i = 2; i < value.length; i += 2) {
|
|
339
|
+
const idx = value[i];
|
|
340
|
+
array[idx] = hydrate(value[i + 1]);
|
|
341
|
+
}
|
|
342
|
+
} else {
|
|
343
|
+
const array = new Array(value.length);
|
|
344
|
+
hydrated[index] = array;
|
|
345
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
346
|
+
const n = value[i];
|
|
347
|
+
if (n === HOLE) continue;
|
|
348
|
+
array[i] = hydrate(n);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
/** @type {Record<string, any>} */
|
|
353
|
+
const object = {};
|
|
354
|
+
hydrated[index] = object;
|
|
355
|
+
for (const key of Object.keys(value)) {
|
|
356
|
+
if (key === "__proto__") throw new Error("Cannot parse an object with a `__proto__` property");
|
|
357
|
+
const n = value[key];
|
|
358
|
+
object[key] = hydrate(n);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return hydrated[index];
|
|
362
|
+
}
|
|
363
|
+
return hydrate(0);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region ../../node_modules/.pnpm/devalue@5.6.3/node_modules/devalue/src/stringify.js
|
|
368
|
+
/**
|
|
369
|
+
* Turn a value into a JSON string that can be parsed with `devalue.parse`
|
|
370
|
+
* @param {any} value
|
|
371
|
+
* @param {Record<string, (value: any) => any>} [reducers]
|
|
372
|
+
*/
|
|
373
|
+
function stringify(value, reducers) {
|
|
374
|
+
/** @type {any[]} */
|
|
375
|
+
const stringified = [];
|
|
376
|
+
/** @type {Map<any, number>} */
|
|
377
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
378
|
+
/** @type {Array<{ key: string, fn: (value: any) => any }>} */
|
|
379
|
+
const custom = [];
|
|
380
|
+
if (reducers) for (const key of Object.getOwnPropertyNames(reducers)) custom.push({
|
|
381
|
+
key,
|
|
382
|
+
fn: reducers[key]
|
|
383
|
+
});
|
|
384
|
+
/** @type {string[]} */
|
|
385
|
+
const keys = [];
|
|
386
|
+
let p = 0;
|
|
387
|
+
/** @param {any} thing */
|
|
388
|
+
function flatten(thing) {
|
|
389
|
+
if (thing === void 0) return UNDEFINED;
|
|
390
|
+
if (Number.isNaN(thing)) return NAN;
|
|
391
|
+
if (thing === Infinity) return POSITIVE_INFINITY;
|
|
392
|
+
if (thing === -Infinity) return NEGATIVE_INFINITY;
|
|
393
|
+
if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO;
|
|
394
|
+
if (indexes.has(thing)) return indexes.get(thing);
|
|
395
|
+
const index$1 = p++;
|
|
396
|
+
indexes.set(thing, index$1);
|
|
397
|
+
for (const { key, fn } of custom) {
|
|
398
|
+
const value$1 = fn(thing);
|
|
399
|
+
if (value$1) {
|
|
400
|
+
stringified[index$1] = `["${key}",${flatten(value$1)}]`;
|
|
401
|
+
return index$1;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (typeof thing === "function") throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
|
|
405
|
+
let str = "";
|
|
406
|
+
if (is_primitive(thing)) str = stringify_primitive(thing);
|
|
407
|
+
else {
|
|
408
|
+
const type = get_type(thing);
|
|
409
|
+
switch (type) {
|
|
410
|
+
case "Number":
|
|
411
|
+
case "String":
|
|
412
|
+
case "Boolean":
|
|
413
|
+
str = `["Object",${stringify_primitive(thing)}]`;
|
|
414
|
+
break;
|
|
415
|
+
case "BigInt":
|
|
416
|
+
str = `["BigInt",${thing}]`;
|
|
417
|
+
break;
|
|
418
|
+
case "Date":
|
|
419
|
+
str = `["Date","${!isNaN(thing.getDate()) ? thing.toISOString() : ""}"]`;
|
|
420
|
+
break;
|
|
421
|
+
case "URL":
|
|
422
|
+
str = `["URL",${stringify_string(thing.toString())}]`;
|
|
423
|
+
break;
|
|
424
|
+
case "URLSearchParams":
|
|
425
|
+
str = `["URLSearchParams",${stringify_string(thing.toString())}]`;
|
|
426
|
+
break;
|
|
427
|
+
case "RegExp":
|
|
428
|
+
const { source, flags } = thing;
|
|
429
|
+
str = flags ? `["RegExp",${stringify_string(source)},"${flags}"]` : `["RegExp",${stringify_string(source)}]`;
|
|
430
|
+
break;
|
|
431
|
+
case "Array": {
|
|
432
|
+
let mostly_dense = false;
|
|
433
|
+
str = "[";
|
|
434
|
+
for (let i = 0; i < thing.length; i += 1) {
|
|
435
|
+
if (i > 0) str += ",";
|
|
436
|
+
if (Object.hasOwn(thing, i)) {
|
|
437
|
+
keys.push(`[${i}]`);
|
|
438
|
+
str += flatten(thing[i]);
|
|
439
|
+
keys.pop();
|
|
440
|
+
} else if (mostly_dense) str += HOLE;
|
|
441
|
+
else {
|
|
442
|
+
const populated_keys = valid_array_indices(thing);
|
|
443
|
+
const population = populated_keys.length;
|
|
444
|
+
const d = String(thing.length).length;
|
|
445
|
+
if ((thing.length - population) * 3 > 4 + d + population * (d + 1)) {
|
|
446
|
+
str = "[" + SPARSE + "," + thing.length;
|
|
447
|
+
for (let j = 0; j < populated_keys.length; j++) {
|
|
448
|
+
const key = populated_keys[j];
|
|
449
|
+
keys.push(`[${key}]`);
|
|
450
|
+
str += "," + key + "," + flatten(thing[key]);
|
|
451
|
+
keys.pop();
|
|
452
|
+
}
|
|
453
|
+
break;
|
|
454
|
+
} else {
|
|
455
|
+
mostly_dense = true;
|
|
456
|
+
str += HOLE;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
str += "]";
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
case "Set":
|
|
464
|
+
str = "[\"Set\"";
|
|
465
|
+
for (const value$1 of thing) str += `,${flatten(value$1)}`;
|
|
466
|
+
str += "]";
|
|
467
|
+
break;
|
|
468
|
+
case "Map":
|
|
469
|
+
str = "[\"Map\"";
|
|
470
|
+
for (const [key, value$1] of thing) {
|
|
471
|
+
keys.push(`.get(${is_primitive(key) ? stringify_primitive(key) : "..."})`);
|
|
472
|
+
str += `,${flatten(key)},${flatten(value$1)}`;
|
|
473
|
+
keys.pop();
|
|
474
|
+
}
|
|
475
|
+
str += "]";
|
|
476
|
+
break;
|
|
477
|
+
case "Int8Array":
|
|
478
|
+
case "Uint8Array":
|
|
479
|
+
case "Uint8ClampedArray":
|
|
480
|
+
case "Int16Array":
|
|
481
|
+
case "Uint16Array":
|
|
482
|
+
case "Int32Array":
|
|
483
|
+
case "Uint32Array":
|
|
484
|
+
case "Float32Array":
|
|
485
|
+
case "Float64Array":
|
|
486
|
+
case "BigInt64Array":
|
|
487
|
+
case "BigUint64Array": {
|
|
488
|
+
/** @type {import("./types.js").TypedArray} */
|
|
489
|
+
const typedArray = thing;
|
|
490
|
+
str = "[\"" + type + "\"," + flatten(typedArray.buffer);
|
|
491
|
+
const a = thing.byteOffset;
|
|
492
|
+
const b = a + thing.byteLength;
|
|
493
|
+
if (a > 0 || b !== typedArray.buffer.byteLength) {
|
|
494
|
+
const m = +/(\d+)/.exec(type)[1] / 8;
|
|
495
|
+
str += `,${a / m},${b / m}`;
|
|
496
|
+
}
|
|
497
|
+
str += "]";
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
500
|
+
case "ArrayBuffer":
|
|
501
|
+
str = `["ArrayBuffer","${encode64(thing)}"]`;
|
|
502
|
+
break;
|
|
503
|
+
case "Temporal.Duration":
|
|
504
|
+
case "Temporal.Instant":
|
|
505
|
+
case "Temporal.PlainDate":
|
|
506
|
+
case "Temporal.PlainTime":
|
|
507
|
+
case "Temporal.PlainDateTime":
|
|
508
|
+
case "Temporal.PlainMonthDay":
|
|
509
|
+
case "Temporal.PlainYearMonth":
|
|
510
|
+
case "Temporal.ZonedDateTime":
|
|
511
|
+
str = `["${type}",${stringify_string(thing.toString())}]`;
|
|
512
|
+
break;
|
|
513
|
+
default:
|
|
514
|
+
if (!is_plain_object(thing)) throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value);
|
|
515
|
+
if (enumerable_symbols(thing).length > 0) throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value);
|
|
516
|
+
if (Object.getPrototypeOf(thing) === null) {
|
|
517
|
+
str = "[\"null\"";
|
|
518
|
+
for (const key of Object.keys(thing)) {
|
|
519
|
+
if (key === "__proto__") throw new DevalueError(`Cannot stringify objects with __proto__ keys`, keys, thing, value);
|
|
520
|
+
keys.push(stringify_key(key));
|
|
521
|
+
str += `,${stringify_string(key)},${flatten(thing[key])}`;
|
|
522
|
+
keys.pop();
|
|
523
|
+
}
|
|
524
|
+
str += "]";
|
|
525
|
+
} else {
|
|
526
|
+
str = "{";
|
|
527
|
+
let started = false;
|
|
528
|
+
for (const key of Object.keys(thing)) {
|
|
529
|
+
if (key === "__proto__") throw new DevalueError(`Cannot stringify objects with __proto__ keys`, keys, thing, value);
|
|
530
|
+
if (started) str += ",";
|
|
531
|
+
started = true;
|
|
532
|
+
keys.push(stringify_key(key));
|
|
533
|
+
str += `${stringify_string(key)}:${flatten(thing[key])}`;
|
|
534
|
+
keys.pop();
|
|
535
|
+
}
|
|
536
|
+
str += "}";
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
stringified[index$1] = str;
|
|
541
|
+
return index$1;
|
|
542
|
+
}
|
|
543
|
+
const index = flatten(value);
|
|
544
|
+
if (index < 0) return `${index}`;
|
|
545
|
+
return `[${stringified.join(",")}]`;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* @param {any} thing
|
|
549
|
+
* @returns {string}
|
|
550
|
+
*/
|
|
551
|
+
function stringify_primitive(thing) {
|
|
552
|
+
const type = typeof thing;
|
|
553
|
+
if (type === "string") return stringify_string(thing);
|
|
554
|
+
if (thing instanceof String) return stringify_string(thing.toString());
|
|
555
|
+
if (thing === void 0) return UNDEFINED.toString();
|
|
556
|
+
if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO.toString();
|
|
557
|
+
if (type === "bigint") return `["BigInt","${thing}"]`;
|
|
558
|
+
return String(thing);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region ../miniflare/src/workers/core/devalue.ts
|
|
563
|
+
const ALLOWED_ARRAY_BUFFER_VIEW_CONSTRUCTORS = [
|
|
564
|
+
DataView,
|
|
565
|
+
Int8Array,
|
|
566
|
+
Uint8Array,
|
|
567
|
+
Uint8ClampedArray,
|
|
568
|
+
Int16Array,
|
|
569
|
+
Uint16Array,
|
|
570
|
+
Int32Array,
|
|
571
|
+
Uint32Array,
|
|
572
|
+
Float32Array,
|
|
573
|
+
Float64Array,
|
|
574
|
+
BigInt64Array,
|
|
575
|
+
BigUint64Array
|
|
576
|
+
];
|
|
577
|
+
const ALLOWED_ERROR_CONSTRUCTORS = [
|
|
578
|
+
EvalError,
|
|
579
|
+
RangeError,
|
|
580
|
+
ReferenceError,
|
|
581
|
+
SyntaxError,
|
|
582
|
+
TypeError,
|
|
583
|
+
URIError,
|
|
584
|
+
Error
|
|
585
|
+
];
|
|
586
|
+
const structuredSerializableReducers = {
|
|
587
|
+
ArrayBuffer(value) {
|
|
588
|
+
if (value instanceof ArrayBuffer) return [Buffer.from(value).toString("base64")];
|
|
589
|
+
},
|
|
590
|
+
ArrayBufferView(value) {
|
|
591
|
+
if (ArrayBuffer.isView(value)) {
|
|
592
|
+
let name = value.constructor.name;
|
|
593
|
+
if (!ALLOWED_ARRAY_BUFFER_VIEW_CONSTRUCTORS.some((c) => c.name === name)) {
|
|
594
|
+
for (const ctor of ALLOWED_ARRAY_BUFFER_VIEW_CONSTRUCTORS) if (value instanceof ctor) {
|
|
595
|
+
name = ctor.name;
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
let buf = value.buffer;
|
|
600
|
+
let off = value.byteOffset;
|
|
601
|
+
if (off !== 0 || buf.byteLength !== value.byteLength) {
|
|
602
|
+
buf = buf.slice(off, off + value.byteLength);
|
|
603
|
+
off = 0;
|
|
604
|
+
}
|
|
605
|
+
return [
|
|
606
|
+
name,
|
|
607
|
+
buf,
|
|
608
|
+
off,
|
|
609
|
+
value.byteLength
|
|
610
|
+
];
|
|
611
|
+
}
|
|
612
|
+
},
|
|
613
|
+
RegExp(value) {
|
|
614
|
+
if (value instanceof RegExp) {
|
|
615
|
+
const { source, flags } = value;
|
|
616
|
+
const encoded = Buffer.from(source).toString("base64");
|
|
617
|
+
return flags ? [
|
|
618
|
+
"RegExp",
|
|
619
|
+
encoded,
|
|
620
|
+
flags
|
|
621
|
+
] : ["RegExp", encoded];
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
Error(value) {
|
|
625
|
+
for (const ctor of ALLOWED_ERROR_CONSTRUCTORS) if (value instanceof ctor && value.name === ctor.name) return [
|
|
626
|
+
value.name,
|
|
627
|
+
value.message,
|
|
628
|
+
value.stack,
|
|
629
|
+
value.cause
|
|
630
|
+
];
|
|
631
|
+
if (value instanceof Error) return [
|
|
632
|
+
"Error",
|
|
633
|
+
value.message,
|
|
634
|
+
value.stack,
|
|
635
|
+
value.cause
|
|
636
|
+
];
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
const structuredSerializableRevivers = {
|
|
640
|
+
ArrayBuffer(value) {
|
|
641
|
+
assert(Array.isArray(value));
|
|
642
|
+
const [encoded] = value;
|
|
643
|
+
assert(typeof encoded === "string");
|
|
644
|
+
const view = Buffer.from(encoded, "base64");
|
|
645
|
+
return view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength);
|
|
646
|
+
},
|
|
647
|
+
ArrayBufferView(value) {
|
|
648
|
+
assert(Array.isArray(value));
|
|
649
|
+
const [name, buffer, byteOffset, byteLength] = value;
|
|
650
|
+
assert(typeof name === "string");
|
|
651
|
+
assert(buffer instanceof ArrayBuffer);
|
|
652
|
+
assert(typeof byteOffset === "number");
|
|
653
|
+
assert(typeof byteLength === "number");
|
|
654
|
+
const ctor = globalThis[name];
|
|
655
|
+
assert(ALLOWED_ARRAY_BUFFER_VIEW_CONSTRUCTORS.includes(ctor));
|
|
656
|
+
let length = byteLength;
|
|
657
|
+
if ("BYTES_PER_ELEMENT" in ctor) length /= ctor.BYTES_PER_ELEMENT;
|
|
658
|
+
return new ctor(buffer, byteOffset, length);
|
|
659
|
+
},
|
|
660
|
+
RegExp(value) {
|
|
661
|
+
assert(Array.isArray(value));
|
|
662
|
+
const [name, encoded, flags] = value;
|
|
663
|
+
assert(typeof name === "string");
|
|
664
|
+
assert(typeof encoded === "string");
|
|
665
|
+
const source = Buffer.from(encoded, "base64").toString("utf-8");
|
|
666
|
+
return new RegExp(source, flags);
|
|
667
|
+
},
|
|
668
|
+
Error(value) {
|
|
669
|
+
assert(Array.isArray(value));
|
|
670
|
+
const [name, message, stack, cause] = value;
|
|
671
|
+
assert(typeof name === "string");
|
|
672
|
+
assert(typeof message === "string");
|
|
673
|
+
assert(stack === void 0 || typeof stack === "string");
|
|
674
|
+
const ctor = globalThis[name];
|
|
675
|
+
assert(ALLOWED_ERROR_CONSTRUCTORS.includes(ctor));
|
|
676
|
+
const error = new ctor(message, { cause });
|
|
677
|
+
error.stack = stack;
|
|
678
|
+
return error;
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
//#endregion
|
|
683
|
+
//#region src/shared/module-path.ts
|
|
684
|
+
const ENCODED_PATH_PREFIX = "/__mf_vitest_encoded__";
|
|
685
|
+
/**
|
|
686
|
+
* Marks encoded file URLs so the module fallback service can decode them
|
|
687
|
+
* without guessing whether percent sequences are URL encoding or literal path
|
|
688
|
+
* characters.
|
|
689
|
+
*
|
|
690
|
+
* @param url - The module URL Vitest uses as the base for `createRequire()`.
|
|
691
|
+
* @returns The marked file URL, or the original value when decoding isn't needed.
|
|
692
|
+
*/
|
|
693
|
+
function markCreateRequireUrl(url) {
|
|
694
|
+
if (!url.startsWith("file:")) return url;
|
|
695
|
+
const parsedUrl = new URL(url);
|
|
696
|
+
if (!parsedUrl.pathname.includes("%") || parsedUrl.pathname.startsWith(ENCODED_PATH_PREFIX)) return url;
|
|
697
|
+
parsedUrl.pathname = `${ENCODED_PATH_PREFIX}${parsedUrl.pathname}`;
|
|
698
|
+
return parsedUrl.href;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
//#endregion
|
|
702
|
+
//#region src/worker/index.ts
|
|
703
|
+
function structuredSerializableStringify(value) {
|
|
704
|
+
return stringify(value, structuredSerializableReducers);
|
|
705
|
+
}
|
|
706
|
+
function structuredSerializableParse(value) {
|
|
707
|
+
return parse(value, structuredSerializableRevivers);
|
|
708
|
+
}
|
|
709
|
+
globalThis.BroadcastChannel = class {
|
|
710
|
+
constructor(name) {
|
|
711
|
+
this.name = name;
|
|
712
|
+
}
|
|
713
|
+
postMessage(_message) {}
|
|
714
|
+
close() {}
|
|
715
|
+
addEventListener(_type, _listener) {}
|
|
716
|
+
removeEventListener(_type, _listener) {}
|
|
717
|
+
onmessage = null;
|
|
718
|
+
onmessageerror = null;
|
|
719
|
+
};
|
|
720
|
+
let cwd;
|
|
721
|
+
process.cwd = () => {
|
|
722
|
+
assert(cwd !== void 0, "Expected cwd to be set");
|
|
723
|
+
return cwd;
|
|
724
|
+
};
|
|
725
|
+
globalThis.__console = console;
|
|
726
|
+
function getCallerFileName(of) {
|
|
727
|
+
const originalStackTraceLimit = Error.stackTraceLimit;
|
|
728
|
+
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
729
|
+
try {
|
|
730
|
+
let fileName = null;
|
|
731
|
+
Error.stackTraceLimit = 1;
|
|
732
|
+
Error.prepareStackTrace = (_error, callSites) => {
|
|
733
|
+
fileName = callSites[0]?.getFileName();
|
|
734
|
+
return "";
|
|
735
|
+
};
|
|
736
|
+
const error = {};
|
|
737
|
+
Error.captureStackTrace(error, of);
|
|
738
|
+
error.stack;
|
|
739
|
+
return fileName;
|
|
740
|
+
} finally {
|
|
741
|
+
Error.stackTraceLimit = originalStackTraceLimit;
|
|
742
|
+
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
const originalSetTimeout = globalThis.setTimeout;
|
|
746
|
+
const originalClearTimeout = globalThis.clearTimeout;
|
|
747
|
+
const timeoutPromiseResolves = /* @__PURE__ */ new Map();
|
|
748
|
+
const monkeypatchedSetTimeout = (...args) => {
|
|
749
|
+
const [callback, delay, ...restArgs] = args;
|
|
750
|
+
const callbackName = args[0]?.name ?? "";
|
|
751
|
+
const callerFileName = getCallerFileName(monkeypatchedSetTimeout);
|
|
752
|
+
if (!(/\/node_modules\/(\.pnpm\/|\.store\/)?vitest/.test(callerFileName ?? "") || /\/packages\/vitest\/dist/.test(callerFileName ?? "") || /\/node_modules\/(\.pnpm\/|\.store\/)?@voidzero-dev[+/]vite-plus-test/.test(callerFileName ?? "")) || delay) return originalSetTimeout.apply(globalThis, args);
|
|
753
|
+
if (callbackName === "NOOP") return -.5;
|
|
754
|
+
let promiseResolve;
|
|
755
|
+
const promise = new Promise((resolve) => {
|
|
756
|
+
promiseResolve = resolve;
|
|
757
|
+
});
|
|
758
|
+
assert(promiseResolve !== void 0);
|
|
759
|
+
registerHandlerAndGlobalWaitUntil(promise);
|
|
760
|
+
const id = originalSetTimeout.call(globalThis, () => {
|
|
761
|
+
promiseResolve?.();
|
|
762
|
+
callback?.(...restArgs);
|
|
763
|
+
});
|
|
764
|
+
timeoutPromiseResolves.set(id, promiseResolve);
|
|
765
|
+
return id;
|
|
766
|
+
};
|
|
767
|
+
globalThis.setTimeout = monkeypatchedSetTimeout;
|
|
768
|
+
globalThis.clearTimeout = (...args) => {
|
|
769
|
+
const id = args[0];
|
|
770
|
+
if (id === -.5) return;
|
|
771
|
+
const maybePromiseResolve = timeoutPromiseResolves.get(id);
|
|
772
|
+
timeoutPromiseResolves.delete(id);
|
|
773
|
+
maybePromiseResolve?.();
|
|
774
|
+
return originalClearTimeout.apply(globalThis, args);
|
|
775
|
+
};
|
|
776
|
+
function isDifferentIOContextError(e) {
|
|
777
|
+
return e instanceof Error && e.message.startsWith("Cannot perform I/O on behalf of a different");
|
|
778
|
+
}
|
|
779
|
+
function isUserConsoleLogResponse(response) {
|
|
780
|
+
return typeof response === "object" && response !== null && "m" in response && response.m === "onUserConsoleLog";
|
|
781
|
+
}
|
|
782
|
+
let patchedFunction = false;
|
|
783
|
+
function ensurePatchedFunction(unsafeEval) {
|
|
784
|
+
if (patchedFunction) return;
|
|
785
|
+
patchedFunction = true;
|
|
786
|
+
globalThis.Function = new Proxy(globalThis.Function, { construct(_target, args, _newTarget) {
|
|
787
|
+
const script = args.pop();
|
|
788
|
+
return unsafeEval.newFunction(script, "anonymous", ...args);
|
|
789
|
+
} });
|
|
790
|
+
}
|
|
791
|
+
function applyDefines() {
|
|
792
|
+
for (const [key, value] of Object.entries(defines)) {
|
|
793
|
+
const segments = key.split(".");
|
|
794
|
+
let target = globalThis;
|
|
795
|
+
for (let i = 0; i < segments.length; i++) {
|
|
796
|
+
const segment = segments[i];
|
|
797
|
+
if (i === segments.length - 1) target[segment] = value;
|
|
798
|
+
else target = target[segment] ??= {};
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
var __VITEST_POOL_WORKERS_RUNNER_DURABLE_OBJECT__ = class extends DurableObject {
|
|
803
|
+
constructor(_state, doEnv) {
|
|
804
|
+
super(_state, doEnv);
|
|
805
|
+
vm._setUnsafeEval(doEnv.__VITEST_POOL_WORKERS_UNSAFE_EVAL);
|
|
806
|
+
ensurePatchedFunction(doEnv.__VITEST_POOL_WORKERS_UNSAFE_EVAL);
|
|
807
|
+
applyDefines();
|
|
808
|
+
}
|
|
809
|
+
async handleVitestRunRequest(request) {
|
|
810
|
+
assert.strictEqual(request.headers.get("Upgrade"), "websocket");
|
|
811
|
+
const { 0: poolSocket, 1: poolResponseSocket } = new WebSocketPair();
|
|
812
|
+
const workerDataHeader = request.headers.get("MF-Vitest-Worker-Data");
|
|
813
|
+
assert(workerDataHeader);
|
|
814
|
+
const wd = structuredSerializableParse(decodeURIComponent(workerDataHeader));
|
|
815
|
+
assert(wd && typeof wd === "object" && "cwd" in wd && typeof wd.cwd === "string");
|
|
816
|
+
cwd = wd.cwd;
|
|
817
|
+
const { init, runBaseTests, setupEnvironment } = await import("vitest/worker");
|
|
818
|
+
poolSocket.accept();
|
|
819
|
+
const pendingConsoleLogs = [];
|
|
820
|
+
const sendPendingConsoleLogs = () => {
|
|
821
|
+
while (pendingConsoleLogs.length > 0) {
|
|
822
|
+
poolSocket.send(structuredSerializableStringify(pendingConsoleLogs[0]));
|
|
823
|
+
pendingConsoleLogs.shift();
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
init({
|
|
827
|
+
post: (response) => {
|
|
828
|
+
try {
|
|
829
|
+
sendPendingConsoleLogs();
|
|
830
|
+
poolSocket.send(structuredSerializableStringify(response));
|
|
831
|
+
} catch (error) {
|
|
832
|
+
if (isDifferentIOContextError(error)) {
|
|
833
|
+
if (isUserConsoleLogResponse(response)) {
|
|
834
|
+
pendingConsoleLogs.push(response);
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
registerHandlerAndGlobalWaitUntil(runInRunnerObject(() => {
|
|
838
|
+
poolSocket.send(structuredSerializableStringify(response));
|
|
839
|
+
}).catch((e) => {
|
|
840
|
+
__console.error("Error sending to pool inside runner:", e, response);
|
|
841
|
+
}));
|
|
842
|
+
} else __console.error("Error sending to pool:", error, response);
|
|
843
|
+
}
|
|
844
|
+
},
|
|
845
|
+
on: (callback) => {
|
|
846
|
+
poolSocket.addEventListener("message", (m) => {
|
|
847
|
+
callback(structuredSerializableParse(m.data));
|
|
848
|
+
});
|
|
849
|
+
},
|
|
850
|
+
runTests: (state, traces) => runBaseTests("run", state, traces),
|
|
851
|
+
collectTests: (state, traces) => runBaseTests("collect", state, traces),
|
|
852
|
+
setup: setupEnvironment,
|
|
853
|
+
onModuleRunner(moduleRunner) {
|
|
854
|
+
const runner = moduleRunner;
|
|
855
|
+
if (runner.evaluator?.createRequire) {
|
|
856
|
+
const originalCreateRequire = runner.evaluator.createRequire.bind(runner.evaluator);
|
|
857
|
+
function createRequire(url) {
|
|
858
|
+
return originalCreateRequire(markCreateRequireUrl(url));
|
|
859
|
+
}
|
|
860
|
+
runner.evaluator.createRequire = createRequire;
|
|
861
|
+
} else __console.warn("[vitest-plugin] Could not patch module runner createRequire. Relative require() may fail when the project path contains encoded characters.");
|
|
862
|
+
if (runner.transport?.invoke) {
|
|
863
|
+
const originalInvoke = runner.transport.invoke.bind(runner.transport);
|
|
864
|
+
runner.transport.invoke = (...args) => {
|
|
865
|
+
return runInRunnerObject(() => originalInvoke(...args));
|
|
866
|
+
};
|
|
867
|
+
} else __console.warn("[vitest-plugin] Could not patch module runner transport. Dynamic import() inside entrypoint/DO handlers may fail.");
|
|
868
|
+
}
|
|
869
|
+
});
|
|
870
|
+
return new Response(null, {
|
|
871
|
+
status: 101,
|
|
872
|
+
webSocket: poolResponseSocket
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
async fetch(request) {
|
|
876
|
+
const response = await maybeHandleRunRequest(request, this);
|
|
877
|
+
if (response !== void 0) return response;
|
|
878
|
+
return this.handleVitestRunRequest(request);
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
var worker_default = createWorkerEntrypointWrapper("default");
|
|
882
|
+
|
|
883
|
+
//#endregion
|
|
884
|
+
export { __VITEST_POOL_WORKERS_RUNNER_DURABLE_OBJECT__, worker_default as default };
|
|
885
|
+
//# sourceMappingURL=index.mjs.map
|