@flare-engine/testing 0.4.6 → 0.4.7
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/index.d.mts +9 -21
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +9 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { SeededRNG } from "@flare-engine/math";
|
|
|
2
2
|
import { InputManager } from "@flare-engine/input";
|
|
3
3
|
import { GameLoop } from "@flare-engine/core";
|
|
4
4
|
import { ComponentDef, World } from "@flare-engine/ecs";
|
|
5
|
-
//#region src/bench-session.d.ts
|
|
6
5
|
interface BenchSessionOptions {
|
|
7
6
|
seed?: number;
|
|
8
7
|
}
|
|
@@ -22,9 +21,7 @@ interface BenchSession {
|
|
|
22
21
|
* Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally
|
|
23
22
|
* so a throw between install and end() cannot leak the patched Math.random.
|
|
24
23
|
*/
|
|
25
|
-
declare function createBenchSession(opts?: BenchSessionOptions): BenchSession;
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/define-snapshot.d.ts
|
|
24
|
+
export declare function createBenchSession(opts?: BenchSessionOptions): BenchSession;
|
|
28
25
|
interface SnapshotProjector {
|
|
29
26
|
readonly query: readonly ComponentDef<unknown>[];
|
|
30
27
|
project(world: World, id: number): unknown;
|
|
@@ -32,9 +29,7 @@ interface SnapshotProjector {
|
|
|
32
29
|
interface SnapshotSchema {
|
|
33
30
|
readonly [key: string]: SnapshotProjector;
|
|
34
31
|
}
|
|
35
|
-
declare function defineSnapshot<S extends SnapshotSchema>(schema: S): (world: World) => { readonly [K in keyof S]: readonly unknown[]; };
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/fake-clock.d.ts
|
|
32
|
+
export declare function defineSnapshot<S extends SnapshotSchema>(schema: S): (world: World) => { readonly [K in keyof S]: readonly unknown[]; };
|
|
38
33
|
/**
|
|
39
34
|
* Fake monotonic clock for driving `GameLoop` deterministically in tests.
|
|
40
35
|
*
|
|
@@ -57,15 +52,13 @@ interface FakeClock {
|
|
|
57
52
|
/** Reset time and cancel all pending callbacks. */
|
|
58
53
|
reset(): void;
|
|
59
54
|
}
|
|
60
|
-
declare function createFakeClock(): FakeClock;
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/mock-input.d.ts
|
|
55
|
+
export declare function createFakeClock(): FakeClock;
|
|
63
56
|
/**
|
|
64
57
|
* `InputManager` subclass with scripted helpers for tests. Drives the same
|
|
65
58
|
* internal state the real manager uses, so any system reading
|
|
66
59
|
* `.pointer` / `.touches` sees identical data.
|
|
67
60
|
*/
|
|
68
|
-
declare class MockInputManager extends InputManager {
|
|
61
|
+
export declare class MockInputManager extends InputManager {
|
|
69
62
|
/** Press a pointer at `(x, y)`. `id` defaults to 0 (primary). */
|
|
70
63
|
press(x: number, y: number, id?: number): void;
|
|
71
64
|
/** Move a pointer to `(x, y)`. */
|
|
@@ -75,9 +68,7 @@ declare class MockInputManager extends InputManager {
|
|
|
75
68
|
/** Full tap: press → release in one call. */
|
|
76
69
|
tap(x: number, y: number, id?: number): void;
|
|
77
70
|
}
|
|
78
|
-
declare function createMockInputManager(): MockInputManager;
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region src/scene-snapshot.d.ts
|
|
71
|
+
export declare function createMockInputManager(): MockInputManager;
|
|
81
72
|
/**
|
|
82
73
|
* A single entity in a snapshot. Component names come from `ComponentDef.name`.
|
|
83
74
|
*/
|
|
@@ -93,14 +84,12 @@ interface SceneSnapshot {
|
|
|
93
84
|
* a stable, deterministic snapshot. Entities are sorted by id; component keys
|
|
94
85
|
* are inserted in the order the components are passed.
|
|
95
86
|
*/
|
|
96
|
-
declare function serializeScene(world: World, components: readonly ComponentDef<unknown>[]): SceneSnapshot;
|
|
87
|
+
export declare function serializeScene(world: World, components: readonly ComponentDef<unknown>[]): SceneSnapshot;
|
|
97
88
|
/**
|
|
98
89
|
* Deep-equal comparison good enough for snapshot assertions. Compares plain
|
|
99
90
|
* objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.
|
|
100
91
|
*/
|
|
101
|
-
declare function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean;
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/test-world.d.ts
|
|
92
|
+
export declare function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean;
|
|
104
93
|
interface TestWorld {
|
|
105
94
|
/** ECS world. */
|
|
106
95
|
readonly world: World;
|
|
@@ -125,7 +114,6 @@ interface CreateTestWorldOptions {
|
|
|
125
114
|
* updates fire for the exact dt you pass, without needing to start the rAF
|
|
126
115
|
* loop.
|
|
127
116
|
*/
|
|
128
|
-
declare function createTestWorld(options?: CreateTestWorldOptions): TestWorld;
|
|
129
|
-
|
|
130
|
-
export { type BenchSession, type BenchSessionOptions, type CreateTestWorldOptions, type FakeClock, MockInputManager, type SceneSnapshot, type SceneSnapshotEntity, type SnapshotProjector, type SnapshotSchema, type TestWorld, createBenchSession, createFakeClock, createMockInputManager, createTestWorld, defineSnapshot, serializeScene, snapshotsEqual };
|
|
117
|
+
export declare function createTestWorld(options?: CreateTestWorldOptions): TestWorld;
|
|
118
|
+
export type { BenchSession, BenchSessionOptions, CreateTestWorldOptions, FakeClock, SceneSnapshot, SceneSnapshotEntity, SnapshotProjector, SnapshotSchema, TestWorld };
|
|
131
119
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/scene-snapshot.ts","../src/test-world.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["SeededRNGType"],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/scene-snapshot.ts","../src/test-world.ts"],"mappings":";;;;UAGiB;EACf;;UAGe;WACN,KAAKA;EACd,QAAQ,cAAc;EACtB,QAAQ;;EAER;WACS,UAAU;;EAEnB;;;;;;;;wBASc,mBAAmB,OAAM,sBAA2B;UCtBnD;WACN,gBAAgB;EACzB,QAAQ,OAAO,OAAO;;UAGP;YACL,cAAc;;wBAGV,eAAe,UAAU,gBACvC,QAAQ,KACN,OAAO,sBAAsB,WAAW;;;;;;;;;;;UCH3B;;WAEN;;EAET,aAAa,WAAW;;EAExB,YAAY;;EAEZ,QAAQ;;EAER;;wBAGc,mBAAmB;;;;;;qBChBtB,yBAAyB;;EAEpC,MAAM,WAAW,WAAW;;EAI5B,KAAK,WAAW,WAAW;;EAI3B,QAAQ,WAAW,WAAW;;EAI9B,IAAI,WAAW,WAAW;;wBAMZ,0BAA0B;;;;UCDzB;EACf;EACA,YAAY;;UAGG;EACf,UAAU;;;;;;;wBAQI,eACd,OAAO,OACP,qBAAqB,0BACpB;;;;;wBAyBa,eAAe,GAAG,eAAe,GAAG;UChEnC;;WAEN,OAAO;;WAEP,MAAM;;WAEN,OAAO;;EAEhB,KAAK;;EAEL,WAAW,gBAAgB;;UAGZ;;EAEf;;EAEA;;;;;;;;wBASc,gBAAgB,UAAS,yBAA8B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { SeededRNG } from "@flare-engine/math";
|
|
|
2
2
|
import { ComponentDef, World } from "@flare-engine/ecs";
|
|
3
3
|
import { InputManager } from "@flare-engine/input";
|
|
4
4
|
import { GameLoop } from "@flare-engine/core";
|
|
5
|
-
//#region src/bench-session.d.ts
|
|
6
5
|
interface BenchSessionOptions {
|
|
7
6
|
seed?: number;
|
|
8
7
|
}
|
|
@@ -22,9 +21,7 @@ interface BenchSession {
|
|
|
22
21
|
* Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally
|
|
23
22
|
* so a throw between install and end() cannot leak the patched Math.random.
|
|
24
23
|
*/
|
|
25
|
-
declare function createBenchSession(opts?: BenchSessionOptions): BenchSession;
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/define-snapshot.d.ts
|
|
24
|
+
export declare function createBenchSession(opts?: BenchSessionOptions): BenchSession;
|
|
28
25
|
interface SnapshotProjector {
|
|
29
26
|
readonly query: readonly ComponentDef<unknown>[];
|
|
30
27
|
project(world: World, id: number): unknown;
|
|
@@ -32,9 +29,7 @@ interface SnapshotProjector {
|
|
|
32
29
|
interface SnapshotSchema {
|
|
33
30
|
readonly [key: string]: SnapshotProjector;
|
|
34
31
|
}
|
|
35
|
-
declare function defineSnapshot<S extends SnapshotSchema>(schema: S): (world: World) => { readonly [K in keyof S]: readonly unknown[]; };
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/fake-clock.d.ts
|
|
32
|
+
export declare function defineSnapshot<S extends SnapshotSchema>(schema: S): (world: World) => { readonly [K in keyof S]: readonly unknown[]; };
|
|
38
33
|
/**
|
|
39
34
|
* Fake monotonic clock for driving `GameLoop` deterministically in tests.
|
|
40
35
|
*
|
|
@@ -57,15 +52,13 @@ interface FakeClock {
|
|
|
57
52
|
/** Reset time and cancel all pending callbacks. */
|
|
58
53
|
reset(): void;
|
|
59
54
|
}
|
|
60
|
-
declare function createFakeClock(): FakeClock;
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/mock-input.d.ts
|
|
55
|
+
export declare function createFakeClock(): FakeClock;
|
|
63
56
|
/**
|
|
64
57
|
* `InputManager` subclass with scripted helpers for tests. Drives the same
|
|
65
58
|
* internal state the real manager uses, so any system reading
|
|
66
59
|
* `.pointer` / `.touches` sees identical data.
|
|
67
60
|
*/
|
|
68
|
-
declare class MockInputManager extends InputManager {
|
|
61
|
+
export declare class MockInputManager extends InputManager {
|
|
69
62
|
/** Press a pointer at `(x, y)`. `id` defaults to 0 (primary). */
|
|
70
63
|
press(x: number, y: number, id?: number): void;
|
|
71
64
|
/** Move a pointer to `(x, y)`. */
|
|
@@ -75,9 +68,7 @@ declare class MockInputManager extends InputManager {
|
|
|
75
68
|
/** Full tap: press → release in one call. */
|
|
76
69
|
tap(x: number, y: number, id?: number): void;
|
|
77
70
|
}
|
|
78
|
-
declare function createMockInputManager(): MockInputManager;
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region src/scene-snapshot.d.ts
|
|
71
|
+
export declare function createMockInputManager(): MockInputManager;
|
|
81
72
|
/**
|
|
82
73
|
* A single entity in a snapshot. Component names come from `ComponentDef.name`.
|
|
83
74
|
*/
|
|
@@ -93,14 +84,12 @@ interface SceneSnapshot {
|
|
|
93
84
|
* a stable, deterministic snapshot. Entities are sorted by id; component keys
|
|
94
85
|
* are inserted in the order the components are passed.
|
|
95
86
|
*/
|
|
96
|
-
declare function serializeScene(world: World, components: readonly ComponentDef<unknown>[]): SceneSnapshot;
|
|
87
|
+
export declare function serializeScene(world: World, components: readonly ComponentDef<unknown>[]): SceneSnapshot;
|
|
97
88
|
/**
|
|
98
89
|
* Deep-equal comparison good enough for snapshot assertions. Compares plain
|
|
99
90
|
* objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.
|
|
100
91
|
*/
|
|
101
|
-
declare function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean;
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/test-world.d.ts
|
|
92
|
+
export declare function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean;
|
|
104
93
|
interface TestWorld {
|
|
105
94
|
/** ECS world. */
|
|
106
95
|
readonly world: World;
|
|
@@ -125,7 +114,6 @@ interface CreateTestWorldOptions {
|
|
|
125
114
|
* updates fire for the exact dt you pass, without needing to start the rAF
|
|
126
115
|
* loop.
|
|
127
116
|
*/
|
|
128
|
-
declare function createTestWorld(options?: CreateTestWorldOptions): TestWorld;
|
|
129
|
-
|
|
130
|
-
export { type BenchSession, type BenchSessionOptions, type CreateTestWorldOptions, type FakeClock, MockInputManager, type SceneSnapshot, type SceneSnapshotEntity, type SnapshotProjector, type SnapshotSchema, type TestWorld, createBenchSession, createFakeClock, createMockInputManager, createTestWorld, defineSnapshot, serializeScene, snapshotsEqual };
|
|
117
|
+
export declare function createTestWorld(options?: CreateTestWorldOptions): TestWorld;
|
|
118
|
+
export type { BenchSession, BenchSessionOptions, CreateTestWorldOptions, FakeClock, SceneSnapshot, SceneSnapshotEntity, SnapshotProjector, SnapshotSchema, TestWorld };
|
|
131
119
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/scene-snapshot.ts","../src/test-world.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["SeededRNGType"],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/scene-snapshot.ts","../src/test-world.ts"],"mappings":";;;;UAGiB;EACf;;UAGe;WACN,KAAKA;EACd,QAAQ,cAAc;EACtB,QAAQ;;EAER;WACS,UAAU;;EAEnB;;;;;;;;wBASc,mBAAmB,OAAM,sBAA2B;UCtBnD;WACN,gBAAgB;EACzB,QAAQ,OAAO,OAAO;;UAGP;YACL,cAAc;;wBAGV,eAAe,UAAU,gBACvC,QAAQ,KACN,OAAO,sBAAsB,WAAW;;;;;;;;;;;UCH3B;;WAEN;;EAET,aAAa,WAAW;;EAExB,YAAY;;EAEZ,QAAQ;;EAER;;wBAGc,mBAAmB;;;;;;qBChBtB,yBAAyB;;EAEpC,MAAM,WAAW,WAAW;;EAI5B,KAAK,WAAW,WAAW;;EAI3B,QAAQ,WAAW,WAAW;;EAI9B,IAAI,WAAW,WAAW;;wBAMZ,0BAA0B;;;;UCDzB;EACf;EACA,YAAY;;UAGG;EACf,UAAU;;;;;;;wBAQI,eACd,OAAO,OACP,qBAAqB,0BACpB;;;;;wBAyBa,eAAe,GAAG,eAAe,GAAG;UChEnC;;WAEN,OAAO;;WAEP,MAAM;;WAEN,OAAO;;EAEhB,KAAK;;EAEL,WAAW,gBAAgB;;UAGZ;;EAEf;;EAEA;;;;;;;;wBASc,gBAAgB,UAAS,yBAA8B"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ let _flare_engine_math = require("@flare-engine/math");
|
|
|
3
3
|
let _flare_engine_input = require("@flare-engine/input");
|
|
4
4
|
let _flare_engine_core = require("@flare-engine/core");
|
|
5
5
|
let _flare_engine_ecs = require("@flare-engine/ecs");
|
|
6
|
-
|
|
6
|
+
// src/bench-session.ts
|
|
7
7
|
/**
|
|
8
8
|
* Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.
|
|
9
9
|
*
|
|
@@ -11,7 +11,8 @@ let _flare_engine_ecs = require("@flare-engine/ecs");
|
|
|
11
11
|
* so a throw between install and end() cannot leak the patched Math.random.
|
|
12
12
|
*/
|
|
13
13
|
function createBenchSession(opts = {}) {
|
|
14
|
-
const
|
|
14
|
+
const seed = opts.seed ?? 1;
|
|
15
|
+
const rng = new _flare_engine_math.SeededRNG(seed);
|
|
15
16
|
const originalRandom = Math.random;
|
|
16
17
|
const patched = () => rng.next();
|
|
17
18
|
Math.random = patched;
|
|
@@ -42,8 +43,7 @@ function createBenchSession(opts = {}) {
|
|
|
42
43
|
}
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
//#region src/define-snapshot.ts
|
|
46
|
+
// src/define-snapshot.ts
|
|
47
47
|
function defineSnapshot(schema) {
|
|
48
48
|
const cache = /* @__PURE__ */ new WeakMap();
|
|
49
49
|
const keys = Object.keys(schema);
|
|
@@ -69,8 +69,7 @@ function defineSnapshot(schema) {
|
|
|
69
69
|
return result;
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
//#region src/fake-clock.ts
|
|
72
|
+
// src/fake-clock.ts
|
|
74
73
|
function createFakeClock() {
|
|
75
74
|
let nowMs = 0;
|
|
76
75
|
let nextId = 1;
|
|
@@ -101,8 +100,7 @@ function createFakeClock() {
|
|
|
101
100
|
}
|
|
102
101
|
};
|
|
103
102
|
}
|
|
104
|
-
|
|
105
|
-
//#region src/mock-input.ts
|
|
103
|
+
// src/mock-input.ts
|
|
106
104
|
/**
|
|
107
105
|
* `InputManager` subclass with scripted helpers for tests. Drives the same
|
|
108
106
|
* internal state the real manager uses, so any system reading
|
|
@@ -130,8 +128,7 @@ var MockInputManager = class extends _flare_engine_input.InputManager {
|
|
|
130
128
|
function createMockInputManager() {
|
|
131
129
|
return new MockInputManager();
|
|
132
130
|
}
|
|
133
|
-
|
|
134
|
-
//#region src/scene-snapshot.ts
|
|
131
|
+
// src/scene-snapshot.ts
|
|
135
132
|
const singletonQueries = /* @__PURE__ */ new WeakMap();
|
|
136
133
|
function singletonQuery(world, def) {
|
|
137
134
|
let byComponent = singletonQueries.get(world);
|
|
@@ -196,8 +193,7 @@ function deepEqual(a, b) {
|
|
|
196
193
|
}
|
|
197
194
|
return false;
|
|
198
195
|
}
|
|
199
|
-
|
|
200
|
-
//#region src/test-world.ts
|
|
196
|
+
// src/test-world.ts
|
|
201
197
|
/**
|
|
202
198
|
* Create a World + GameLoop + FakeClock wired together for deterministic
|
|
203
199
|
* testing. `step()` calls the loop's `step()` directly so fixed and variable
|
|
@@ -222,7 +218,6 @@ function createTestWorld(options = {}) {
|
|
|
222
218
|
}
|
|
223
219
|
};
|
|
224
220
|
}
|
|
225
|
-
//#endregion
|
|
226
221
|
exports.MockInputManager = MockInputManager;
|
|
227
222
|
exports.createBenchSession = createBenchSession;
|
|
228
223
|
exports.createFakeClock = createFakeClock;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["SeededRNG","InputManager","World","GameLoop"],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/scene-snapshot.ts","../src/test-world.ts"],"sourcesContent":["import type { SeededRNG as SeededRNGType } from '@flare-engine/math';\nimport { SeededRNG } from '@flare-engine/math';\n\nexport interface BenchSessionOptions {\n seed?: number;\n}\n\nexport interface BenchSession {\n readonly rng: SeededRNGType;\n setFlag(name: string, value: boolean): void;\n getFlag(name: string): boolean;\n /** Resolves whenDone. Idempotent — safe to call multiple times. */\n done(): void;\n readonly whenDone: Promise<void>;\n /** Restores Math.random. Idempotent. */\n end(): void;\n}\n\n/**\n * Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.\n *\n * Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally\n * so a throw between install and end() cannot leak the patched Math.random.\n */\nexport function createBenchSession(opts: BenchSessionOptions = {}): BenchSession {\n const seed = opts.seed ?? 1;\n const rng = new SeededRNG(seed);\n\n const originalRandom = Math.random;\n const patched = () => rng.next();\n Math.random = patched;\n\n const flags: Record<string, boolean> = {};\n\n let resolve: (() => void) | null = null;\n const whenDone = new Promise<void>((res) => {\n resolve = res;\n });\n\n let doneResolved = false;\n\n return {\n rng,\n setFlag(name: string, value: boolean): void {\n flags[name] = value;\n },\n getFlag(name: string): boolean {\n return flags[name] ?? false;\n },\n done(): void {\n if (!doneResolved) {\n doneResolved = true;\n resolve?.();\n }\n },\n whenDone,\n end(): void {\n // Only restore when our own patch is still active — guards against\n // out-of-order end() clobbering a newer session's patch.\n if (Math.random === patched) {\n Math.random = originalRandom;\n } else {\n console.warn(\n \"[BenchSession] end() called out of order: Math.random is no longer this session's patch. \" +\n 'Sessions must be ended in LIFO order; a seeded Math.random may have leaked into later tests.',\n );\n }\n },\n };\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\nexport interface SnapshotProjector {\n readonly query: readonly ComponentDef<unknown>[];\n project(world: World, id: number): unknown;\n}\n\nexport interface SnapshotSchema {\n readonly [key: string]: SnapshotProjector;\n}\n\nexport function defineSnapshot<S extends SnapshotSchema>(\n schema: S,\n): (world: World) => { readonly [K in keyof S]: readonly unknown[] } {\n // One Query[] per world; queries auto-update so reuse is correct.\n const cache = new WeakMap<World, Query[]>();\n const keys = Object.keys(schema);\n\n return (world: World) => {\n let queries = cache.get(world);\n if (queries === undefined) {\n queries = keys.map((key) => {\n const projector = schema[key]!;\n return world.query(...(projector.query as ComponentDef<unknown>[]));\n });\n cache.set(world, queries);\n }\n\n const result: Record<string, readonly unknown[]> = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!;\n const projector = schema[key]!;\n const q = queries[i]!;\n const ids: number[] = [];\n for (const id of q) {\n ids.push(id);\n }\n ids.sort((a, b) => a - b);\n result[key] = ids.map((id) => projector.project(world, id));\n }\n return result as { readonly [K in keyof S]: readonly unknown[] };\n };\n}\n","/**\n * Fake monotonic clock for driving `GameLoop` deterministically in tests.\n *\n * Usage:\n * const fake = createFakeClock();\n * loop.tick = fake.requestFrame;\n * loop.cancelTick = fake.cancelFrame;\n * loop.start();\n * fake.advance(1 / 60); // runs one frame\n */\nexport interface FakeClock {\n /** Current fake timestamp in milliseconds. */\n readonly now: number;\n /** rAF-compatible request — stores the callback for the next `advance`. */\n requestFrame(callback: (time: number) => void): number;\n /** rAF-compatible cancel. */\n cancelFrame(id: number): void;\n /** Advance time by `seconds` and fire every pending callback once. */\n advance(seconds: number): void;\n /** Reset time and cancel all pending callbacks. */\n reset(): void;\n}\n\nexport function createFakeClock(): FakeClock {\n let nowMs = 0;\n let nextId = 1;\n const pending = new Map<number, (time: number) => void>();\n\n const clock: FakeClock = {\n get now() {\n return nowMs;\n },\n requestFrame(callback) {\n const id = nextId++;\n pending.set(id, callback);\n return id;\n },\n cancelFrame(id) {\n pending.delete(id);\n },\n advance(seconds) {\n if (seconds < 0) throw new Error('[@flare-engine/testing] cannot advance backwards');\n nowMs += seconds * 1000;\n // Snapshot callbacks so any newly scheduled ones via requestFrame during\n // this flush are deferred to the next advance — mirrors rAF semantics.\n const snapshot = [...pending.entries()];\n pending.clear();\n for (const [, cb] of snapshot) cb(nowMs);\n },\n reset() {\n nowMs = 0;\n pending.clear();\n nextId = 1;\n },\n };\n return clock;\n}\n","import { InputManager } from '@flare-engine/input';\n\n/**\n * `InputManager` subclass with scripted helpers for tests. Drives the same\n * internal state the real manager uses, so any system reading\n * `.pointer` / `.touches` sees identical data.\n */\nexport class MockInputManager extends InputManager {\n /** Press a pointer at `(x, y)`. `id` defaults to 0 (primary). */\n press(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n }\n /** Move a pointer to `(x, y)`. */\n move(x: number, y: number, id = 0): void {\n this.onPointerMove(id, x, y);\n }\n /** Release a pointer at `(x, y)`. */\n release(x: number, y: number, id = 0): void {\n this.onPointerUp(id, x, y);\n }\n /** Full tap: press → release in one call. */\n tap(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n this.onPointerUp(id, x, y);\n }\n}\n\nexport function createMockInputManager(): MockInputManager {\n return new MockInputManager();\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\n// One singleton Query per (world, component), memoized so repeat serializeScene\n// calls reuse them instead of registering a fresh (leaked) query each call.\n// Queries auto-update, so reuse always reflects current world state. Bounded: at\n// most one query per distinct component per world, all released when the world is\n// garbage-collected (the WeakMap holds no strong ref beyond the world's lifetime).\nconst singletonQueries = new WeakMap<World, Map<number, Query>>();\n\nfunction singletonQuery(world: World, def: ComponentDef<unknown>): Query {\n let byComponent = singletonQueries.get(world);\n if (byComponent === undefined) {\n byComponent = new Map();\n singletonQueries.set(world, byComponent);\n }\n let q = byComponent.get(def.id);\n if (q === undefined) {\n q = world.query(def);\n byComponent.set(def.id, q);\n }\n return q;\n}\n\n/**\n * A single entity in a snapshot. Component names come from `ComponentDef.name`.\n */\nexport interface SceneSnapshotEntity {\n id: number;\n components: Record<string, unknown>;\n}\n\nexport interface SceneSnapshot {\n entities: SceneSnapshotEntity[];\n}\n\n/**\n * Serialize every entity that has at least one of the supplied components into\n * a stable, deterministic snapshot. Entities are sorted by id; component keys\n * are inserted in the order the components are passed.\n */\nexport function serializeScene(\n world: World,\n components: readonly ComponentDef<unknown>[],\n): SceneSnapshot {\n // Collect every entity that has ANY of the supplied components (union of the\n // per-component queries). A separate ALL query would be redundant — anything\n // matching ALL already matches each singleton.\n const ids = new Set<number>();\n for (const def of components) {\n for (const id of singletonQuery(world, def)) ids.add(id);\n }\n\n const sortedIds = [...ids].sort((a, b) => a - b);\n const entities: SceneSnapshotEntity[] = [];\n for (const id of sortedIds) {\n const comps: Record<string, unknown> = {};\n for (const def of components) {\n if (world.has(id, def)) comps[def.name] = world.get(id, def);\n }\n entities.push({ id, components: comps });\n }\n return { entities };\n}\n\n/**\n * Deep-equal comparison good enough for snapshot assertions. Compares plain\n * objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.\n */\nexport function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean {\n return deepEqual(a, b);\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== typeof b) return false;\n if (a === null || b === null) return false;\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (!deepEqual(a[i], b[i])) return false;\n }\n return true;\n }\n if (typeof a === 'object' && typeof b === 'object') {\n const ao = a as Record<string, unknown>;\n const bo = b as Record<string, unknown>;\n const ak = Object.keys(ao);\n const bk = Object.keys(bo);\n if (ak.length !== bk.length) return false;\n for (const k of ak) {\n if (!Object.hasOwn(bo, k)) return false;\n if (!deepEqual(ao[k], bo[k])) return false;\n }\n return true;\n }\n return false;\n}\n","import { GameLoop } from '@flare-engine/core';\nimport { World } from '@flare-engine/ecs';\nimport { createFakeClock, type FakeClock } from './fake-clock.js';\n\nexport interface TestWorld {\n /** ECS world. */\n readonly world: World;\n /** Game loop wired to a fake clock. */\n readonly loop: GameLoop;\n /** Fake clock driving the loop. */\n readonly clock: FakeClock;\n /** Advance one frame of `dt` seconds. Runs the loop's fixed + variable update. */\n step(dt: number): void;\n /** Advance `frames` frames of `dt` seconds each. */\n stepFrames(frames: number, dt?: number): void;\n}\n\nexport interface CreateTestWorldOptions {\n /** Fixed timestep passed to `GameLoop`. Defaults to 1/60. */\n fixedDt?: number;\n /** Maximum raw dt cap passed to `GameLoop`. Defaults to 0.25s. */\n maxDt?: number;\n}\n\n/**\n * Create a World + GameLoop + FakeClock wired together for deterministic\n * testing. `step()` calls the loop's `step()` directly so fixed and variable\n * updates fire for the exact dt you pass, without needing to start the rAF\n * loop.\n */\nexport function createTestWorld(options: CreateTestWorldOptions = {}): TestWorld {\n const world = new World();\n const loop = new GameLoop(options);\n const clock = createFakeClock();\n loop.tick = clock.requestFrame;\n loop.cancelTick = clock.cancelFrame;\n\n return {\n world,\n loop,\n clock,\n step(dt) {\n loop.step(dt);\n },\n stepFrames(frames, dt = 1 / 60) {\n for (let i = 0; i < frames; i++) loop.step(dt);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;AAwBA,SAAgB,mBAAmB,OAA4B,CAAC,GAAiB;CAE/E,MAAM,MAAM,IAAIA,mBAAAA,UADH,KAAK,QAAQ,CACI;CAE9B,MAAM,iBAAiB,KAAK;CAC5B,MAAM,gBAAgB,IAAI,KAAK;CAC/B,KAAK,SAAS;CAEd,MAAM,QAAiC,CAAC;CAExC,IAAI,UAA+B;CACnC,MAAM,WAAW,IAAI,SAAe,QAAQ;EAC1C,UAAU;CACZ,CAAC;CAED,IAAI,eAAe;CAEnB,OAAO;EACL;EACA,QAAQ,MAAc,OAAsB;GAC1C,MAAM,QAAQ;EAChB;EACA,QAAQ,MAAuB;GAC7B,OAAO,MAAM,SAAS;EACxB;EACA,OAAa;GACX,IAAI,CAAC,cAAc;IACjB,eAAe;IACf,UAAU;GACZ;EACF;EACA;EACA,MAAY;GAGV,IAAI,KAAK,WAAW,SAClB,KAAK,SAAS;QAEd,QAAQ,KACN,uLAEF;EAEJ;CACF;AACF;;;AC1DA,SAAgB,eAC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AAK,IAAI;GACP,KAAK,KAAK,EAAE;EACd;EACA,WAAW,QAAQ,KAAK,IAAI,IAAI;GAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK,KAAK,KAAK,EAAE;EAC/C;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["SeededRNG","InputManager","World","GameLoop"],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/scene-snapshot.ts","../src/test-world.ts"],"sourcesContent":["import type { SeededRNG as SeededRNGType } from '@flare-engine/math';\nimport { SeededRNG } from '@flare-engine/math';\n\nexport interface BenchSessionOptions {\n seed?: number;\n}\n\nexport interface BenchSession {\n readonly rng: SeededRNGType;\n setFlag(name: string, value: boolean): void;\n getFlag(name: string): boolean;\n /** Resolves whenDone. Idempotent — safe to call multiple times. */\n done(): void;\n readonly whenDone: Promise<void>;\n /** Restores Math.random. Idempotent. */\n end(): void;\n}\n\n/**\n * Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.\n *\n * Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally\n * so a throw between install and end() cannot leak the patched Math.random.\n */\nexport function createBenchSession(opts: BenchSessionOptions = {}): BenchSession {\n const seed = opts.seed ?? 1;\n const rng = new SeededRNG(seed);\n\n const originalRandom = Math.random;\n const patched = () => rng.next();\n Math.random = patched;\n\n const flags: Record<string, boolean> = {};\n\n let resolve: (() => void) | null = null;\n const whenDone = new Promise<void>((res) => {\n resolve = res;\n });\n\n let doneResolved = false;\n\n return {\n rng,\n setFlag(name: string, value: boolean): void {\n flags[name] = value;\n },\n getFlag(name: string): boolean {\n return flags[name] ?? false;\n },\n done(): void {\n if (!doneResolved) {\n doneResolved = true;\n resolve?.();\n }\n },\n whenDone,\n end(): void {\n // Only restore when our own patch is still active — guards against\n // out-of-order end() clobbering a newer session's patch.\n if (Math.random === patched) {\n Math.random = originalRandom;\n } else {\n console.warn(\n \"[BenchSession] end() called out of order: Math.random is no longer this session's patch. \" +\n 'Sessions must be ended in LIFO order; a seeded Math.random may have leaked into later tests.',\n );\n }\n },\n };\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\nexport interface SnapshotProjector {\n readonly query: readonly ComponentDef<unknown>[];\n project(world: World, id: number): unknown;\n}\n\nexport interface SnapshotSchema {\n readonly [key: string]: SnapshotProjector;\n}\n\nexport function defineSnapshot<S extends SnapshotSchema>(\n schema: S,\n): (world: World) => { readonly [K in keyof S]: readonly unknown[] } {\n // One Query[] per world; queries auto-update so reuse is correct.\n const cache = new WeakMap<World, Query[]>();\n const keys = Object.keys(schema);\n\n return (world: World) => {\n let queries = cache.get(world);\n if (queries === undefined) {\n queries = keys.map((key) => {\n const projector = schema[key]!;\n return world.query(...(projector.query as ComponentDef<unknown>[]));\n });\n cache.set(world, queries);\n }\n\n const result: Record<string, readonly unknown[]> = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!;\n const projector = schema[key]!;\n const q = queries[i]!;\n const ids: number[] = [];\n for (const id of q) {\n ids.push(id);\n }\n ids.sort((a, b) => a - b);\n result[key] = ids.map((id) => projector.project(world, id));\n }\n return result as { readonly [K in keyof S]: readonly unknown[] };\n };\n}\n","/**\n * Fake monotonic clock for driving `GameLoop` deterministically in tests.\n *\n * Usage:\n * const fake = createFakeClock();\n * loop.tick = fake.requestFrame;\n * loop.cancelTick = fake.cancelFrame;\n * loop.start();\n * fake.advance(1 / 60); // runs one frame\n */\nexport interface FakeClock {\n /** Current fake timestamp in milliseconds. */\n readonly now: number;\n /** rAF-compatible request — stores the callback for the next `advance`. */\n requestFrame(callback: (time: number) => void): number;\n /** rAF-compatible cancel. */\n cancelFrame(id: number): void;\n /** Advance time by `seconds` and fire every pending callback once. */\n advance(seconds: number): void;\n /** Reset time and cancel all pending callbacks. */\n reset(): void;\n}\n\nexport function createFakeClock(): FakeClock {\n let nowMs = 0;\n let nextId = 1;\n const pending = new Map<number, (time: number) => void>();\n\n const clock: FakeClock = {\n get now() {\n return nowMs;\n },\n requestFrame(callback) {\n const id = nextId++;\n pending.set(id, callback);\n return id;\n },\n cancelFrame(id) {\n pending.delete(id);\n },\n advance(seconds) {\n if (seconds < 0) throw new Error('[@flare-engine/testing] cannot advance backwards');\n nowMs += seconds * 1000;\n // Snapshot callbacks so any newly scheduled ones via requestFrame during\n // this flush are deferred to the next advance — mirrors rAF semantics.\n const snapshot = [...pending.entries()];\n pending.clear();\n for (const [, cb] of snapshot) cb(nowMs);\n },\n reset() {\n nowMs = 0;\n pending.clear();\n nextId = 1;\n },\n };\n return clock;\n}\n","import { InputManager } from '@flare-engine/input';\n\n/**\n * `InputManager` subclass with scripted helpers for tests. Drives the same\n * internal state the real manager uses, so any system reading\n * `.pointer` / `.touches` sees identical data.\n */\nexport class MockInputManager extends InputManager {\n /** Press a pointer at `(x, y)`. `id` defaults to 0 (primary). */\n press(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n }\n /** Move a pointer to `(x, y)`. */\n move(x: number, y: number, id = 0): void {\n this.onPointerMove(id, x, y);\n }\n /** Release a pointer at `(x, y)`. */\n release(x: number, y: number, id = 0): void {\n this.onPointerUp(id, x, y);\n }\n /** Full tap: press → release in one call. */\n tap(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n this.onPointerUp(id, x, y);\n }\n}\n\nexport function createMockInputManager(): MockInputManager {\n return new MockInputManager();\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\n// One singleton Query per (world, component), memoized so repeat serializeScene\n// calls reuse them instead of registering a fresh (leaked) query each call.\n// Queries auto-update, so reuse always reflects current world state. Bounded: at\n// most one query per distinct component per world, all released when the world is\n// garbage-collected (the WeakMap holds no strong ref beyond the world's lifetime).\nconst singletonQueries = new WeakMap<World, Map<number, Query>>();\n\nfunction singletonQuery(world: World, def: ComponentDef<unknown>): Query {\n let byComponent = singletonQueries.get(world);\n if (byComponent === undefined) {\n byComponent = new Map();\n singletonQueries.set(world, byComponent);\n }\n let q = byComponent.get(def.id);\n if (q === undefined) {\n q = world.query(def);\n byComponent.set(def.id, q);\n }\n return q;\n}\n\n/**\n * A single entity in a snapshot. Component names come from `ComponentDef.name`.\n */\nexport interface SceneSnapshotEntity {\n id: number;\n components: Record<string, unknown>;\n}\n\nexport interface SceneSnapshot {\n entities: SceneSnapshotEntity[];\n}\n\n/**\n * Serialize every entity that has at least one of the supplied components into\n * a stable, deterministic snapshot. Entities are sorted by id; component keys\n * are inserted in the order the components are passed.\n */\nexport function serializeScene(\n world: World,\n components: readonly ComponentDef<unknown>[],\n): SceneSnapshot {\n // Collect every entity that has ANY of the supplied components (union of the\n // per-component queries). A separate ALL query would be redundant — anything\n // matching ALL already matches each singleton.\n const ids = new Set<number>();\n for (const def of components) {\n for (const id of singletonQuery(world, def)) ids.add(id);\n }\n\n const sortedIds = [...ids].sort((a, b) => a - b);\n const entities: SceneSnapshotEntity[] = [];\n for (const id of sortedIds) {\n const comps: Record<string, unknown> = {};\n for (const def of components) {\n if (world.has(id, def)) comps[def.name] = world.get(id, def);\n }\n entities.push({ id, components: comps });\n }\n return { entities };\n}\n\n/**\n * Deep-equal comparison good enough for snapshot assertions. Compares plain\n * objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.\n */\nexport function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean {\n return deepEqual(a, b);\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== typeof b) return false;\n if (a === null || b === null) return false;\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (!deepEqual(a[i], b[i])) return false;\n }\n return true;\n }\n if (typeof a === 'object' && typeof b === 'object') {\n const ao = a as Record<string, unknown>;\n const bo = b as Record<string, unknown>;\n const ak = Object.keys(ao);\n const bk = Object.keys(bo);\n if (ak.length !== bk.length) return false;\n for (const k of ak) {\n if (!Object.hasOwn(bo, k)) return false;\n if (!deepEqual(ao[k], bo[k])) return false;\n }\n return true;\n }\n return false;\n}\n","import { GameLoop } from '@flare-engine/core';\nimport { World } from '@flare-engine/ecs';\nimport { createFakeClock, type FakeClock } from './fake-clock.js';\n\nexport interface TestWorld {\n /** ECS world. */\n readonly world: World;\n /** Game loop wired to a fake clock. */\n readonly loop: GameLoop;\n /** Fake clock driving the loop. */\n readonly clock: FakeClock;\n /** Advance one frame of `dt` seconds. Runs the loop's fixed + variable update. */\n step(dt: number): void;\n /** Advance `frames` frames of `dt` seconds each. */\n stepFrames(frames: number, dt?: number): void;\n}\n\nexport interface CreateTestWorldOptions {\n /** Fixed timestep passed to `GameLoop`. Defaults to 1/60. */\n fixedDt?: number;\n /** Maximum raw dt cap passed to `GameLoop`. Defaults to 0.25s. */\n maxDt?: number;\n}\n\n/**\n * Create a World + GameLoop + FakeClock wired together for deterministic\n * testing. `step()` calls the loop's `step()` directly so fixed and variable\n * updates fire for the exact dt you pass, without needing to start the rAF\n * loop.\n */\nexport function createTestWorld(options: CreateTestWorldOptions = {}): TestWorld {\n const world = new World();\n const loop = new GameLoop(options);\n const clock = createFakeClock();\n loop.tick = clock.requestFrame;\n loop.cancelTick = clock.cancelFrame;\n\n return {\n world,\n loop,\n clock,\n step(dt) {\n loop.step(dt);\n },\n stepFrames(frames, dt = 1 / 60) {\n for (let i = 0; i < frames; i++) loop.step(dt);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;AAwBA,SAAgB,mBAAmB,OAA4B,CAAC,GAAiB;CAC/E,MAAM,OAAO,KAAK,QAAQ;CAC1B,MAAM,MAAM,IAAIA,mBAAAA,UAAU,IAAI;CAE9B,MAAM,iBAAiB,KAAK;CAC5B,MAAM,gBAAgB,IAAI,KAAK;CAC/B,KAAK,SAAS;CAEd,MAAM,QAAiC,CAAC;CAExC,IAAI,UAA+B;CACnC,MAAM,WAAW,IAAI,SAAe,QAAQ;EAC1C,UAAU;CACZ,CAAC;CAED,IAAI,eAAe;CAEnB,OAAO;EACL;EAC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C;EACA,OAAO;CACT;CACA,OAAO;AACT;;;;;;;;AClEA,SAAgB,gBAAgB,UAAkC,CAAC,GAAc;CAC/E,MAAM,QAAQ,IAAIC,kBAAAA,MAAM;CACxB,MAAM,OAAO,IAAIC,mBAAAA,SAAS,OAAO;CACjC,MAAM,QAAQ,gBAAgB;CAC9B,KAAK,OAAO,MAAM;CAClB,KAAK,aAAa,MAAM;CAExB,OAAO;EACL;EACA;EACA;EACA,KAAK,IAAI;GACP,KAAK,KAAK,EAAE;EACd;EACA,WAAW,QAAQ,KAAK,IAAI,IAAI;GAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK,KAAK,KAAK,EAAE;EAC/C;CACF;AACF"}
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { SeededRNG } from "@flare-engine/math";
|
|
|
2
2
|
import { InputManager } from "@flare-engine/input";
|
|
3
3
|
import { GameLoop } from "@flare-engine/core";
|
|
4
4
|
import { World } from "@flare-engine/ecs";
|
|
5
|
-
|
|
5
|
+
// src/bench-session.ts
|
|
6
6
|
/**
|
|
7
7
|
* Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.
|
|
8
8
|
*
|
|
@@ -10,7 +10,8 @@ import { World } from "@flare-engine/ecs";
|
|
|
10
10
|
* so a throw between install and end() cannot leak the patched Math.random.
|
|
11
11
|
*/
|
|
12
12
|
function createBenchSession(opts = {}) {
|
|
13
|
-
const
|
|
13
|
+
const seed = opts.seed ?? 1;
|
|
14
|
+
const rng = new SeededRNG(seed);
|
|
14
15
|
const originalRandom = Math.random;
|
|
15
16
|
const patched = () => rng.next();
|
|
16
17
|
Math.random = patched;
|
|
@@ -41,8 +42,7 @@ function createBenchSession(opts = {}) {
|
|
|
41
42
|
}
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
//#region src/define-snapshot.ts
|
|
45
|
+
// src/define-snapshot.ts
|
|
46
46
|
function defineSnapshot(schema) {
|
|
47
47
|
const cache = /* @__PURE__ */ new WeakMap();
|
|
48
48
|
const keys = Object.keys(schema);
|
|
@@ -68,8 +68,7 @@ function defineSnapshot(schema) {
|
|
|
68
68
|
return result;
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
//#region src/fake-clock.ts
|
|
71
|
+
// src/fake-clock.ts
|
|
73
72
|
function createFakeClock() {
|
|
74
73
|
let nowMs = 0;
|
|
75
74
|
let nextId = 1;
|
|
@@ -100,8 +99,7 @@ function createFakeClock() {
|
|
|
100
99
|
}
|
|
101
100
|
};
|
|
102
101
|
}
|
|
103
|
-
|
|
104
|
-
//#region src/mock-input.ts
|
|
102
|
+
// src/mock-input.ts
|
|
105
103
|
/**
|
|
106
104
|
* `InputManager` subclass with scripted helpers for tests. Drives the same
|
|
107
105
|
* internal state the real manager uses, so any system reading
|
|
@@ -129,8 +127,7 @@ var MockInputManager = class extends InputManager {
|
|
|
129
127
|
function createMockInputManager() {
|
|
130
128
|
return new MockInputManager();
|
|
131
129
|
}
|
|
132
|
-
|
|
133
|
-
//#region src/scene-snapshot.ts
|
|
130
|
+
// src/scene-snapshot.ts
|
|
134
131
|
const singletonQueries = /* @__PURE__ */ new WeakMap();
|
|
135
132
|
function singletonQuery(world, def) {
|
|
136
133
|
let byComponent = singletonQueries.get(world);
|
|
@@ -195,8 +192,7 @@ function deepEqual(a, b) {
|
|
|
195
192
|
}
|
|
196
193
|
return false;
|
|
197
194
|
}
|
|
198
|
-
|
|
199
|
-
//#region src/test-world.ts
|
|
195
|
+
// src/test-world.ts
|
|
200
196
|
/**
|
|
201
197
|
* Create a World + GameLoop + FakeClock wired together for deterministic
|
|
202
198
|
* testing. `step()` calls the loop's `step()` directly so fixed and variable
|
|
@@ -221,7 +217,6 @@ function createTestWorld(options = {}) {
|
|
|
221
217
|
}
|
|
222
218
|
};
|
|
223
219
|
}
|
|
224
|
-
//#endregion
|
|
225
220
|
export { MockInputManager, createBenchSession, createFakeClock, createMockInputManager, createTestWorld, defineSnapshot, serializeScene, snapshotsEqual };
|
|
226
221
|
|
|
227
222
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/scene-snapshot.ts","../src/test-world.ts"],"sourcesContent":["import type { SeededRNG as SeededRNGType } from '@flare-engine/math';\nimport { SeededRNG } from '@flare-engine/math';\n\nexport interface BenchSessionOptions {\n seed?: number;\n}\n\nexport interface BenchSession {\n readonly rng: SeededRNGType;\n setFlag(name: string, value: boolean): void;\n getFlag(name: string): boolean;\n /** Resolves whenDone. Idempotent — safe to call multiple times. */\n done(): void;\n readonly whenDone: Promise<void>;\n /** Restores Math.random. Idempotent. */\n end(): void;\n}\n\n/**\n * Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.\n *\n * Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally\n * so a throw between install and end() cannot leak the patched Math.random.\n */\nexport function createBenchSession(opts: BenchSessionOptions = {}): BenchSession {\n const seed = opts.seed ?? 1;\n const rng = new SeededRNG(seed);\n\n const originalRandom = Math.random;\n const patched = () => rng.next();\n Math.random = patched;\n\n const flags: Record<string, boolean> = {};\n\n let resolve: (() => void) | null = null;\n const whenDone = new Promise<void>((res) => {\n resolve = res;\n });\n\n let doneResolved = false;\n\n return {\n rng,\n setFlag(name: string, value: boolean): void {\n flags[name] = value;\n },\n getFlag(name: string): boolean {\n return flags[name] ?? false;\n },\n done(): void {\n if (!doneResolved) {\n doneResolved = true;\n resolve?.();\n }\n },\n whenDone,\n end(): void {\n // Only restore when our own patch is still active — guards against\n // out-of-order end() clobbering a newer session's patch.\n if (Math.random === patched) {\n Math.random = originalRandom;\n } else {\n console.warn(\n \"[BenchSession] end() called out of order: Math.random is no longer this session's patch. \" +\n 'Sessions must be ended in LIFO order; a seeded Math.random may have leaked into later tests.',\n );\n }\n },\n };\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\nexport interface SnapshotProjector {\n readonly query: readonly ComponentDef<unknown>[];\n project(world: World, id: number): unknown;\n}\n\nexport interface SnapshotSchema {\n readonly [key: string]: SnapshotProjector;\n}\n\nexport function defineSnapshot<S extends SnapshotSchema>(\n schema: S,\n): (world: World) => { readonly [K in keyof S]: readonly unknown[] } {\n // One Query[] per world; queries auto-update so reuse is correct.\n const cache = new WeakMap<World, Query[]>();\n const keys = Object.keys(schema);\n\n return (world: World) => {\n let queries = cache.get(world);\n if (queries === undefined) {\n queries = keys.map((key) => {\n const projector = schema[key]!;\n return world.query(...(projector.query as ComponentDef<unknown>[]));\n });\n cache.set(world, queries);\n }\n\n const result: Record<string, readonly unknown[]> = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!;\n const projector = schema[key]!;\n const q = queries[i]!;\n const ids: number[] = [];\n for (const id of q) {\n ids.push(id);\n }\n ids.sort((a, b) => a - b);\n result[key] = ids.map((id) => projector.project(world, id));\n }\n return result as { readonly [K in keyof S]: readonly unknown[] };\n };\n}\n","/**\n * Fake monotonic clock for driving `GameLoop` deterministically in tests.\n *\n * Usage:\n * const fake = createFakeClock();\n * loop.tick = fake.requestFrame;\n * loop.cancelTick = fake.cancelFrame;\n * loop.start();\n * fake.advance(1 / 60); // runs one frame\n */\nexport interface FakeClock {\n /** Current fake timestamp in milliseconds. */\n readonly now: number;\n /** rAF-compatible request — stores the callback for the next `advance`. */\n requestFrame(callback: (time: number) => void): number;\n /** rAF-compatible cancel. */\n cancelFrame(id: number): void;\n /** Advance time by `seconds` and fire every pending callback once. */\n advance(seconds: number): void;\n /** Reset time and cancel all pending callbacks. */\n reset(): void;\n}\n\nexport function createFakeClock(): FakeClock {\n let nowMs = 0;\n let nextId = 1;\n const pending = new Map<number, (time: number) => void>();\n\n const clock: FakeClock = {\n get now() {\n return nowMs;\n },\n requestFrame(callback) {\n const id = nextId++;\n pending.set(id, callback);\n return id;\n },\n cancelFrame(id) {\n pending.delete(id);\n },\n advance(seconds) {\n if (seconds < 0) throw new Error('[@flare-engine/testing] cannot advance backwards');\n nowMs += seconds * 1000;\n // Snapshot callbacks so any newly scheduled ones via requestFrame during\n // this flush are deferred to the next advance — mirrors rAF semantics.\n const snapshot = [...pending.entries()];\n pending.clear();\n for (const [, cb] of snapshot) cb(nowMs);\n },\n reset() {\n nowMs = 0;\n pending.clear();\n nextId = 1;\n },\n };\n return clock;\n}\n","import { InputManager } from '@flare-engine/input';\n\n/**\n * `InputManager` subclass with scripted helpers for tests. Drives the same\n * internal state the real manager uses, so any system reading\n * `.pointer` / `.touches` sees identical data.\n */\nexport class MockInputManager extends InputManager {\n /** Press a pointer at `(x, y)`. `id` defaults to 0 (primary). */\n press(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n }\n /** Move a pointer to `(x, y)`. */\n move(x: number, y: number, id = 0): void {\n this.onPointerMove(id, x, y);\n }\n /** Release a pointer at `(x, y)`. */\n release(x: number, y: number, id = 0): void {\n this.onPointerUp(id, x, y);\n }\n /** Full tap: press → release in one call. */\n tap(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n this.onPointerUp(id, x, y);\n }\n}\n\nexport function createMockInputManager(): MockInputManager {\n return new MockInputManager();\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\n// One singleton Query per (world, component), memoized so repeat serializeScene\n// calls reuse them instead of registering a fresh (leaked) query each call.\n// Queries auto-update, so reuse always reflects current world state. Bounded: at\n// most one query per distinct component per world, all released when the world is\n// garbage-collected (the WeakMap holds no strong ref beyond the world's lifetime).\nconst singletonQueries = new WeakMap<World, Map<number, Query>>();\n\nfunction singletonQuery(world: World, def: ComponentDef<unknown>): Query {\n let byComponent = singletonQueries.get(world);\n if (byComponent === undefined) {\n byComponent = new Map();\n singletonQueries.set(world, byComponent);\n }\n let q = byComponent.get(def.id);\n if (q === undefined) {\n q = world.query(def);\n byComponent.set(def.id, q);\n }\n return q;\n}\n\n/**\n * A single entity in a snapshot. Component names come from `ComponentDef.name`.\n */\nexport interface SceneSnapshotEntity {\n id: number;\n components: Record<string, unknown>;\n}\n\nexport interface SceneSnapshot {\n entities: SceneSnapshotEntity[];\n}\n\n/**\n * Serialize every entity that has at least one of the supplied components into\n * a stable, deterministic snapshot. Entities are sorted by id; component keys\n * are inserted in the order the components are passed.\n */\nexport function serializeScene(\n world: World,\n components: readonly ComponentDef<unknown>[],\n): SceneSnapshot {\n // Collect every entity that has ANY of the supplied components (union of the\n // per-component queries). A separate ALL query would be redundant — anything\n // matching ALL already matches each singleton.\n const ids = new Set<number>();\n for (const def of components) {\n for (const id of singletonQuery(world, def)) ids.add(id);\n }\n\n const sortedIds = [...ids].sort((a, b) => a - b);\n const entities: SceneSnapshotEntity[] = [];\n for (const id of sortedIds) {\n const comps: Record<string, unknown> = {};\n for (const def of components) {\n if (world.has(id, def)) comps[def.name] = world.get(id, def);\n }\n entities.push({ id, components: comps });\n }\n return { entities };\n}\n\n/**\n * Deep-equal comparison good enough for snapshot assertions. Compares plain\n * objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.\n */\nexport function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean {\n return deepEqual(a, b);\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== typeof b) return false;\n if (a === null || b === null) return false;\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (!deepEqual(a[i], b[i])) return false;\n }\n return true;\n }\n if (typeof a === 'object' && typeof b === 'object') {\n const ao = a as Record<string, unknown>;\n const bo = b as Record<string, unknown>;\n const ak = Object.keys(ao);\n const bk = Object.keys(bo);\n if (ak.length !== bk.length) return false;\n for (const k of ak) {\n if (!Object.hasOwn(bo, k)) return false;\n if (!deepEqual(ao[k], bo[k])) return false;\n }\n return true;\n }\n return false;\n}\n","import { GameLoop } from '@flare-engine/core';\nimport { World } from '@flare-engine/ecs';\nimport { createFakeClock, type FakeClock } from './fake-clock.js';\n\nexport interface TestWorld {\n /** ECS world. */\n readonly world: World;\n /** Game loop wired to a fake clock. */\n readonly loop: GameLoop;\n /** Fake clock driving the loop. */\n readonly clock: FakeClock;\n /** Advance one frame of `dt` seconds. Runs the loop's fixed + variable update. */\n step(dt: number): void;\n /** Advance `frames` frames of `dt` seconds each. */\n stepFrames(frames: number, dt?: number): void;\n}\n\nexport interface CreateTestWorldOptions {\n /** Fixed timestep passed to `GameLoop`. Defaults to 1/60. */\n fixedDt?: number;\n /** Maximum raw dt cap passed to `GameLoop`. Defaults to 0.25s. */\n maxDt?: number;\n}\n\n/**\n * Create a World + GameLoop + FakeClock wired together for deterministic\n * testing. `step()` calls the loop's `step()` directly so fixed and variable\n * updates fire for the exact dt you pass, without needing to start the rAF\n * loop.\n */\nexport function createTestWorld(options: CreateTestWorldOptions = {}): TestWorld {\n const world = new World();\n const loop = new GameLoop(options);\n const clock = createFakeClock();\n loop.tick = clock.requestFrame;\n loop.cancelTick = clock.cancelFrame;\n\n return {\n world,\n loop,\n clock,\n step(dt) {\n loop.step(dt);\n },\n stepFrames(frames, dt = 1 / 60) {\n for (let i = 0; i < frames; i++) loop.step(dt);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;AAwBA,SAAgB,mBAAmB,OAA4B,CAAC,GAAiB;CAE/E,MAAM,MAAM,IAAI,UADH,KAAK,QAAQ,CACI;CAE9B,MAAM,iBAAiB,KAAK;CAC5B,MAAM,gBAAgB,IAAI,KAAK;CAC/B,KAAK,SAAS;CAEd,MAAM,QAAiC,CAAC;CAExC,IAAI,UAA+B;CACnC,MAAM,WAAW,IAAI,SAAe,QAAQ;EAC1C,UAAU;CACZ,CAAC;CAED,IAAI,eAAe;CAEnB,OAAO;EACL;EACA,QAAQ,MAAc,OAAsB;GAC1C,MAAM,QAAQ;EAChB;EACA,QAAQ,MAAuB;GAC7B,OAAO,MAAM,SAAS;EACxB;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IAAI,MAAM;CACxB,MAAM,OAAO,IAAI,SAAS,OAAO;CACjC,MAAM,QAAQ,gBAAgB;CAC9B,KAAK,OAAO,MAAM;CAClB,KAAK,aAAa,MAAM;CAExB,OAAO;EACL;EACA;EACA;EACA,KAAK,IAAI;GACP,KAAK,KAAK,EAAE;EACd;EACA,WAAW,QAAQ,KAAK,IAAI,IAAI;GAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK,KAAK,KAAK,EAAE;EAC/C;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/scene-snapshot.ts","../src/test-world.ts"],"sourcesContent":["import type { SeededRNG as SeededRNGType } from '@flare-engine/math';\nimport { SeededRNG } from '@flare-engine/math';\n\nexport interface BenchSessionOptions {\n seed?: number;\n}\n\nexport interface BenchSession {\n readonly rng: SeededRNGType;\n setFlag(name: string, value: boolean): void;\n getFlag(name: string): boolean;\n /** Resolves whenDone. Idempotent — safe to call multiple times. */\n done(): void;\n readonly whenDone: Promise<void>;\n /** Restores Math.random. Idempotent. */\n end(): void;\n}\n\n/**\n * Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.\n *\n * Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally\n * so a throw between install and end() cannot leak the patched Math.random.\n */\nexport function createBenchSession(opts: BenchSessionOptions = {}): BenchSession {\n const seed = opts.seed ?? 1;\n const rng = new SeededRNG(seed);\n\n const originalRandom = Math.random;\n const patched = () => rng.next();\n Math.random = patched;\n\n const flags: Record<string, boolean> = {};\n\n let resolve: (() => void) | null = null;\n const whenDone = new Promise<void>((res) => {\n resolve = res;\n });\n\n let doneResolved = false;\n\n return {\n rng,\n setFlag(name: string, value: boolean): void {\n flags[name] = value;\n },\n getFlag(name: string): boolean {\n return flags[name] ?? false;\n },\n done(): void {\n if (!doneResolved) {\n doneResolved = true;\n resolve?.();\n }\n },\n whenDone,\n end(): void {\n // Only restore when our own patch is still active — guards against\n // out-of-order end() clobbering a newer session's patch.\n if (Math.random === patched) {\n Math.random = originalRandom;\n } else {\n console.warn(\n \"[BenchSession] end() called out of order: Math.random is no longer this session's patch. \" +\n 'Sessions must be ended in LIFO order; a seeded Math.random may have leaked into later tests.',\n );\n }\n },\n };\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\nexport interface SnapshotProjector {\n readonly query: readonly ComponentDef<unknown>[];\n project(world: World, id: number): unknown;\n}\n\nexport interface SnapshotSchema {\n readonly [key: string]: SnapshotProjector;\n}\n\nexport function defineSnapshot<S extends SnapshotSchema>(\n schema: S,\n): (world: World) => { readonly [K in keyof S]: readonly unknown[] } {\n // One Query[] per world; queries auto-update so reuse is correct.\n const cache = new WeakMap<World, Query[]>();\n const keys = Object.keys(schema);\n\n return (world: World) => {\n let queries = cache.get(world);\n if (queries === undefined) {\n queries = keys.map((key) => {\n const projector = schema[key]!;\n return world.query(...(projector.query as ComponentDef<unknown>[]));\n });\n cache.set(world, queries);\n }\n\n const result: Record<string, readonly unknown[]> = {};\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!;\n const projector = schema[key]!;\n const q = queries[i]!;\n const ids: number[] = [];\n for (const id of q) {\n ids.push(id);\n }\n ids.sort((a, b) => a - b);\n result[key] = ids.map((id) => projector.project(world, id));\n }\n return result as { readonly [K in keyof S]: readonly unknown[] };\n };\n}\n","/**\n * Fake monotonic clock for driving `GameLoop` deterministically in tests.\n *\n * Usage:\n * const fake = createFakeClock();\n * loop.tick = fake.requestFrame;\n * loop.cancelTick = fake.cancelFrame;\n * loop.start();\n * fake.advance(1 / 60); // runs one frame\n */\nexport interface FakeClock {\n /** Current fake timestamp in milliseconds. */\n readonly now: number;\n /** rAF-compatible request — stores the callback for the next `advance`. */\n requestFrame(callback: (time: number) => void): number;\n /** rAF-compatible cancel. */\n cancelFrame(id: number): void;\n /** Advance time by `seconds` and fire every pending callback once. */\n advance(seconds: number): void;\n /** Reset time and cancel all pending callbacks. */\n reset(): void;\n}\n\nexport function createFakeClock(): FakeClock {\n let nowMs = 0;\n let nextId = 1;\n const pending = new Map<number, (time: number) => void>();\n\n const clock: FakeClock = {\n get now() {\n return nowMs;\n },\n requestFrame(callback) {\n const id = nextId++;\n pending.set(id, callback);\n return id;\n },\n cancelFrame(id) {\n pending.delete(id);\n },\n advance(seconds) {\n if (seconds < 0) throw new Error('[@flare-engine/testing] cannot advance backwards');\n nowMs += seconds * 1000;\n // Snapshot callbacks so any newly scheduled ones via requestFrame during\n // this flush are deferred to the next advance — mirrors rAF semantics.\n const snapshot = [...pending.entries()];\n pending.clear();\n for (const [, cb] of snapshot) cb(nowMs);\n },\n reset() {\n nowMs = 0;\n pending.clear();\n nextId = 1;\n },\n };\n return clock;\n}\n","import { InputManager } from '@flare-engine/input';\n\n/**\n * `InputManager` subclass with scripted helpers for tests. Drives the same\n * internal state the real manager uses, so any system reading\n * `.pointer` / `.touches` sees identical data.\n */\nexport class MockInputManager extends InputManager {\n /** Press a pointer at `(x, y)`. `id` defaults to 0 (primary). */\n press(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n }\n /** Move a pointer to `(x, y)`. */\n move(x: number, y: number, id = 0): void {\n this.onPointerMove(id, x, y);\n }\n /** Release a pointer at `(x, y)`. */\n release(x: number, y: number, id = 0): void {\n this.onPointerUp(id, x, y);\n }\n /** Full tap: press → release in one call. */\n tap(x: number, y: number, id = 0): void {\n this.onPointerDown(id, x, y);\n this.onPointerUp(id, x, y);\n }\n}\n\nexport function createMockInputManager(): MockInputManager {\n return new MockInputManager();\n}\n","import type { ComponentDef, Query, World } from '@flare-engine/ecs';\n\n// One singleton Query per (world, component), memoized so repeat serializeScene\n// calls reuse them instead of registering a fresh (leaked) query each call.\n// Queries auto-update, so reuse always reflects current world state. Bounded: at\n// most one query per distinct component per world, all released when the world is\n// garbage-collected (the WeakMap holds no strong ref beyond the world's lifetime).\nconst singletonQueries = new WeakMap<World, Map<number, Query>>();\n\nfunction singletonQuery(world: World, def: ComponentDef<unknown>): Query {\n let byComponent = singletonQueries.get(world);\n if (byComponent === undefined) {\n byComponent = new Map();\n singletonQueries.set(world, byComponent);\n }\n let q = byComponent.get(def.id);\n if (q === undefined) {\n q = world.query(def);\n byComponent.set(def.id, q);\n }\n return q;\n}\n\n/**\n * A single entity in a snapshot. Component names come from `ComponentDef.name`.\n */\nexport interface SceneSnapshotEntity {\n id: number;\n components: Record<string, unknown>;\n}\n\nexport interface SceneSnapshot {\n entities: SceneSnapshotEntity[];\n}\n\n/**\n * Serialize every entity that has at least one of the supplied components into\n * a stable, deterministic snapshot. Entities are sorted by id; component keys\n * are inserted in the order the components are passed.\n */\nexport function serializeScene(\n world: World,\n components: readonly ComponentDef<unknown>[],\n): SceneSnapshot {\n // Collect every entity that has ANY of the supplied components (union of the\n // per-component queries). A separate ALL query would be redundant — anything\n // matching ALL already matches each singleton.\n const ids = new Set<number>();\n for (const def of components) {\n for (const id of singletonQuery(world, def)) ids.add(id);\n }\n\n const sortedIds = [...ids].sort((a, b) => a - b);\n const entities: SceneSnapshotEntity[] = [];\n for (const id of sortedIds) {\n const comps: Record<string, unknown> = {};\n for (const def of components) {\n if (world.has(id, def)) comps[def.name] = world.get(id, def);\n }\n entities.push({ id, components: comps });\n }\n return { entities };\n}\n\n/**\n * Deep-equal comparison good enough for snapshot assertions. Compares plain\n * objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.\n */\nexport function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean {\n return deepEqual(a, b);\n}\n\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== typeof b) return false;\n if (a === null || b === null) return false;\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (!deepEqual(a[i], b[i])) return false;\n }\n return true;\n }\n if (typeof a === 'object' && typeof b === 'object') {\n const ao = a as Record<string, unknown>;\n const bo = b as Record<string, unknown>;\n const ak = Object.keys(ao);\n const bk = Object.keys(bo);\n if (ak.length !== bk.length) return false;\n for (const k of ak) {\n if (!Object.hasOwn(bo, k)) return false;\n if (!deepEqual(ao[k], bo[k])) return false;\n }\n return true;\n }\n return false;\n}\n","import { GameLoop } from '@flare-engine/core';\nimport { World } from '@flare-engine/ecs';\nimport { createFakeClock, type FakeClock } from './fake-clock.js';\n\nexport interface TestWorld {\n /** ECS world. */\n readonly world: World;\n /** Game loop wired to a fake clock. */\n readonly loop: GameLoop;\n /** Fake clock driving the loop. */\n readonly clock: FakeClock;\n /** Advance one frame of `dt` seconds. Runs the loop's fixed + variable update. */\n step(dt: number): void;\n /** Advance `frames` frames of `dt` seconds each. */\n stepFrames(frames: number, dt?: number): void;\n}\n\nexport interface CreateTestWorldOptions {\n /** Fixed timestep passed to `GameLoop`. Defaults to 1/60. */\n fixedDt?: number;\n /** Maximum raw dt cap passed to `GameLoop`. Defaults to 0.25s. */\n maxDt?: number;\n}\n\n/**\n * Create a World + GameLoop + FakeClock wired together for deterministic\n * testing. `step()` calls the loop's `step()` directly so fixed and variable\n * updates fire for the exact dt you pass, without needing to start the rAF\n * loop.\n */\nexport function createTestWorld(options: CreateTestWorldOptions = {}): TestWorld {\n const world = new World();\n const loop = new GameLoop(options);\n const clock = createFakeClock();\n loop.tick = clock.requestFrame;\n loop.cancelTick = clock.cancelFrame;\n\n return {\n world,\n loop,\n clock,\n step(dt) {\n loop.step(dt);\n },\n stepFrames(frames, dt = 1 / 60) {\n for (let i = 0; i < frames; i++) loop.step(dt);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;AAwBA,SAAgB,mBAAmB,OAA4B,CAAC,GAAiB;CAC/E,MAAM,OAAO,KAAK,QAAQ;CAC1B,MAAM,MAAM,IAAI,UAAU,IAAI;CAE9B,MAAM,iBAAiB,KAAK;CAC5B,MAAM,gBAAgB,IAAI,KAAK;CAC/B,KAAK,SAAS;CAEd,MAAM,QAAiC,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ClB,IAAI,CAAC,OAAO,OAAO,IAAI,CAAC,GAAG,OAAO;GAClC,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,GAAG,OAAO;EACvC;EACA,OAAO;CACT;CACA,OAAO;AACT;;;;;;;;AClEA,SAAgB,gBAAgB,UAAkC,CAAC,GAAc;CAC/E,MAAM,QAAQ,IAAI,MAAM;CACxB,MAAM,OAAO,IAAI,SAAS,OAAO;CACjC,MAAM,QAAQ,gBAAgB;CAC9B,KAAK,OAAO,MAAM;CAClB,KAAK,aAAa,MAAM;CAExB,OAAO;EACL;EACA;EACA;EACA,KAAK,IAAI;GACP,KAAK,KAAK,EAAE;EACd;EACA,WAAW,QAAQ,KAAK,IAAI,IAAI;GAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK,KAAK,KAAK,EAAE;EAC/C;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flare-engine/testing",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "Deterministic World factory, fake Clock, mock InputManager, and scene snapshot helpers",
|
|
5
5
|
"keywords": ["flare-engine", "testing", "ecs", "fake-clock", "snapshot"],
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"typecheck": "tsc --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@flare-engine/core": "^0.4.
|
|
41
|
-
"@flare-engine/ecs": "^0.4.
|
|
42
|
-
"@flare-engine/input": "^0.4.
|
|
43
|
-
"@flare-engine/math": "^0.4.
|
|
40
|
+
"@flare-engine/core": "^0.4.7",
|
|
41
|
+
"@flare-engine/ecs": "^0.4.7",
|
|
42
|
+
"@flare-engine/input": "^0.4.7",
|
|
43
|
+
"@flare-engine/math": "^0.4.7"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=20"
|