@irtio/testing 3.1.1 → 4.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/dist/{chunk-47O3HZBE.js → chunk-LQ5TGD2E.js} +24 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -1
- package/dist/matchers.js +1 -1
- package/package.json +7 -7
|
@@ -247,6 +247,7 @@ var DROPPABLE = /* @__PURE__ */ new Set([
|
|
|
247
247
|
]);
|
|
248
248
|
var MICROTASK_TURNS = 8;
|
|
249
249
|
var SETTLE_ROUNDS = 64;
|
|
250
|
+
var RUN_HOPS_MAX = 1e4;
|
|
250
251
|
var JOIN_TIMEOUT_MS = 3e4;
|
|
251
252
|
var HELD_FRAMES_MAX = 16;
|
|
252
253
|
var DROPPED_HELD = new Uint8Array(0);
|
|
@@ -976,8 +977,30 @@ var TestHarness = class {
|
|
|
976
977
|
await this.settle();
|
|
977
978
|
}
|
|
978
979
|
}
|
|
980
|
+
/**
|
|
981
|
+
* Bug #127: one `clock.advance(ms)` would fire every timer in the window, but a script parked on
|
|
982
|
+
* `await npc.wait(50)` only resumes in a **microtask**, which cannot run until `advance` has
|
|
983
|
+
* returned — so the script's next timer was armed after the window had already gone by and a
|
|
984
|
+
* 1000 ms run took the script exactly one step. So hop instead of leaping: advance to the next
|
|
985
|
+
* due timer, let microtasks drain (continuations run, new timers get armed), and repeat until
|
|
986
|
+
* the target. With nothing armed it is still a single leap.
|
|
987
|
+
*/
|
|
979
988
|
async run(ms) {
|
|
980
|
-
this.clock.
|
|
989
|
+
const target = this.clock.now() + Math.max(0, ms);
|
|
990
|
+
for (let hops = 0; ; hops++) {
|
|
991
|
+
if (hops > RUN_HOPS_MAX) {
|
|
992
|
+
throw new Error(
|
|
993
|
+
`testRoom: t.run(${ms}) did not settle \u2014 more than ${RUN_HOPS_MAX} timers came due, which usually means a timer re-arms itself at the same fake time`
|
|
994
|
+
);
|
|
995
|
+
}
|
|
996
|
+
const due = this.clock.nextDueAt();
|
|
997
|
+
if (due === void 0 || due > target) {
|
|
998
|
+
this.clock.advance(target - this.clock.now());
|
|
999
|
+
break;
|
|
1000
|
+
}
|
|
1001
|
+
this.clock.advance(Math.max(0, due - this.clock.now()));
|
|
1002
|
+
await microtasks();
|
|
1003
|
+
}
|
|
981
1004
|
await this.settle();
|
|
982
1005
|
}
|
|
983
1006
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -566,6 +566,14 @@ declare class TestHarness<S extends AnySchema> implements TestRoom<S> {
|
|
|
566
566
|
*/
|
|
567
567
|
private reportHandlerErrors;
|
|
568
568
|
tick(n?: number): Promise<void>;
|
|
569
|
+
/**
|
|
570
|
+
* Bug #127: one `clock.advance(ms)` would fire every timer in the window, but a script parked on
|
|
571
|
+
* `await npc.wait(50)` only resumes in a **microtask**, which cannot run until `advance` has
|
|
572
|
+
* returned — so the script's next timer was armed after the window had already gone by and a
|
|
573
|
+
* 1000 ms run took the script exactly one step. So hop instead of leaping: advance to the next
|
|
574
|
+
* due timer, let microtasks drain (continuations run, new timers get armed), and repeat until
|
|
575
|
+
* the target. With nothing armed it is still a single leap.
|
|
576
|
+
*/
|
|
569
577
|
run(ms: number): Promise<void>;
|
|
570
578
|
/**
|
|
571
579
|
* Advances until `pred()` holds. In **event mode** a tick is a zero-length clock step, so this
|
package/dist/index.js
CHANGED
package/dist/matchers.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@irtio/testing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "irtio's blessed test API: testRoom() in-process rooms with real client semantics, plus Vitest matchers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@irtio/bots": "
|
|
32
|
-
"@irtio/client": "
|
|
33
|
-
"@irtio/protocol": "
|
|
34
|
-
"@irtio/runtime": "
|
|
35
|
-
"@irtio/schema": "
|
|
36
|
-
"@irtio/server": "
|
|
31
|
+
"@irtio/bots": "^4.0.0",
|
|
32
|
+
"@irtio/client": "^4.0.0",
|
|
33
|
+
"@irtio/protocol": "^4.0.0",
|
|
34
|
+
"@irtio/runtime": "^4.0.0",
|
|
35
|
+
"@irtio/schema": "^4.0.0",
|
|
36
|
+
"@irtio/server": "^4.0.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"vitest": ">=3"
|