@cloudflare/vitest-pool-workers 0.12.20 → 0.12.21
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/pool/index.mjs +120 -22
- package/dist/pool/index.mjs.map +2 -2
- package/dist/worker/index.mjs +118 -20
- package/dist/worker/index.mjs.map +2 -2
- package/package.json +6 -6
package/dist/pool/index.mjs
CHANGED
|
@@ -1241,20 +1241,24 @@ function nanoid(size = 21) {
|
|
|
1241
1241
|
return id;
|
|
1242
1242
|
}
|
|
1243
1243
|
|
|
1244
|
-
// ../../node_modules/.pnpm/devalue@5.3
|
|
1244
|
+
// ../../node_modules/.pnpm/devalue@5.6.3/node_modules/devalue/index.js
|
|
1245
1245
|
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
1246
1246
|
|
|
1247
|
-
// ../../node_modules/.pnpm/devalue@5.3
|
|
1247
|
+
// ../../node_modules/.pnpm/devalue@5.6.3/node_modules/devalue/src/utils.js
|
|
1248
1248
|
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
1249
1249
|
var DevalueError = class extends Error {
|
|
1250
1250
|
/**
|
|
1251
1251
|
* @param {string} message
|
|
1252
1252
|
* @param {string[]} keys
|
|
1253
|
+
* @param {any} [value] - The value that failed to be serialized
|
|
1254
|
+
* @param {any} [root] - The root value being serialized
|
|
1253
1255
|
*/
|
|
1254
|
-
constructor(message, keys) {
|
|
1256
|
+
constructor(message, keys, value, root) {
|
|
1255
1257
|
super(message);
|
|
1256
1258
|
this.name = "DevalueError";
|
|
1257
1259
|
this.path = keys.join("");
|
|
1260
|
+
this.value = value;
|
|
1261
|
+
this.root = root;
|
|
1258
1262
|
}
|
|
1259
1263
|
};
|
|
1260
1264
|
function is_primitive(thing) {
|
|
@@ -1319,11 +1323,33 @@ var is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
|
|
|
1319
1323
|
function stringify_key(key) {
|
|
1320
1324
|
return is_identifier.test(key) ? "." + key : "[" + JSON.stringify(key) + "]";
|
|
1321
1325
|
}
|
|
1326
|
+
function is_valid_array_index(s) {
|
|
1327
|
+
if (s.length === 0) return false;
|
|
1328
|
+
if (s.length > 1 && s.charCodeAt(0) === 48) return false;
|
|
1329
|
+
for (let i = 0; i < s.length; i++) {
|
|
1330
|
+
const c = s.charCodeAt(i);
|
|
1331
|
+
if (c < 48 || c > 57) return false;
|
|
1332
|
+
}
|
|
1333
|
+
const n = +s;
|
|
1334
|
+
if (n >= 2 ** 32 - 1) return false;
|
|
1335
|
+
if (n < 0) return false;
|
|
1336
|
+
return true;
|
|
1337
|
+
}
|
|
1338
|
+
function valid_array_indices(array) {
|
|
1339
|
+
const keys = Object.keys(array);
|
|
1340
|
+
for (var i = keys.length - 1; i >= 0; i--) {
|
|
1341
|
+
if (is_valid_array_index(keys[i])) {
|
|
1342
|
+
break;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
keys.length = i + 1;
|
|
1346
|
+
return keys;
|
|
1347
|
+
}
|
|
1322
1348
|
|
|
1323
|
-
// ../../node_modules/.pnpm/devalue@5.3
|
|
1349
|
+
// ../../node_modules/.pnpm/devalue@5.6.3/node_modules/devalue/src/parse.js
|
|
1324
1350
|
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
1325
1351
|
|
|
1326
|
-
// ../../node_modules/.pnpm/devalue@5.3
|
|
1352
|
+
// ../../node_modules/.pnpm/devalue@5.6.3/node_modules/devalue/src/base64.js
|
|
1327
1353
|
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
1328
1354
|
function encode64(arraybuffer) {
|
|
1329
1355
|
const dv = new DataView(arraybuffer);
|
|
@@ -1396,7 +1422,7 @@ function binaryToAscii(str) {
|
|
|
1396
1422
|
return out;
|
|
1397
1423
|
}
|
|
1398
1424
|
|
|
1399
|
-
// ../../node_modules/.pnpm/devalue@5.3
|
|
1425
|
+
// ../../node_modules/.pnpm/devalue@5.6.3/node_modules/devalue/src/constants.js
|
|
1400
1426
|
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
1401
1427
|
var UNDEFINED = -1;
|
|
1402
1428
|
var HOLE = -2;
|
|
@@ -1404,8 +1430,9 @@ var NAN = -3;
|
|
|
1404
1430
|
var POSITIVE_INFINITY = -4;
|
|
1405
1431
|
var NEGATIVE_INFINITY = -5;
|
|
1406
1432
|
var NEGATIVE_ZERO = -6;
|
|
1433
|
+
var SPARSE = -7;
|
|
1407
1434
|
|
|
1408
|
-
// ../../node_modules/.pnpm/devalue@5.3
|
|
1435
|
+
// ../../node_modules/.pnpm/devalue@5.6.3/node_modules/devalue/src/parse.js
|
|
1409
1436
|
function parse(serialized, revivers) {
|
|
1410
1437
|
return unflatten(JSON.parse(serialized), revivers);
|
|
1411
1438
|
}
|
|
@@ -1419,6 +1446,7 @@ function unflatten(parsed, revivers) {
|
|
|
1419
1446
|
parsed
|
|
1420
1447
|
);
|
|
1421
1448
|
const hydrated = Array(values.length);
|
|
1449
|
+
let hydrating = null;
|
|
1422
1450
|
function hydrate(index, standalone = false) {
|
|
1423
1451
|
if (index === UNDEFINED) return void 0;
|
|
1424
1452
|
if (index === NAN) return NaN;
|
|
@@ -1435,9 +1463,20 @@ function unflatten(parsed, revivers) {
|
|
|
1435
1463
|
} else if (Array.isArray(value)) {
|
|
1436
1464
|
if (typeof value[0] === "string") {
|
|
1437
1465
|
const type = value[0];
|
|
1438
|
-
const reviver = revivers
|
|
1466
|
+
const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : void 0;
|
|
1439
1467
|
if (reviver) {
|
|
1440
|
-
|
|
1468
|
+
let i = value[1];
|
|
1469
|
+
if (typeof i !== "number") {
|
|
1470
|
+
i = values.push(value[1]) - 1;
|
|
1471
|
+
}
|
|
1472
|
+
hydrating ??= /* @__PURE__ */ new Set();
|
|
1473
|
+
if (hydrating.has(i)) {
|
|
1474
|
+
throw new Error("Invalid circular reference");
|
|
1475
|
+
}
|
|
1476
|
+
hydrating.add(i);
|
|
1477
|
+
hydrated[index] = reviver(hydrate(i));
|
|
1478
|
+
hydrating.delete(i);
|
|
1479
|
+
return hydrated[index];
|
|
1441
1480
|
}
|
|
1442
1481
|
switch (type) {
|
|
1443
1482
|
case "Date":
|
|
@@ -1484,13 +1523,20 @@ function unflatten(parsed, revivers) {
|
|
|
1484
1523
|
case "Float64Array":
|
|
1485
1524
|
case "BigInt64Array":
|
|
1486
1525
|
case "BigUint64Array": {
|
|
1526
|
+
if (values[value[1]][0] !== "ArrayBuffer") {
|
|
1527
|
+
throw new Error("Invalid data");
|
|
1528
|
+
}
|
|
1487
1529
|
const TypedArrayConstructor = globalThis[type];
|
|
1488
|
-
const
|
|
1530
|
+
const buffer = hydrate(value[1]);
|
|
1531
|
+
const typedArray = new TypedArrayConstructor(buffer);
|
|
1489
1532
|
hydrated[index] = value[2] !== void 0 ? typedArray.subarray(value[2], value[3]) : typedArray;
|
|
1490
1533
|
break;
|
|
1491
1534
|
}
|
|
1492
1535
|
case "ArrayBuffer": {
|
|
1493
1536
|
const base64 = value[1];
|
|
1537
|
+
if (typeof base64 !== "string") {
|
|
1538
|
+
throw new Error("Invalid ArrayBuffer encoding");
|
|
1539
|
+
}
|
|
1494
1540
|
const arraybuffer = decode64(base64);
|
|
1495
1541
|
hydrated[index] = arraybuffer;
|
|
1496
1542
|
break;
|
|
@@ -1520,6 +1566,14 @@ function unflatten(parsed, revivers) {
|
|
|
1520
1566
|
default:
|
|
1521
1567
|
throw new Error(`Unknown type ${type}`);
|
|
1522
1568
|
}
|
|
1569
|
+
} else if (value[0] === SPARSE) {
|
|
1570
|
+
const len = value[1];
|
|
1571
|
+
const array = new Array(len);
|
|
1572
|
+
hydrated[index] = array;
|
|
1573
|
+
for (let i = 2; i < value.length; i += 2) {
|
|
1574
|
+
const idx = value[i];
|
|
1575
|
+
array[idx] = hydrate(value[i + 1]);
|
|
1576
|
+
}
|
|
1523
1577
|
} else {
|
|
1524
1578
|
const array = new Array(value.length);
|
|
1525
1579
|
hydrated[index] = array;
|
|
@@ -1532,7 +1586,7 @@ function unflatten(parsed, revivers) {
|
|
|
1532
1586
|
} else {
|
|
1533
1587
|
const object = {};
|
|
1534
1588
|
hydrated[index] = object;
|
|
1535
|
-
for (const key
|
|
1589
|
+
for (const key of Object.keys(value)) {
|
|
1536
1590
|
if (key === "__proto__") {
|
|
1537
1591
|
throw new Error("Cannot parse an object with a `__proto__` property");
|
|
1538
1592
|
}
|
|
@@ -1545,7 +1599,7 @@ function unflatten(parsed, revivers) {
|
|
|
1545
1599
|
return hydrate(0);
|
|
1546
1600
|
}
|
|
1547
1601
|
|
|
1548
|
-
// ../../node_modules/.pnpm/devalue@5.3
|
|
1602
|
+
// ../../node_modules/.pnpm/devalue@5.6.3/node_modules/devalue/src/stringify.js
|
|
1549
1603
|
init_define_VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES();
|
|
1550
1604
|
function stringify(value, reducers) {
|
|
1551
1605
|
const stringified = [];
|
|
@@ -1559,9 +1613,6 @@ function stringify(value, reducers) {
|
|
|
1559
1613
|
const keys = [];
|
|
1560
1614
|
let p = 0;
|
|
1561
1615
|
function flatten(thing) {
|
|
1562
|
-
if (typeof thing === "function") {
|
|
1563
|
-
throw new DevalueError(`Cannot stringify a function`, keys);
|
|
1564
|
-
}
|
|
1565
1616
|
if (thing === void 0) return UNDEFINED;
|
|
1566
1617
|
if (Number.isNaN(thing)) return NAN;
|
|
1567
1618
|
if (thing === Infinity) return POSITIVE_INFINITY;
|
|
@@ -1577,6 +1628,9 @@ function stringify(value, reducers) {
|
|
|
1577
1628
|
return index2;
|
|
1578
1629
|
}
|
|
1579
1630
|
}
|
|
1631
|
+
if (typeof thing === "function") {
|
|
1632
|
+
throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
|
|
1633
|
+
}
|
|
1580
1634
|
let str = "";
|
|
1581
1635
|
if (is_primitive(thing)) {
|
|
1582
1636
|
str = stringify_primitive(thing);
|
|
@@ -1605,20 +1659,44 @@ function stringify(value, reducers) {
|
|
|
1605
1659
|
const { source, flags } = thing;
|
|
1606
1660
|
str = flags ? `["RegExp",${stringify_string(source)},"${flags}"]` : `["RegExp",${stringify_string(source)}]`;
|
|
1607
1661
|
break;
|
|
1608
|
-
case "Array":
|
|
1662
|
+
case "Array": {
|
|
1663
|
+
let mostly_dense = false;
|
|
1609
1664
|
str = "[";
|
|
1610
1665
|
for (let i = 0; i < thing.length; i += 1) {
|
|
1611
1666
|
if (i > 0) str += ",";
|
|
1612
|
-
if (i
|
|
1667
|
+
if (Object.hasOwn(thing, i)) {
|
|
1613
1668
|
keys.push(`[${i}]`);
|
|
1614
1669
|
str += flatten(thing[i]);
|
|
1615
1670
|
keys.pop();
|
|
1616
|
-
} else {
|
|
1671
|
+
} else if (mostly_dense) {
|
|
1617
1672
|
str += HOLE;
|
|
1673
|
+
} else {
|
|
1674
|
+
const populated_keys = valid_array_indices(
|
|
1675
|
+
/** @type {any[]} */
|
|
1676
|
+
thing
|
|
1677
|
+
);
|
|
1678
|
+
const population = populated_keys.length;
|
|
1679
|
+
const d = String(thing.length).length;
|
|
1680
|
+
const hole_cost = (thing.length - population) * 3;
|
|
1681
|
+
const sparse_cost = 4 + d + population * (d + 1);
|
|
1682
|
+
if (hole_cost > sparse_cost) {
|
|
1683
|
+
str = "[" + SPARSE + "," + thing.length;
|
|
1684
|
+
for (let j = 0; j < populated_keys.length; j++) {
|
|
1685
|
+
const key = populated_keys[j];
|
|
1686
|
+
keys.push(`[${key}]`);
|
|
1687
|
+
str += "," + key + "," + flatten(thing[key]);
|
|
1688
|
+
keys.pop();
|
|
1689
|
+
}
|
|
1690
|
+
break;
|
|
1691
|
+
} else {
|
|
1692
|
+
mostly_dense = true;
|
|
1693
|
+
str += HOLE;
|
|
1694
|
+
}
|
|
1618
1695
|
}
|
|
1619
1696
|
}
|
|
1620
1697
|
str += "]";
|
|
1621
1698
|
break;
|
|
1699
|
+
}
|
|
1622
1700
|
case "Set":
|
|
1623
1701
|
str = '["Set"';
|
|
1624
1702
|
for (const value2 of thing) {
|
|
@@ -1679,18 +1757,30 @@ function stringify(value, reducers) {
|
|
|
1679
1757
|
if (!is_plain_object(thing)) {
|
|
1680
1758
|
throw new DevalueError(
|
|
1681
1759
|
`Cannot stringify arbitrary non-POJOs`,
|
|
1682
|
-
keys
|
|
1760
|
+
keys,
|
|
1761
|
+
thing,
|
|
1762
|
+
value
|
|
1683
1763
|
);
|
|
1684
1764
|
}
|
|
1685
1765
|
if (enumerable_symbols(thing).length > 0) {
|
|
1686
1766
|
throw new DevalueError(
|
|
1687
1767
|
`Cannot stringify POJOs with symbolic keys`,
|
|
1688
|
-
keys
|
|
1768
|
+
keys,
|
|
1769
|
+
thing,
|
|
1770
|
+
value
|
|
1689
1771
|
);
|
|
1690
1772
|
}
|
|
1691
1773
|
if (Object.getPrototypeOf(thing) === null) {
|
|
1692
1774
|
str = '["null"';
|
|
1693
|
-
for (const key
|
|
1775
|
+
for (const key of Object.keys(thing)) {
|
|
1776
|
+
if (key === "__proto__") {
|
|
1777
|
+
throw new DevalueError(
|
|
1778
|
+
`Cannot stringify objects with __proto__ keys`,
|
|
1779
|
+
keys,
|
|
1780
|
+
thing,
|
|
1781
|
+
value
|
|
1782
|
+
);
|
|
1783
|
+
}
|
|
1694
1784
|
keys.push(stringify_key(key));
|
|
1695
1785
|
str += `,${stringify_string(key)},${flatten(thing[key])}`;
|
|
1696
1786
|
keys.pop();
|
|
@@ -1699,7 +1789,15 @@ function stringify(value, reducers) {
|
|
|
1699
1789
|
} else {
|
|
1700
1790
|
str = "{";
|
|
1701
1791
|
let started = false;
|
|
1702
|
-
for (const key
|
|
1792
|
+
for (const key of Object.keys(thing)) {
|
|
1793
|
+
if (key === "__proto__") {
|
|
1794
|
+
throw new DevalueError(
|
|
1795
|
+
`Cannot stringify objects with __proto__ keys`,
|
|
1796
|
+
keys,
|
|
1797
|
+
thing,
|
|
1798
|
+
value
|
|
1799
|
+
);
|
|
1800
|
+
}
|
|
1703
1801
|
if (started) str += ",";
|
|
1704
1802
|
started = true;
|
|
1705
1803
|
keys.push(stringify_key(key));
|