@flare-engine/testing 0.4.8 → 0.4.10
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 +29 -1
- package/dist/index.d.mts +75 -22
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +75 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +70 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @flare-engine/testing
|
|
2
2
|
|
|
3
|
-
Deterministic test helpers for ECS games.
|
|
3
|
+
Deterministic test helpers for ECS games. A dev-time package by default — it is not bundled into apps unless an app opts in for the one runtime use described under [Bench harnesses](#bench-harnesses). `createFakeClock` is a deterministic `requestFrame` / `cancelFrame` replacement; `createTestWorld` wires a `World` + `GameLoop` + fake clock together; `createHeadlessContext` builds on it to stand in for the React `GameContextValue` (camera, input, assets, sheet) without React Native or Skia; `MockInputManager` extends the real `InputManager` with scriptable pointer sequences; `serializeScene` / `snapshotsEqual` enable regression-style snapshot tests.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -27,6 +27,34 @@ const posX = (snap.entities[0]?.components['Position'] as { x: number } | undefi
|
|
|
27
27
|
const passed: boolean = posX === 60;
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
## Headless context
|
|
31
|
+
|
|
32
|
+
`createHeadlessContext` returns the `createTestWorld` members plus a real `Camera2D`, a `MockInputManager`, an `AssetManager` with a resolve-`null` loader, a permissive `SpriteSheet` and a caller-supplied `scenes` slot. `loop.onLateUpdate` runs `camera.update(dt)` then `input.update()` each frame, the same wiring `GameView` installs.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { getFrame } from '@flare-engine/assets';
|
|
36
|
+
import { createHeadlessContext } from '@flare-engine/testing';
|
|
37
|
+
|
|
38
|
+
const ctx = createHeadlessContext({ viewportWidth: 320, viewportHeight: 180 });
|
|
39
|
+
ctx.camera.shake(8, 0.5);
|
|
40
|
+
ctx.input.tap(10, 10);
|
|
41
|
+
ctx.stepFrames(10);
|
|
42
|
+
|
|
43
|
+
// camera.update(dt) and input.update() ran on every stepped frame
|
|
44
|
+
const shaking: boolean = ctx.camera.effectiveX !== ctx.camera.x;
|
|
45
|
+
const tapCleared: boolean = ctx.input.pointer.justPressed === false;
|
|
46
|
+
// the permissive sheet resolves every frame name to its single 8x8 frame
|
|
47
|
+
const frame = getFrame(ctx.sheet, 'any-name');
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Bench harnesses
|
|
51
|
+
|
|
52
|
+
`createBenchSession` is a test-runner primitive, not an app-side one. It replaces `Math.random` with a seeded RNG for the life of the session (until `end()` restores it), and its `whenDone` latch is a Promise for a test to `await` — not a synchronous flag a render loop can poll each frame. It is meant to wrap one deterministic scenario inside a test runner.
|
|
53
|
+
|
|
54
|
+
In-app bench harnesses — a scenario runner that ships in app code, its done-latch (a synchronous `isBenchDone()` or similar), its flags and its reporting — are **consumer-owned**. The engine does not ship one, and no runtime package re-exports `createBenchSession`. Write the harness in the app; share with it only what it actually needs from the engine (for example a `SeededRNG` from `@flare-engine/math`).
|
|
55
|
+
|
|
56
|
+
An app that does want the seeded session at runtime may list `@flare-engine/testing` as a regular `dependency` instead of a `devDependency`. Its own dependencies are the `@flare-engine/*` runtime packages `assets`, `core`, `ecs`, `input`, `math` and `render` only, with no peer dependencies, so nothing outside the engine enters the bundle.
|
|
57
|
+
|
|
30
58
|
See [API spec](https://github.com/grzott/flare-engine/blob/main/docs/design/api-specs.md#flare-enginetesting--4kb-raw).
|
|
31
59
|
|
|
32
60
|
## License
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { SeededRNG } from "@flare-engine/math";
|
|
2
|
+
import { AssetManager, SpriteSheet } from "@flare-engine/assets";
|
|
3
|
+
import { Camera2D } from "@flare-engine/render";
|
|
2
4
|
import { InputManager } from "@flare-engine/input";
|
|
3
5
|
import { GameLoop } from "@flare-engine/core";
|
|
4
6
|
import { ComponentDef, World } from "@flare-engine/ecs";
|
|
@@ -69,27 +71,6 @@ export declare class MockInputManager extends InputManager {
|
|
|
69
71
|
tap(x: number, y: number, id?: number): void;
|
|
70
72
|
}
|
|
71
73
|
export declare function createMockInputManager(): MockInputManager;
|
|
72
|
-
/**
|
|
73
|
-
* A single entity in a snapshot. Component names come from `ComponentDef.name`.
|
|
74
|
-
*/
|
|
75
|
-
interface SceneSnapshotEntity {
|
|
76
|
-
id: number;
|
|
77
|
-
components: Record<string, unknown>;
|
|
78
|
-
}
|
|
79
|
-
interface SceneSnapshot {
|
|
80
|
-
entities: SceneSnapshotEntity[];
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Serialize every entity that has at least one of the supplied components into
|
|
84
|
-
* a stable, deterministic snapshot. Entities are sorted by id; component keys
|
|
85
|
-
* are inserted in the order the components are passed.
|
|
86
|
-
*/
|
|
87
|
-
export declare function serializeScene(world: World, components: readonly ComponentDef<unknown>[]): SceneSnapshot;
|
|
88
|
-
/**
|
|
89
|
-
* Deep-equal comparison good enough for snapshot assertions. Compares plain
|
|
90
|
-
* objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.
|
|
91
|
-
*/
|
|
92
|
-
export declare function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean;
|
|
93
74
|
interface TestWorld {
|
|
94
75
|
/** ECS world. */
|
|
95
76
|
readonly world: World;
|
|
@@ -115,5 +96,77 @@ interface CreateTestWorldOptions {
|
|
|
115
96
|
* loop.
|
|
116
97
|
*/
|
|
117
98
|
export declare function createTestWorld(options?: CreateTestWorldOptions): TestWorld;
|
|
118
|
-
|
|
99
|
+
interface CreateHeadlessContextOptions<S = undefined> extends CreateTestWorldOptions {
|
|
100
|
+
/**
|
|
101
|
+
* Viewport width in pixels, forwarded to `camera.setViewport`. Must be given
|
|
102
|
+
* together with `viewportHeight`; one without the other throws a
|
|
103
|
+
* `RangeError`. Omitting both leaves the camera at its `new Camera2D()`
|
|
104
|
+
* default of a 0×0 viewport.
|
|
105
|
+
*/
|
|
106
|
+
viewportWidth?: number;
|
|
107
|
+
/** Viewport height in pixels. See `viewportWidth`. */
|
|
108
|
+
viewportHeight?: number;
|
|
109
|
+
/**
|
|
110
|
+
* Value exposed as `scenes` on the context, passed through untouched. The
|
|
111
|
+
* real `GameContextValue` holds a `SceneManager`, but `@flare-engine/scene`
|
|
112
|
+
* is tier 3 and this package is tier 2.5, so the caller builds it (or any
|
|
113
|
+
* stand-in) and hands it over here.
|
|
114
|
+
*/
|
|
115
|
+
scenes?: S;
|
|
116
|
+
}
|
|
117
|
+
interface HeadlessContext<S = undefined> extends TestWorld {
|
|
118
|
+
/** Real `Camera2D`, updated from `loop.onLateUpdate` like `GameView` does. */
|
|
119
|
+
readonly camera: Camera2D;
|
|
120
|
+
/** Scriptable input; `update()` runs from `loop.onLateUpdate` every frame. */
|
|
121
|
+
readonly input: MockInputManager;
|
|
122
|
+
/** Real `AssetManager` with a loader that resolves `null` for every entry. */
|
|
123
|
+
readonly assets: AssetManager;
|
|
124
|
+
/**
|
|
125
|
+
* Permissive sprite sheet: one 8×8 frame named `headless`, and a `frameMap`
|
|
126
|
+
* whose `get` always returns `0` and `has` always returns `true`, so
|
|
127
|
+
* `getFrame(sheet, anyName)` resolves to that frame.
|
|
128
|
+
*/
|
|
129
|
+
readonly sheet: SpriteSheet;
|
|
130
|
+
/** Whatever `options.scenes` was; `undefined` when omitted. */
|
|
131
|
+
readonly scenes: S;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Build a headless stand-in for the React `GameContextValue` for loop-harness
|
|
135
|
+
* tests. It is `createTestWorld(options)` plus the same `camera`, `input` and
|
|
136
|
+
* `assets` members `GameView` constructs (`audio`, `renderer` and `batch` are
|
|
137
|
+
* omitted — they need a platform), a permissive `sheet`, and a caller-supplied
|
|
138
|
+
* `scenes` slot. Nothing here imports React Native or Skia.
|
|
139
|
+
*
|
|
140
|
+
* Mirrors `GameView`'s frame wiring: `loop.onLateUpdate` runs
|
|
141
|
+
* `camera.update(dt)` then `input.update()`, so a `camera.shake()` moves
|
|
142
|
+
* `effectiveX` / `effectiveY` and a tapped pointer's `justPressed` clears once
|
|
143
|
+
* frames are stepped. `world`, `loop`, `clock`, `step` and `stepFrames` are the
|
|
144
|
+
* test world's own.
|
|
145
|
+
*/
|
|
146
|
+
export declare function createHeadlessContext(options?: CreateHeadlessContextOptions): HeadlessContext;
|
|
147
|
+
export declare function createHeadlessContext<S>(options: CreateHeadlessContextOptions<S> & {
|
|
148
|
+
scenes: S;
|
|
149
|
+
}): HeadlessContext<S>;
|
|
150
|
+
/**
|
|
151
|
+
* A single entity in a snapshot. Component names come from `ComponentDef.name`.
|
|
152
|
+
*/
|
|
153
|
+
interface SceneSnapshotEntity {
|
|
154
|
+
id: number;
|
|
155
|
+
components: Record<string, unknown>;
|
|
156
|
+
}
|
|
157
|
+
interface SceneSnapshot {
|
|
158
|
+
entities: SceneSnapshotEntity[];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Serialize every entity that has at least one of the supplied components into
|
|
162
|
+
* a stable, deterministic snapshot. Entities are sorted by id; component keys
|
|
163
|
+
* are inserted in the order the components are passed.
|
|
164
|
+
*/
|
|
165
|
+
export declare function serializeScene(world: World, components: readonly ComponentDef<unknown>[]): SceneSnapshot;
|
|
166
|
+
/**
|
|
167
|
+
* Deep-equal comparison good enough for snapshot assertions. Compares plain
|
|
168
|
+
* objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.
|
|
169
|
+
*/
|
|
170
|
+
export declare function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean;
|
|
171
|
+
export type { BenchSession, BenchSessionOptions, CreateHeadlessContextOptions, CreateTestWorldOptions, FakeClock, HeadlessContext, SceneSnapshot, SceneSnapshotEntity, SnapshotProjector, SnapshotSchema, TestWorld };
|
|
119
172
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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/
|
|
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/test-world.ts","../src/headless-context.ts","../src/scene-snapshot.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;UCvBzB;;WAEN,OAAO;;WAEP,MAAM;;WAEN,OAAO;;EAEhB,KAAK;;EAEL,WAAW,gBAAgB;;UAGZ;;EAEf;;EAEA;;;;;;;;wBASc,gBAAgB,UAAS,yBAA8B;UCzBtD,6BAA6B,uBAAuB;;;;;;;EAOnE;;EAEA;;;;;;;EAOA,SAAS;;UAGM,gBAAgB,uBAAuB;;WAE7C,QAAQ;;WAER,OAAO;;WAEP,QAAQ;;;;;;WAMR,OAAO;;WAEP,QAAQ;;;;;;;;;;;;;;;wBA6BH,sBAAsB,UAAU,+BAA+B;wBAC/D,sBAAsB,GACpC,SAAS,6BAA6B;EAAO,QAAQ;IACpD,gBAAgB;;;;UC5CF;EACf;EACA,YAAY;;UAGG;EACf,UAAU;;;;;;;wBAQI,eACd,OAAO,OACP,qBAAqB,0BACpB;;;;;wBAyBa,eAAe,GAAG,eAAe,GAAG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SeededRNG } from "@flare-engine/math";
|
|
2
2
|
import { ComponentDef, World } from "@flare-engine/ecs";
|
|
3
|
+
import { AssetManager, SpriteSheet } from "@flare-engine/assets";
|
|
4
|
+
import { Camera2D } from "@flare-engine/render";
|
|
3
5
|
import { InputManager } from "@flare-engine/input";
|
|
4
6
|
import { GameLoop } from "@flare-engine/core";
|
|
5
7
|
interface BenchSessionOptions {
|
|
@@ -69,27 +71,6 @@ export declare class MockInputManager extends InputManager {
|
|
|
69
71
|
tap(x: number, y: number, id?: number): void;
|
|
70
72
|
}
|
|
71
73
|
export declare function createMockInputManager(): MockInputManager;
|
|
72
|
-
/**
|
|
73
|
-
* A single entity in a snapshot. Component names come from `ComponentDef.name`.
|
|
74
|
-
*/
|
|
75
|
-
interface SceneSnapshotEntity {
|
|
76
|
-
id: number;
|
|
77
|
-
components: Record<string, unknown>;
|
|
78
|
-
}
|
|
79
|
-
interface SceneSnapshot {
|
|
80
|
-
entities: SceneSnapshotEntity[];
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Serialize every entity that has at least one of the supplied components into
|
|
84
|
-
* a stable, deterministic snapshot. Entities are sorted by id; component keys
|
|
85
|
-
* are inserted in the order the components are passed.
|
|
86
|
-
*/
|
|
87
|
-
export declare function serializeScene(world: World, components: readonly ComponentDef<unknown>[]): SceneSnapshot;
|
|
88
|
-
/**
|
|
89
|
-
* Deep-equal comparison good enough for snapshot assertions. Compares plain
|
|
90
|
-
* objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.
|
|
91
|
-
*/
|
|
92
|
-
export declare function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean;
|
|
93
74
|
interface TestWorld {
|
|
94
75
|
/** ECS world. */
|
|
95
76
|
readonly world: World;
|
|
@@ -115,5 +96,77 @@ interface CreateTestWorldOptions {
|
|
|
115
96
|
* loop.
|
|
116
97
|
*/
|
|
117
98
|
export declare function createTestWorld(options?: CreateTestWorldOptions): TestWorld;
|
|
118
|
-
|
|
99
|
+
interface CreateHeadlessContextOptions<S = undefined> extends CreateTestWorldOptions {
|
|
100
|
+
/**
|
|
101
|
+
* Viewport width in pixels, forwarded to `camera.setViewport`. Must be given
|
|
102
|
+
* together with `viewportHeight`; one without the other throws a
|
|
103
|
+
* `RangeError`. Omitting both leaves the camera at its `new Camera2D()`
|
|
104
|
+
* default of a 0×0 viewport.
|
|
105
|
+
*/
|
|
106
|
+
viewportWidth?: number;
|
|
107
|
+
/** Viewport height in pixels. See `viewportWidth`. */
|
|
108
|
+
viewportHeight?: number;
|
|
109
|
+
/**
|
|
110
|
+
* Value exposed as `scenes` on the context, passed through untouched. The
|
|
111
|
+
* real `GameContextValue` holds a `SceneManager`, but `@flare-engine/scene`
|
|
112
|
+
* is tier 3 and this package is tier 2.5, so the caller builds it (or any
|
|
113
|
+
* stand-in) and hands it over here.
|
|
114
|
+
*/
|
|
115
|
+
scenes?: S;
|
|
116
|
+
}
|
|
117
|
+
interface HeadlessContext<S = undefined> extends TestWorld {
|
|
118
|
+
/** Real `Camera2D`, updated from `loop.onLateUpdate` like `GameView` does. */
|
|
119
|
+
readonly camera: Camera2D;
|
|
120
|
+
/** Scriptable input; `update()` runs from `loop.onLateUpdate` every frame. */
|
|
121
|
+
readonly input: MockInputManager;
|
|
122
|
+
/** Real `AssetManager` with a loader that resolves `null` for every entry. */
|
|
123
|
+
readonly assets: AssetManager;
|
|
124
|
+
/**
|
|
125
|
+
* Permissive sprite sheet: one 8×8 frame named `headless`, and a `frameMap`
|
|
126
|
+
* whose `get` always returns `0` and `has` always returns `true`, so
|
|
127
|
+
* `getFrame(sheet, anyName)` resolves to that frame.
|
|
128
|
+
*/
|
|
129
|
+
readonly sheet: SpriteSheet;
|
|
130
|
+
/** Whatever `options.scenes` was; `undefined` when omitted. */
|
|
131
|
+
readonly scenes: S;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Build a headless stand-in for the React `GameContextValue` for loop-harness
|
|
135
|
+
* tests. It is `createTestWorld(options)` plus the same `camera`, `input` and
|
|
136
|
+
* `assets` members `GameView` constructs (`audio`, `renderer` and `batch` are
|
|
137
|
+
* omitted — they need a platform), a permissive `sheet`, and a caller-supplied
|
|
138
|
+
* `scenes` slot. Nothing here imports React Native or Skia.
|
|
139
|
+
*
|
|
140
|
+
* Mirrors `GameView`'s frame wiring: `loop.onLateUpdate` runs
|
|
141
|
+
* `camera.update(dt)` then `input.update()`, so a `camera.shake()` moves
|
|
142
|
+
* `effectiveX` / `effectiveY` and a tapped pointer's `justPressed` clears once
|
|
143
|
+
* frames are stepped. `world`, `loop`, `clock`, `step` and `stepFrames` are the
|
|
144
|
+
* test world's own.
|
|
145
|
+
*/
|
|
146
|
+
export declare function createHeadlessContext(options?: CreateHeadlessContextOptions): HeadlessContext;
|
|
147
|
+
export declare function createHeadlessContext<S>(options: CreateHeadlessContextOptions<S> & {
|
|
148
|
+
scenes: S;
|
|
149
|
+
}): HeadlessContext<S>;
|
|
150
|
+
/**
|
|
151
|
+
* A single entity in a snapshot. Component names come from `ComponentDef.name`.
|
|
152
|
+
*/
|
|
153
|
+
interface SceneSnapshotEntity {
|
|
154
|
+
id: number;
|
|
155
|
+
components: Record<string, unknown>;
|
|
156
|
+
}
|
|
157
|
+
interface SceneSnapshot {
|
|
158
|
+
entities: SceneSnapshotEntity[];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Serialize every entity that has at least one of the supplied components into
|
|
162
|
+
* a stable, deterministic snapshot. Entities are sorted by id; component keys
|
|
163
|
+
* are inserted in the order the components are passed.
|
|
164
|
+
*/
|
|
165
|
+
export declare function serializeScene(world: World, components: readonly ComponentDef<unknown>[]): SceneSnapshot;
|
|
166
|
+
/**
|
|
167
|
+
* Deep-equal comparison good enough for snapshot assertions. Compares plain
|
|
168
|
+
* objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.
|
|
169
|
+
*/
|
|
170
|
+
export declare function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean;
|
|
171
|
+
export type { BenchSession, BenchSessionOptions, CreateHeadlessContextOptions, CreateTestWorldOptions, FakeClock, HeadlessContext, SceneSnapshot, SceneSnapshotEntity, SnapshotProjector, SnapshotSchema, TestWorld };
|
|
119
172
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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/
|
|
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/test-world.ts","../src/headless-context.ts","../src/scene-snapshot.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;UCvBzB;;WAEN,OAAO;;WAEP,MAAM;;WAEN,OAAO;;EAEhB,KAAK;;EAEL,WAAW,gBAAgB;;UAGZ;;EAEf;;EAEA;;;;;;;;wBASc,gBAAgB,UAAS,yBAA8B;UCzBtD,6BAA6B,uBAAuB;;;;;;;EAOnE;;EAEA;;;;;;;EAOA,SAAS;;UAGM,gBAAgB,uBAAuB;;WAE7C,QAAQ;;WAER,OAAO;;WAEP,QAAQ;;;;;;WAMR,OAAO;;WAEP,QAAQ;;;;;;;;;;;;;;;wBA6BH,sBAAsB,UAAU,+BAA+B;wBAC/D,sBAAsB,GACpC,SAAS,6BAA6B;EAAO,QAAQ;IACpD,gBAAgB;;;;UC5CF;EACf;EACA,YAAY;;UAGG;EACf,UAAU;;;;;;;wBAQI,eACd,OAAO,OACP,qBAAqB,0BACpB;;;;;wBAyBa,eAAe,GAAG,eAAe,GAAG"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _flare_engine_math = require("@flare-engine/math");
|
|
3
|
+
let _flare_engine_assets = require("@flare-engine/assets");
|
|
4
|
+
let _flare_engine_render = require("@flare-engine/render");
|
|
3
5
|
let _flare_engine_input = require("@flare-engine/input");
|
|
4
6
|
let _flare_engine_core = require("@flare-engine/core");
|
|
5
7
|
let _flare_engine_ecs = require("@flare-engine/ecs");
|
|
@@ -128,6 +130,73 @@ var MockInputManager = class extends _flare_engine_input.InputManager {
|
|
|
128
130
|
function createMockInputManager() {
|
|
129
131
|
return new MockInputManager();
|
|
130
132
|
}
|
|
133
|
+
// src/test-world.ts
|
|
134
|
+
/**
|
|
135
|
+
* Create a World + GameLoop + FakeClock wired together for deterministic
|
|
136
|
+
* testing. `step()` calls the loop's `step()` directly so fixed and variable
|
|
137
|
+
* updates fire for the exact dt you pass, without needing to start the rAF
|
|
138
|
+
* loop.
|
|
139
|
+
*/
|
|
140
|
+
function createTestWorld(options = {}) {
|
|
141
|
+
const world = new _flare_engine_ecs.World();
|
|
142
|
+
const loop = new _flare_engine_core.GameLoop(options);
|
|
143
|
+
const clock = createFakeClock();
|
|
144
|
+
loop.tick = clock.requestFrame;
|
|
145
|
+
loop.cancelTick = clock.cancelFrame;
|
|
146
|
+
return {
|
|
147
|
+
world,
|
|
148
|
+
loop,
|
|
149
|
+
clock,
|
|
150
|
+
step(dt) {
|
|
151
|
+
loop.step(dt);
|
|
152
|
+
},
|
|
153
|
+
stepFrames(frames, dt = 1 / 60) {
|
|
154
|
+
for (let i = 0; i < frames; i++) loop.step(dt);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// src/headless-context.ts
|
|
159
|
+
const noopLoader = () => Promise.resolve(null);
|
|
160
|
+
function createPermissiveSheet() {
|
|
161
|
+
const frameMap = /* @__PURE__ */ new Map();
|
|
162
|
+
frameMap.get = () => 0;
|
|
163
|
+
frameMap.has = () => true;
|
|
164
|
+
return {
|
|
165
|
+
frames: [{
|
|
166
|
+
name: "headless",
|
|
167
|
+
x: 0,
|
|
168
|
+
y: 0,
|
|
169
|
+
w: 8,
|
|
170
|
+
h: 8
|
|
171
|
+
}],
|
|
172
|
+
frameMap,
|
|
173
|
+
animations: /* @__PURE__ */ new Map()
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function createHeadlessContext(options = {}) {
|
|
177
|
+
const { viewportWidth, viewportHeight } = options;
|
|
178
|
+
if (viewportWidth === void 0 !== (viewportHeight === void 0)) throw new RangeError("[@flare-engine/testing] viewportWidth and viewportHeight must be given together");
|
|
179
|
+
const testWorld = createTestWorld({
|
|
180
|
+
fixedDt: options.fixedDt,
|
|
181
|
+
maxDt: options.maxDt
|
|
182
|
+
});
|
|
183
|
+
const camera = new _flare_engine_render.Camera2D();
|
|
184
|
+
if (viewportWidth !== void 0 && viewportHeight !== void 0) camera.setViewport(viewportWidth, viewportHeight);
|
|
185
|
+
const input = createMockInputManager();
|
|
186
|
+
const assets = new _flare_engine_assets.AssetManager(noopLoader);
|
|
187
|
+
testWorld.loop.onLateUpdate.add((dt) => {
|
|
188
|
+
camera.update(dt);
|
|
189
|
+
input.update();
|
|
190
|
+
});
|
|
191
|
+
return {
|
|
192
|
+
...testWorld,
|
|
193
|
+
camera,
|
|
194
|
+
input,
|
|
195
|
+
assets,
|
|
196
|
+
sheet: createPermissiveSheet(),
|
|
197
|
+
scenes: options.scenes
|
|
198
|
+
};
|
|
199
|
+
}
|
|
131
200
|
// src/scene-snapshot.ts
|
|
132
201
|
const singletonQueries = /* @__PURE__ */ new WeakMap();
|
|
133
202
|
function singletonQuery(world, def) {
|
|
@@ -193,34 +262,10 @@ function deepEqual(a, b) {
|
|
|
193
262
|
}
|
|
194
263
|
return false;
|
|
195
264
|
}
|
|
196
|
-
// src/test-world.ts
|
|
197
|
-
/**
|
|
198
|
-
* Create a World + GameLoop + FakeClock wired together for deterministic
|
|
199
|
-
* testing. `step()` calls the loop's `step()` directly so fixed and variable
|
|
200
|
-
* updates fire for the exact dt you pass, without needing to start the rAF
|
|
201
|
-
* loop.
|
|
202
|
-
*/
|
|
203
|
-
function createTestWorld(options = {}) {
|
|
204
|
-
const world = new _flare_engine_ecs.World();
|
|
205
|
-
const loop = new _flare_engine_core.GameLoop(options);
|
|
206
|
-
const clock = createFakeClock();
|
|
207
|
-
loop.tick = clock.requestFrame;
|
|
208
|
-
loop.cancelTick = clock.cancelFrame;
|
|
209
|
-
return {
|
|
210
|
-
world,
|
|
211
|
-
loop,
|
|
212
|
-
clock,
|
|
213
|
-
step(dt) {
|
|
214
|
-
loop.step(dt);
|
|
215
|
-
},
|
|
216
|
-
stepFrames(frames, dt = 1 / 60) {
|
|
217
|
-
for (let i = 0; i < frames; i++) loop.step(dt);
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
265
|
exports.MockInputManager = MockInputManager;
|
|
222
266
|
exports.createBenchSession = createBenchSession;
|
|
223
267
|
exports.createFakeClock = createFakeClock;
|
|
268
|
+
exports.createHeadlessContext = createHeadlessContext;
|
|
224
269
|
exports.createMockInputManager = createMockInputManager;
|
|
225
270
|
exports.createTestWorld = createTestWorld;
|
|
226
271
|
exports.defineSnapshot = defineSnapshot;
|
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;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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;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,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"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["SeededRNG","InputManager","World","GameLoop","Camera2D","AssetManager"],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/test-world.ts","../src/headless-context.ts","../src/scene-snapshot.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 { 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","import { type AssetLoader, AssetManager, type SpriteSheet } from '@flare-engine/assets';\nimport { Camera2D } from '@flare-engine/render';\nimport { createMockInputManager, type MockInputManager } from './mock-input.js';\nimport { type CreateTestWorldOptions, createTestWorld, type TestWorld } from './test-world.js';\n\nexport interface CreateHeadlessContextOptions<S = undefined> extends CreateTestWorldOptions {\n /**\n * Viewport width in pixels, forwarded to `camera.setViewport`. Must be given\n * together with `viewportHeight`; one without the other throws a\n * `RangeError`. Omitting both leaves the camera at its `new Camera2D()`\n * default of a 0×0 viewport.\n */\n viewportWidth?: number;\n /** Viewport height in pixels. See `viewportWidth`. */\n viewportHeight?: number;\n /**\n * Value exposed as `scenes` on the context, passed through untouched. The\n * real `GameContextValue` holds a `SceneManager`, but `@flare-engine/scene`\n * is tier 3 and this package is tier 2.5, so the caller builds it (or any\n * stand-in) and hands it over here.\n */\n scenes?: S;\n}\n\nexport interface HeadlessContext<S = undefined> extends TestWorld {\n /** Real `Camera2D`, updated from `loop.onLateUpdate` like `GameView` does. */\n readonly camera: Camera2D;\n /** Scriptable input; `update()` runs from `loop.onLateUpdate` every frame. */\n readonly input: MockInputManager;\n /** Real `AssetManager` with a loader that resolves `null` for every entry. */\n readonly assets: AssetManager;\n /**\n * Permissive sprite sheet: one 8×8 frame named `headless`, and a `frameMap`\n * whose `get` always returns `0` and `has` always returns `true`, so\n * `getFrame(sheet, anyName)` resolves to that frame.\n */\n readonly sheet: SpriteSheet;\n /** Whatever `options.scenes` was; `undefined` when omitted. */\n readonly scenes: S;\n}\n\nconst noopLoader: AssetLoader = () => Promise.resolve(null);\n\nfunction createPermissiveSheet(): SpriteSheet {\n const frameMap = new Map<string, number>();\n frameMap.get = () => 0;\n frameMap.has = () => true;\n return {\n frames: [{ name: 'headless', x: 0, y: 0, w: 8, h: 8 }],\n frameMap,\n animations: new Map(),\n };\n}\n\n/**\n * Build a headless stand-in for the React `GameContextValue` for loop-harness\n * tests. It is `createTestWorld(options)` plus the same `camera`, `input` and\n * `assets` members `GameView` constructs (`audio`, `renderer` and `batch` are\n * omitted — they need a platform), a permissive `sheet`, and a caller-supplied\n * `scenes` slot. Nothing here imports React Native or Skia.\n *\n * Mirrors `GameView`'s frame wiring: `loop.onLateUpdate` runs\n * `camera.update(dt)` then `input.update()`, so a `camera.shake()` moves\n * `effectiveX` / `effectiveY` and a tapped pointer's `justPressed` clears once\n * frames are stepped. `world`, `loop`, `clock`, `step` and `stepFrames` are the\n * test world's own.\n */\nexport function createHeadlessContext(options?: CreateHeadlessContextOptions): HeadlessContext;\nexport function createHeadlessContext<S>(\n options: CreateHeadlessContextOptions<S> & { scenes: S },\n): HeadlessContext<S>;\nexport function createHeadlessContext(\n options: CreateHeadlessContextOptions<unknown> = {},\n): HeadlessContext<unknown> {\n const { viewportWidth, viewportHeight } = options;\n if ((viewportWidth === undefined) !== (viewportHeight === undefined)) {\n throw new RangeError(\n '[@flare-engine/testing] viewportWidth and viewportHeight must be given together',\n );\n }\n\n const testWorld = createTestWorld({ fixedDt: options.fixedDt, maxDt: options.maxDt });\n const camera = new Camera2D();\n if (viewportWidth !== undefined && viewportHeight !== undefined) {\n camera.setViewport(viewportWidth, viewportHeight);\n }\n const input = createMockInputManager();\n const assets = new AssetManager(noopLoader);\n\n testWorld.loop.onLateUpdate.add((dt) => {\n camera.update(dt);\n input.update();\n });\n\n return {\n ...testWorld,\n camera,\n input,\n assets,\n sheet: createPermissiveSheet(),\n scenes: options.scenes,\n };\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"],"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,CA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O,IAAI,CAAC,GAAG,OAAO;GAClC,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,GAAG,OAAO;EACvC;EACA,OAAO;CACT;CACA,OAAO;AACT"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { SeededRNG } from "@flare-engine/math";
|
|
2
|
+
import { AssetManager } from "@flare-engine/assets";
|
|
3
|
+
import { Camera2D } from "@flare-engine/render";
|
|
2
4
|
import { InputManager } from "@flare-engine/input";
|
|
3
5
|
import { GameLoop } from "@flare-engine/core";
|
|
4
6
|
import { World } from "@flare-engine/ecs";
|
|
@@ -127,6 +129,73 @@ var MockInputManager = class extends InputManager {
|
|
|
127
129
|
function createMockInputManager() {
|
|
128
130
|
return new MockInputManager();
|
|
129
131
|
}
|
|
132
|
+
// src/test-world.ts
|
|
133
|
+
/**
|
|
134
|
+
* Create a World + GameLoop + FakeClock wired together for deterministic
|
|
135
|
+
* testing. `step()` calls the loop's `step()` directly so fixed and variable
|
|
136
|
+
* updates fire for the exact dt you pass, without needing to start the rAF
|
|
137
|
+
* loop.
|
|
138
|
+
*/
|
|
139
|
+
function createTestWorld(options = {}) {
|
|
140
|
+
const world = new World();
|
|
141
|
+
const loop = new GameLoop(options);
|
|
142
|
+
const clock = createFakeClock();
|
|
143
|
+
loop.tick = clock.requestFrame;
|
|
144
|
+
loop.cancelTick = clock.cancelFrame;
|
|
145
|
+
return {
|
|
146
|
+
world,
|
|
147
|
+
loop,
|
|
148
|
+
clock,
|
|
149
|
+
step(dt) {
|
|
150
|
+
loop.step(dt);
|
|
151
|
+
},
|
|
152
|
+
stepFrames(frames, dt = 1 / 60) {
|
|
153
|
+
for (let i = 0; i < frames; i++) loop.step(dt);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
// src/headless-context.ts
|
|
158
|
+
const noopLoader = () => Promise.resolve(null);
|
|
159
|
+
function createPermissiveSheet() {
|
|
160
|
+
const frameMap = /* @__PURE__ */ new Map();
|
|
161
|
+
frameMap.get = () => 0;
|
|
162
|
+
frameMap.has = () => true;
|
|
163
|
+
return {
|
|
164
|
+
frames: [{
|
|
165
|
+
name: "headless",
|
|
166
|
+
x: 0,
|
|
167
|
+
y: 0,
|
|
168
|
+
w: 8,
|
|
169
|
+
h: 8
|
|
170
|
+
}],
|
|
171
|
+
frameMap,
|
|
172
|
+
animations: /* @__PURE__ */ new Map()
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function createHeadlessContext(options = {}) {
|
|
176
|
+
const { viewportWidth, viewportHeight } = options;
|
|
177
|
+
if (viewportWidth === void 0 !== (viewportHeight === void 0)) throw new RangeError("[@flare-engine/testing] viewportWidth and viewportHeight must be given together");
|
|
178
|
+
const testWorld = createTestWorld({
|
|
179
|
+
fixedDt: options.fixedDt,
|
|
180
|
+
maxDt: options.maxDt
|
|
181
|
+
});
|
|
182
|
+
const camera = new Camera2D();
|
|
183
|
+
if (viewportWidth !== void 0 && viewportHeight !== void 0) camera.setViewport(viewportWidth, viewportHeight);
|
|
184
|
+
const input = createMockInputManager();
|
|
185
|
+
const assets = new AssetManager(noopLoader);
|
|
186
|
+
testWorld.loop.onLateUpdate.add((dt) => {
|
|
187
|
+
camera.update(dt);
|
|
188
|
+
input.update();
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
...testWorld,
|
|
192
|
+
camera,
|
|
193
|
+
input,
|
|
194
|
+
assets,
|
|
195
|
+
sheet: createPermissiveSheet(),
|
|
196
|
+
scenes: options.scenes
|
|
197
|
+
};
|
|
198
|
+
}
|
|
130
199
|
// src/scene-snapshot.ts
|
|
131
200
|
const singletonQueries = /* @__PURE__ */ new WeakMap();
|
|
132
201
|
function singletonQuery(world, def) {
|
|
@@ -192,31 +261,6 @@ function deepEqual(a, b) {
|
|
|
192
261
|
}
|
|
193
262
|
return false;
|
|
194
263
|
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Create a World + GameLoop + FakeClock wired together for deterministic
|
|
198
|
-
* testing. `step()` calls the loop's `step()` directly so fixed and variable
|
|
199
|
-
* updates fire for the exact dt you pass, without needing to start the rAF
|
|
200
|
-
* loop.
|
|
201
|
-
*/
|
|
202
|
-
function createTestWorld(options = {}) {
|
|
203
|
-
const world = new World();
|
|
204
|
-
const loop = new GameLoop(options);
|
|
205
|
-
const clock = createFakeClock();
|
|
206
|
-
loop.tick = clock.requestFrame;
|
|
207
|
-
loop.cancelTick = clock.cancelFrame;
|
|
208
|
-
return {
|
|
209
|
-
world,
|
|
210
|
-
loop,
|
|
211
|
-
clock,
|
|
212
|
-
step(dt) {
|
|
213
|
-
loop.step(dt);
|
|
214
|
-
},
|
|
215
|
-
stepFrames(frames, dt = 1 / 60) {
|
|
216
|
-
for (let i = 0; i < frames; i++) loop.step(dt);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
export { MockInputManager, createBenchSession, createFakeClock, createMockInputManager, createTestWorld, defineSnapshot, serializeScene, snapshotsEqual };
|
|
264
|
+
export { MockInputManager, createBenchSession, createFakeClock, createHeadlessContext, createMockInputManager, createTestWorld, defineSnapshot, serializeScene, snapshotsEqual };
|
|
221
265
|
|
|
222
266
|
//# 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;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,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,eACd,QACmE;CAEnE,MAAM,wBAAQ,IAAI,QAAwB;CAC1C,MAAM,OAAO,OAAO,KAAK,MAAM;CAE/B,QAAQ,UAAiB;EACvB,IAAI,UAAU,MAAM,IAAI,KAAK;EAC7B,IAAI,YAAY,KAAA,GAAW;GACzB,UAAU,KAAK,KAAK,QAAQ;IAC1B,MAAM,YAAY,OAAO;IACzB,OAAO,MAAM,MAAM,GAAI,UAAU,KAAiC;GACpE,CAAC;GACD,MAAM,IAAI,OAAO,OAAO;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CAClC,IAAI,MAAM,QAAQ,MAAM,MAAM,OAAO;CACrC,IAAI,MAAM,QAAQ,CAAC,GAAG;EACpB,IAAI,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,OAAO;EACvD,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAC5B,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO;EAErC,OAAO;CACT;CACA,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;EAClD,MAAM,KAAK;EACX,MAAM,KAAK;EACX,MAAM,KAAK,OAAO,KAAK,EAAE;EACzB,MAAM,KAAK,OAAO,KAAK,EAAE;EACzB,IAAI,GAAG,WAAW,GAAG,QAAQ,OAAO;EACpC,KAAK,MAAM,KAAK,IAAI;GAClB,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"}
|
|
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/test-world.ts","../src/headless-context.ts","../src/scene-snapshot.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 { 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","import { type AssetLoader, AssetManager, type SpriteSheet } from '@flare-engine/assets';\nimport { Camera2D } from '@flare-engine/render';\nimport { createMockInputManager, type MockInputManager } from './mock-input.js';\nimport { type CreateTestWorldOptions, createTestWorld, type TestWorld } from './test-world.js';\n\nexport interface CreateHeadlessContextOptions<S = undefined> extends CreateTestWorldOptions {\n /**\n * Viewport width in pixels, forwarded to `camera.setViewport`. Must be given\n * together with `viewportHeight`; one without the other throws a\n * `RangeError`. Omitting both leaves the camera at its `new Camera2D()`\n * default of a 0×0 viewport.\n */\n viewportWidth?: number;\n /** Viewport height in pixels. See `viewportWidth`. */\n viewportHeight?: number;\n /**\n * Value exposed as `scenes` on the context, passed through untouched. The\n * real `GameContextValue` holds a `SceneManager`, but `@flare-engine/scene`\n * is tier 3 and this package is tier 2.5, so the caller builds it (or any\n * stand-in) and hands it over here.\n */\n scenes?: S;\n}\n\nexport interface HeadlessContext<S = undefined> extends TestWorld {\n /** Real `Camera2D`, updated from `loop.onLateUpdate` like `GameView` does. */\n readonly camera: Camera2D;\n /** Scriptable input; `update()` runs from `loop.onLateUpdate` every frame. */\n readonly input: MockInputManager;\n /** Real `AssetManager` with a loader that resolves `null` for every entry. */\n readonly assets: AssetManager;\n /**\n * Permissive sprite sheet: one 8×8 frame named `headless`, and a `frameMap`\n * whose `get` always returns `0` and `has` always returns `true`, so\n * `getFrame(sheet, anyName)` resolves to that frame.\n */\n readonly sheet: SpriteSheet;\n /** Whatever `options.scenes` was; `undefined` when omitted. */\n readonly scenes: S;\n}\n\nconst noopLoader: AssetLoader = () => Promise.resolve(null);\n\nfunction createPermissiveSheet(): SpriteSheet {\n const frameMap = new Map<string, number>();\n frameMap.get = () => 0;\n frameMap.has = () => true;\n return {\n frames: [{ name: 'headless', x: 0, y: 0, w: 8, h: 8 }],\n frameMap,\n animations: new Map(),\n };\n}\n\n/**\n * Build a headless stand-in for the React `GameContextValue` for loop-harness\n * tests. It is `createTestWorld(options)` plus the same `camera`, `input` and\n * `assets` members `GameView` constructs (`audio`, `renderer` and `batch` are\n * omitted — they need a platform), a permissive `sheet`, and a caller-supplied\n * `scenes` slot. Nothing here imports React Native or Skia.\n *\n * Mirrors `GameView`'s frame wiring: `loop.onLateUpdate` runs\n * `camera.update(dt)` then `input.update()`, so a `camera.shake()` moves\n * `effectiveX` / `effectiveY` and a tapped pointer's `justPressed` clears once\n * frames are stepped. `world`, `loop`, `clock`, `step` and `stepFrames` are the\n * test world's own.\n */\nexport function createHeadlessContext(options?: CreateHeadlessContextOptions): HeadlessContext;\nexport function createHeadlessContext<S>(\n options: CreateHeadlessContextOptions<S> & { scenes: S },\n): HeadlessContext<S>;\nexport function createHeadlessContext(\n options: CreateHeadlessContextOptions<unknown> = {},\n): HeadlessContext<unknown> {\n const { viewportWidth, viewportHeight } = options;\n if ((viewportWidth === undefined) !== (viewportHeight === undefined)) {\n throw new RangeError(\n '[@flare-engine/testing] viewportWidth and viewportHeight must be given together',\n );\n }\n\n const testWorld = createTestWorld({ fixedDt: options.fixedDt, maxDt: options.maxDt });\n const camera = new Camera2D();\n if (viewportWidth !== undefined && viewportHeight !== undefined) {\n camera.setViewport(viewportWidth, viewportHeight);\n }\n const input = createMockInputManager();\n const assets = new AssetManager(noopLoader);\n\n testWorld.loop.onLateUpdate.add((dt) => {\n camera.update(dt);\n input.update();\n });\n\n return {\n ...testWorld,\n camera,\n input,\n assets,\n sheet: createPermissiveSheet(),\n scenes: options.scenes,\n };\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"],"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,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,eACd,QACmE;CAEnE,MAAM,wBAAQ,IAAI,QAAwB;CAC1C,MAAM,OAAO,OAAO,KAAK,MAAM;CAE/B,QAAQ,UAAiB;EACvB,IAAI,UAAU,MAAM,IAAI,KAAK;EAC7B,IAAI,YAAY,KAAA,GAAW;GACzB,UAAU,KAAK,KAAK,QAAQ;IAC1B,MAAM,YAAY,OAAO;IACzB,OAAO,MAAM,MAAM,GAAI,UAAU,KAAiC;GACpE,CAAC;GACD,MAAM,IAAI,OAAO,OAAO;EAC1B;EAEA,MAAM,SAA6C,CAAC;EACpD,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MAAM,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AI,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,OAAO;EACvD,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAC5B,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO;EAErC,OAAO;CACT;CACA,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;EAClD,MAAM,KAAK;EACX,MAAM,KAAK;EACX,MAAM,KAAK,OAAO,KAAK,EAAE;EACzB,MAAM,KAAK,OAAO,KAAK,EAAE;EACzB,IAAI,GAAG,WAAW,GAAG,QAAQ,OAAO;EACpC,KAAK,MAAM,KAAK,IAAI;GAClB,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"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flare-engine/testing",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.10",
|
|
4
4
|
"description": "Deterministic World factory, fake Clock, mock InputManager, and scene snapshot helpers",
|
|
5
|
-
"keywords": ["flare-engine", "testing", "ecs", "fake-clock", "snapshot"],
|
|
5
|
+
"keywords": ["flare-engine", "testing", "ecs", "fake-clock", "snapshot", "typescript"],
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"author": "Grzegorz Otto",
|
|
8
8
|
"homepage": "https://github.com/grzott/flare-engine#readme",
|
|
@@ -37,10 +37,12 @@
|
|
|
37
37
|
"typecheck": "tsc --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@flare-engine/
|
|
41
|
-
"@flare-engine/
|
|
42
|
-
"@flare-engine/
|
|
43
|
-
"@flare-engine/
|
|
40
|
+
"@flare-engine/assets": "^0.4.10",
|
|
41
|
+
"@flare-engine/core": "^0.4.10",
|
|
42
|
+
"@flare-engine/ecs": "^0.4.10",
|
|
43
|
+
"@flare-engine/input": "^0.4.10",
|
|
44
|
+
"@flare-engine/math": "^0.4.10",
|
|
45
|
+
"@flare-engine/render": "^0.4.10"
|
|
44
46
|
},
|
|
45
47
|
"engines": {
|
|
46
48
|
"node": ">=20"
|