@flare-engine/testing 0.1.0 → 0.2.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 +1 -1
- package/dist/index.d.mts +34 -1
- package/dist/index.d.ts +34 -1
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ const snap = serializeScene(world, [Position]);
|
|
|
25
25
|
expect(snap.entities[0].components.Position.x).toBe(60);
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
See [API spec](../../docs/design/api-specs.md#flare-enginetesting--4kb-raw)
|
|
28
|
+
See [API spec](../../docs/design/api-specs.md#flare-enginetesting--4kb-raw).
|
|
29
29
|
|
|
30
30
|
## License
|
|
31
31
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GameLoop } from '@flare-engine/core';
|
|
2
2
|
import { World, ComponentDef } from '@flare-engine/ecs';
|
|
3
3
|
import { InputManager } from '@flare-engine/input';
|
|
4
|
+
import { SeededRNG } from '@flare-engine/math';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Fake monotonic clock for driving `GameLoop` deterministically in tests.
|
|
@@ -91,4 +92,36 @@ declare function serializeScene(world: World, components: readonly ComponentDef<
|
|
|
91
92
|
*/
|
|
92
93
|
declare function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean;
|
|
93
94
|
|
|
94
|
-
|
|
95
|
+
interface BenchSessionOptions {
|
|
96
|
+
seed?: number;
|
|
97
|
+
}
|
|
98
|
+
interface BenchSession {
|
|
99
|
+
readonly rng: SeededRNG;
|
|
100
|
+
setFlag(name: string, value: boolean): void;
|
|
101
|
+
getFlag(name: string): boolean;
|
|
102
|
+
/** Resolves whenDone. Idempotent — safe to call multiple times. */
|
|
103
|
+
done(): void;
|
|
104
|
+
readonly whenDone: Promise<void>;
|
|
105
|
+
/** Restores Math.random. Idempotent. */
|
|
106
|
+
end(): void;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.
|
|
110
|
+
*
|
|
111
|
+
* Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally
|
|
112
|
+
* so a throw between install and end() cannot leak the patched Math.random.
|
|
113
|
+
*/
|
|
114
|
+
declare function createBenchSession(opts?: BenchSessionOptions): BenchSession;
|
|
115
|
+
|
|
116
|
+
interface SnapshotProjector {
|
|
117
|
+
readonly query: readonly ComponentDef<unknown>[];
|
|
118
|
+
project(world: World, id: number): unknown;
|
|
119
|
+
}
|
|
120
|
+
interface SnapshotSchema {
|
|
121
|
+
readonly [key: string]: SnapshotProjector;
|
|
122
|
+
}
|
|
123
|
+
declare function defineSnapshot<S extends SnapshotSchema>(schema: S): (world: World) => {
|
|
124
|
+
readonly [K in keyof S]: readonly unknown[];
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GameLoop } from '@flare-engine/core';
|
|
2
2
|
import { World, ComponentDef } from '@flare-engine/ecs';
|
|
3
3
|
import { InputManager } from '@flare-engine/input';
|
|
4
|
+
import { SeededRNG } from '@flare-engine/math';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Fake monotonic clock for driving `GameLoop` deterministically in tests.
|
|
@@ -91,4 +92,36 @@ declare function serializeScene(world: World, components: readonly ComponentDef<
|
|
|
91
92
|
*/
|
|
92
93
|
declare function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean;
|
|
93
94
|
|
|
94
|
-
|
|
95
|
+
interface BenchSessionOptions {
|
|
96
|
+
seed?: number;
|
|
97
|
+
}
|
|
98
|
+
interface BenchSession {
|
|
99
|
+
readonly rng: SeededRNG;
|
|
100
|
+
setFlag(name: string, value: boolean): void;
|
|
101
|
+
getFlag(name: string): boolean;
|
|
102
|
+
/** Resolves whenDone. Idempotent — safe to call multiple times. */
|
|
103
|
+
done(): void;
|
|
104
|
+
readonly whenDone: Promise<void>;
|
|
105
|
+
/** Restores Math.random. Idempotent. */
|
|
106
|
+
end(): void;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.
|
|
110
|
+
*
|
|
111
|
+
* Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally
|
|
112
|
+
* so a throw between install and end() cannot leak the patched Math.random.
|
|
113
|
+
*/
|
|
114
|
+
declare function createBenchSession(opts?: BenchSessionOptions): BenchSession;
|
|
115
|
+
|
|
116
|
+
interface SnapshotProjector {
|
|
117
|
+
readonly query: readonly ComponentDef<unknown>[];
|
|
118
|
+
project(world: World, id: number): unknown;
|
|
119
|
+
}
|
|
120
|
+
interface SnapshotSchema {
|
|
121
|
+
readonly [key: string]: SnapshotProjector;
|
|
122
|
+
}
|
|
123
|
+
declare function defineSnapshot<S extends SnapshotSchema>(schema: S): (world: World) => {
|
|
124
|
+
readonly [K in keyof S]: readonly unknown[];
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -21,9 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
MockInputManager: () => MockInputManager,
|
|
24
|
+
createBenchSession: () => createBenchSession,
|
|
24
25
|
createFakeClock: () => createFakeClock,
|
|
25
26
|
createMockInputManager: () => createMockInputManager,
|
|
26
27
|
createTestWorld: () => createTestWorld,
|
|
28
|
+
defineSnapshot: () => defineSnapshot,
|
|
27
29
|
serializeScene: () => serializeScene,
|
|
28
30
|
snapshotsEqual: () => snapshotsEqual
|
|
29
31
|
});
|
|
@@ -157,12 +159,80 @@ function deepEqual(a, b) {
|
|
|
157
159
|
}
|
|
158
160
|
return false;
|
|
159
161
|
}
|
|
162
|
+
|
|
163
|
+
// src/bench-session.ts
|
|
164
|
+
var import_math = require("@flare-engine/math");
|
|
165
|
+
function createBenchSession(opts = {}) {
|
|
166
|
+
const seed = opts.seed ?? 1;
|
|
167
|
+
const rng = new import_math.SeededRNG(seed);
|
|
168
|
+
const originalRandom = Math.random;
|
|
169
|
+
const patched = () => rng.next();
|
|
170
|
+
Math.random = patched;
|
|
171
|
+
const flags = {};
|
|
172
|
+
let resolve = null;
|
|
173
|
+
const whenDone = new Promise((res) => {
|
|
174
|
+
resolve = res;
|
|
175
|
+
});
|
|
176
|
+
let doneResolved = false;
|
|
177
|
+
return {
|
|
178
|
+
rng,
|
|
179
|
+
setFlag(name, value) {
|
|
180
|
+
flags[name] = value;
|
|
181
|
+
},
|
|
182
|
+
getFlag(name) {
|
|
183
|
+
return flags[name] ?? false;
|
|
184
|
+
},
|
|
185
|
+
done() {
|
|
186
|
+
if (!doneResolved) {
|
|
187
|
+
doneResolved = true;
|
|
188
|
+
resolve?.();
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
whenDone,
|
|
192
|
+
end() {
|
|
193
|
+
if (Math.random === patched) {
|
|
194
|
+
Math.random = originalRandom;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/define-snapshot.ts
|
|
201
|
+
function defineSnapshot(schema) {
|
|
202
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
203
|
+
const keys = Object.keys(schema);
|
|
204
|
+
return (world) => {
|
|
205
|
+
let queries = cache.get(world);
|
|
206
|
+
if (queries === void 0) {
|
|
207
|
+
queries = keys.map((key) => {
|
|
208
|
+
const projector = schema[key];
|
|
209
|
+
return world.query(...projector.query);
|
|
210
|
+
});
|
|
211
|
+
cache.set(world, queries);
|
|
212
|
+
}
|
|
213
|
+
const result = {};
|
|
214
|
+
for (let i = 0; i < keys.length; i++) {
|
|
215
|
+
const key = keys[i];
|
|
216
|
+
const projector = schema[key];
|
|
217
|
+
const q = queries[i];
|
|
218
|
+
const ids = [];
|
|
219
|
+
for (const id of q) {
|
|
220
|
+
ids.push(id);
|
|
221
|
+
}
|
|
222
|
+
ids.sort((a, b) => a - b);
|
|
223
|
+
result[key] = ids.map((id) => projector.project(world, id));
|
|
224
|
+
}
|
|
225
|
+
return result;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
160
228
|
// Annotate the CommonJS export names for ESM import in node:
|
|
161
229
|
0 && (module.exports = {
|
|
162
230
|
MockInputManager,
|
|
231
|
+
createBenchSession,
|
|
163
232
|
createFakeClock,
|
|
164
233
|
createMockInputManager,
|
|
165
234
|
createTestWorld,
|
|
235
|
+
defineSnapshot,
|
|
166
236
|
serializeScene,
|
|
167
237
|
snapshotsEqual
|
|
168
238
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/fake-clock.ts","../src/test-world.ts","../src/mock-input.ts","../src/scene-snapshot.ts"],"sourcesContent":["export { createFakeClock } from './fake-clock.js';\nexport type { FakeClock } from './fake-clock.js';\nexport { createTestWorld } from './test-world.js';\nexport type { CreateTestWorldOptions, TestWorld } from './test-world.js';\nexport { MockInputManager, createMockInputManager } from './mock-input.js';\nexport { serializeScene, snapshotsEqual } from './scene-snapshot.js';\nexport type { SceneSnapshot, SceneSnapshotEntity } from './scene-snapshot.js';\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 { GameLoop } from '@flare-engine/core';\nimport { World } from '@flare-engine/ecs';\nimport { type FakeClock, createFakeClock } 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","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, World } from '@flare-engine/ecs';\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 const ids = new Set<number>();\n const q = world.query(...components);\n for (const id of q) ids.add(id);\n // Also include entities that have any subset — the query above requires ALL.\n // For snapshots we want \"any of\". Iterate each component individually.\n for (const def of components) {\n const singletonQ = world.query(def);\n for (const id of singletonQ) 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACuBO,SAAS,kBAA6B;AAC3C,MAAI,QAAQ;AACZ,MAAI,SAAS;AACb,QAAM,UAAU,oBAAI,IAAoC;AAExD,QAAM,QAAmB;AAAA,IACvB,IAAI,MAAM;AAC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OAAQ,QAAO;AACvD,aAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,UAAI,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAG,QAAO;AAAA,IACrC;AACA,WAAO;AAAA,EACT;AACA,MAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;AAClD,UAAM,KAAK;AACX,UAAM,KAAK;AACX,UAAM,KAAK,OAAO,KAAK,EAAE;AACzB,UAAM,KAAK,OAAO,KAAK,EAAE;AACzB,QAAI,GAAG,WAAW,GAAG,OAAQ,QAAO;AACpC,eAAW,KAAK,IAAI;AAClB,UAAI,CAAC,OAAO,OAAO,IAAI,CAAC,EAAG,QAAO;AAClC,UAAI,CAAC,UAAU,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,EAAG,QAAO;AAAA,IACvC;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/fake-clock.ts","../src/test-world.ts","../src/mock-input.ts","../src/scene-snapshot.ts","../src/bench-session.ts","../src/define-snapshot.ts"],"sourcesContent":["export { createFakeClock } from './fake-clock.js';\nexport type { FakeClock } from './fake-clock.js';\nexport { createTestWorld } from './test-world.js';\nexport type { CreateTestWorldOptions, TestWorld } from './test-world.js';\nexport { MockInputManager, createMockInputManager } from './mock-input.js';\nexport { serializeScene, snapshotsEqual } from './scene-snapshot.js';\nexport type { SceneSnapshot, SceneSnapshotEntity } from './scene-snapshot.js';\nexport { createBenchSession } from './bench-session.js';\nexport type { BenchSession, BenchSessionOptions } from './bench-session.js';\nexport { defineSnapshot } from './define-snapshot.js';\nexport type { SnapshotProjector, SnapshotSchema } from './define-snapshot.js';\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 { GameLoop } from '@flare-engine/core';\nimport { World } from '@flare-engine/ecs';\nimport { type FakeClock, createFakeClock } 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","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, World } from '@flare-engine/ecs';\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 const ids = new Set<number>();\n const q = world.query(...components);\n for (const id of q) ids.add(id);\n // Also include entities that have any subset — the query above requires ALL.\n // For snapshots we want \"any of\". Iterate each component individually.\n for (const def of components) {\n const singletonQ = world.query(def);\n for (const id of singletonQ) 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 { SeededRNG } from '@flare-engine/math';\nimport type { SeededRNG as SeededRNGType } 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 }\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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Aa;AACX,UAAI,CAAC,cAAc;AACjB,uBAAe;AACf,kBAAU;AAAA,MACZ;AAAA,IACF;AAAA,IACA;AAAA,IACA,MAAY;AAGV,UAAI,KAAK,WAAW,SAAS;AAC3B,aAAK,SAAS;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;;;ACrDO,SAAS,eACd,QACmE;AAEnE,QAAM,QAAQ,oBAAI,QAAwB;AAC1C,QAAM,OAAO,OAAO,KAAK,MAAM;AAE/B,SAAO,CAAC,UAAiB;AACvB,QAAI,UAAU,MAAM,IAAI,KAAK;AAC7B,QAAI,YAAY,QAAW;AACzB,gBAAU,KAAK,IAAI,CAAC,QAAQ;AAC1B,cAAM,YAAY,OAAO,GAAG;AAC5B,eAAO,MAAM,MAAM,GAAI,UAAU,KAAiC;AAAA,MACpE,CAAC;AACD,YAAM,IAAI,OAAO,OAAO;AAAA,IAC1B;AAEA,UAAM,SAA6C,CAAC;AACpD,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,YAAM,MAAM,KAAK,CAAC;AAClB,YAAM,YAAY,OAAO,GAAG;AAC5B,YAAM,IAAI,QAAQ,CAAC;AACnB,YAAM,MAAgB,CAAC;AACvB,iBAAW,MAAM,GAAG;AAClB,YAAI,KAAK,EAAE;AAAA,MACb;AACA,UAAI,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AACxB,aAAO,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,UAAU,QAAQ,OAAO,EAAE,CAAC;AAAA,IAC5D;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -126,11 +126,79 @@ function deepEqual(a, b) {
|
|
|
126
126
|
}
|
|
127
127
|
return false;
|
|
128
128
|
}
|
|
129
|
+
|
|
130
|
+
// src/bench-session.ts
|
|
131
|
+
import { SeededRNG } from "@flare-engine/math";
|
|
132
|
+
function createBenchSession(opts = {}) {
|
|
133
|
+
const seed = opts.seed ?? 1;
|
|
134
|
+
const rng = new SeededRNG(seed);
|
|
135
|
+
const originalRandom = Math.random;
|
|
136
|
+
const patched = () => rng.next();
|
|
137
|
+
Math.random = patched;
|
|
138
|
+
const flags = {};
|
|
139
|
+
let resolve = null;
|
|
140
|
+
const whenDone = new Promise((res) => {
|
|
141
|
+
resolve = res;
|
|
142
|
+
});
|
|
143
|
+
let doneResolved = false;
|
|
144
|
+
return {
|
|
145
|
+
rng,
|
|
146
|
+
setFlag(name, value) {
|
|
147
|
+
flags[name] = value;
|
|
148
|
+
},
|
|
149
|
+
getFlag(name) {
|
|
150
|
+
return flags[name] ?? false;
|
|
151
|
+
},
|
|
152
|
+
done() {
|
|
153
|
+
if (!doneResolved) {
|
|
154
|
+
doneResolved = true;
|
|
155
|
+
resolve?.();
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
whenDone,
|
|
159
|
+
end() {
|
|
160
|
+
if (Math.random === patched) {
|
|
161
|
+
Math.random = originalRandom;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/define-snapshot.ts
|
|
168
|
+
function defineSnapshot(schema) {
|
|
169
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
170
|
+
const keys = Object.keys(schema);
|
|
171
|
+
return (world) => {
|
|
172
|
+
let queries = cache.get(world);
|
|
173
|
+
if (queries === void 0) {
|
|
174
|
+
queries = keys.map((key) => {
|
|
175
|
+
const projector = schema[key];
|
|
176
|
+
return world.query(...projector.query);
|
|
177
|
+
});
|
|
178
|
+
cache.set(world, queries);
|
|
179
|
+
}
|
|
180
|
+
const result = {};
|
|
181
|
+
for (let i = 0; i < keys.length; i++) {
|
|
182
|
+
const key = keys[i];
|
|
183
|
+
const projector = schema[key];
|
|
184
|
+
const q = queries[i];
|
|
185
|
+
const ids = [];
|
|
186
|
+
for (const id of q) {
|
|
187
|
+
ids.push(id);
|
|
188
|
+
}
|
|
189
|
+
ids.sort((a, b) => a - b);
|
|
190
|
+
result[key] = ids.map((id) => projector.project(world, id));
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
};
|
|
194
|
+
}
|
|
129
195
|
export {
|
|
130
196
|
MockInputManager,
|
|
197
|
+
createBenchSession,
|
|
131
198
|
createFakeClock,
|
|
132
199
|
createMockInputManager,
|
|
133
200
|
createTestWorld,
|
|
201
|
+
defineSnapshot,
|
|
134
202
|
serializeScene,
|
|
135
203
|
snapshotsEqual
|
|
136
204
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fake-clock.ts","../src/test-world.ts","../src/mock-input.ts","../src/scene-snapshot.ts"],"sourcesContent":["/**\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 { GameLoop } from '@flare-engine/core';\nimport { World } from '@flare-engine/ecs';\nimport { type FakeClock, createFakeClock } 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","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, World } from '@flare-engine/ecs';\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 const ids = new Set<number>();\n const q = world.query(...components);\n for (const id of q) ids.add(id);\n // Also include entities that have any subset — the query above requires ALL.\n // For snapshots we want \"any of\". Iterate each component individually.\n for (const def of components) {\n const singletonQ = world.query(def);\n for (const id of singletonQ) 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"],"mappings":";AAuBO,SAAS,kBAA6B;AAC3C,MAAI,QAAQ;AACZ,MAAI,SAAS;AACb,QAAM,UAAU,oBAAI,IAAoC;AAExD,QAAM,QAAmB;AAAA,IACvB,IAAI,MAAM;AACR,aAAO;AAAA,IACT;AAAA,IACA,aAAa,UAAU;AACrB,YAAM,KAAK;AACX,cAAQ,IAAI,IAAI,QAAQ;AACxB,aAAO;AAAA,IACT;AAAA,IACA,YAAY,IAAI;AACd,cAAQ,OAAO,EAAE;AAAA,IACnB;AAAA,IACA,QAAQ,SAAS;AACf,UAAI,UAAU,EAAG,OAAM,IAAI,MAAM,kDAAkD;AACnF,eAAS,UAAU;AAGnB,YAAM,WAAW,CAAC,GAAG,QAAQ,QAAQ,CAAC;AACtC,cAAQ,MAAM;AACd,iBAAW,CAAC,EAAE,EAAE,KAAK,SAAU,IAAG,KAAK;AAAA,IACzC;AAAA,IACA,QAAQ;AACN,cAAQ;AACR,cAAQ,MAAM;AACd,eAAS;AAAA,IACX;AAAA,EACF;AACA,SAAO;AACT;;;ACxDA,SAAS,gBAAgB;AACzB,SAAS,aAAa;AA6Bf,SAAS,gBAAgB,UAAkC,CAAC,GAAc;AAC/E,QAAM,QAAQ,IAAI,MAAM;AACxB,QAAM,OAAO,IAAI,SAAS,OAAO;AACjC,QAAM,QAAQ,gBAAgB;AAC9B,OAAK,OAAO,MAAM;AAClB,OAAK,aAAa,MAAM;AAExB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,KAAK,IAAI;AACP,WAAK,KAAK,EAAE;AAAA,IACd;AAAA,IACA,WAAW,QAAQ,KAAK,IAAI,IAAI;AAC9B,eAAS,IAAI,GAAG,IAAI,QAAQ,IAAK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,SAAS,eAAe,GAAkB,GAA2B;AAC1E,SAAO,UAAU,GAAG,CAAC;AACvB;AAEA,SAAS,UAAU,GAAY,GAAqB;AAClD,MAAI,OAAO,GAAG,GAAG,CAAC,EAAG,QAAO;AAC5B,MAAI,OAAO,MAAM,OAAO,EAAG,QAAO;AAClC,MAAI,MAAM,QAAQ,MAAM,KAAM,QAAO;AACrC,MAAI,MAAM,QAAQ,CAAC,GAAG;AACpB,QAAI,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,OAAQ,QAAO;AACvD,aAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,UAAI,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAG,QAAO;AAAA,IACrC;AACA,WAAO;AAAA,EACT;AACA,MAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;AAClD,UAAM,KAAK;AACX,UAAM,KAAK;AACX,UAAM,KAAK,OAAO,KAAK,EAAE;AACzB,UAAM,KAAK,OAAO,KAAK,EAAE;AACzB,QAAI,GAAG,WAAW,GAAG,OAAQ,QAAO;AACpC,eAAW,KAAK,IAAI;AAClB,UAAI,CAAC,OAAO,OAAO,IAAI,CAAC,EAAG,QAAO;AAClC,UAAI,CAAC,UAAU,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,EAAG,QAAO;AAAA,IACvC;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/fake-clock.ts","../src/test-world.ts","../src/mock-input.ts","../src/scene-snapshot.ts","../src/bench-session.ts","../src/define-snapshot.ts"],"sourcesContent":["/**\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 { GameLoop } from '@flare-engine/core';\nimport { World } from '@flare-engine/ecs';\nimport { type FakeClock, createFakeClock } 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","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, World } from '@flare-engine/ecs';\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 const ids = new Set<number>();\n const q = world.query(...components);\n for (const id of q) ids.add(id);\n // Also include entities that have any subset — the query above requires ALL.\n // For snapshots we want \"any of\". Iterate each component individually.\n for (const def of components) {\n const singletonQ = world.query(def);\n for (const id of singletonQ) 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 { SeededRNG } from '@flare-engine/math';\nimport type { SeededRNG as SeededRNGType } 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 }\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"],"mappings":";AAuBO,SAAS,kBAA6B;AAC3C,MAAI,QAAQ;AACZ,MAAI,SAAS;AACb,QAAM,UAAU,oBAAI,IAAoC;AAExD,QAAM,QAAmB;AAAA,IACvB,IAAI,MAAM;AACR,aAA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S;AAC3B,aAAK,SAAS;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;;;ACrDO,SAAS,eACd,QACmE;AAEnE,QAAM,QAAQ,oBAAI,QAAwB;AAC1C,QAAM,OAAO,OAAO,KAAK,MAAM;AAE/B,SAAO,CAAC,UAAiB;AACvB,QAAI,UAAU,MAAM,IAAI,KAAK;AAC7B,QAAI,YAAY,QAAW;AACzB,gBAAU,KAAK,IAAI,CAAC,QAAQ;AAC1B,cAAM,YAAY,OAAO,GAAG;AAC5B,eAAO,MAAM,MAAM,GAAI,UAAU,KAAiC;AAAA,MACpE,CAAC;AACD,YAAM,IAAI,OAAO,OAAO;AAAA,IAC1B;AAEA,UAAM,SAA6C,CAAC;AACpD,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,YAAM,MAAM,KAAK,CAAC;AAClB,YAAM,YAAY,OAAO,GAAG;AAC5B,YAAM,IAAI,QAAQ,CAAC;AACnB,YAAM,MAAgB,CAAC;AACvB,iBAAW,MAAM,GAAG;AAClB,YAAI,KAAK,EAAE;AAAA,MACb;AACA,UAAI,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AACxB,aAAO,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,UAAU,QAAQ,OAAO,EAAE,CAAC;AAAA,IAC5D;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flare-engine/testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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": "MIT",
|
|
@@ -32,9 +32,10 @@
|
|
|
32
32
|
"typecheck": "tsc --noEmit"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@flare-engine/core": "^0.
|
|
36
|
-
"@flare-engine/ecs": "^0.
|
|
37
|
-
"@flare-engine/input": "^0.
|
|
35
|
+
"@flare-engine/core": "^0.2.0",
|
|
36
|
+
"@flare-engine/ecs": "^0.2.0",
|
|
37
|
+
"@flare-engine/input": "^0.2.0",
|
|
38
|
+
"@flare-engine/math": "^0.2.0"
|
|
38
39
|
},
|
|
39
40
|
"publishConfig": {
|
|
40
41
|
"access": "restricted",
|