@flare-engine/testing 0.2.1 → 0.3.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/LICENSE +201 -21
- package/NOTICE +2 -0
- package/README.md +5 -3
- package/dist/index.d.mts +87 -83
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +87 -83
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +221 -229
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +211 -193
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { InputManager } from
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { SeededRNG } from "@flare-engine/math";
|
|
2
|
+
import { ComponentDef, World } from "@flare-engine/ecs";
|
|
3
|
+
import { InputManager } from "@flare-engine/input";
|
|
4
|
+
import { GameLoop } from "@flare-engine/core";
|
|
5
|
+
//#region src/bench-session.d.ts
|
|
6
|
+
interface BenchSessionOptions {
|
|
7
|
+
seed?: number;
|
|
8
|
+
}
|
|
9
|
+
interface BenchSession {
|
|
10
|
+
readonly rng: SeededRNG;
|
|
11
|
+
setFlag(name: string, value: boolean): void;
|
|
12
|
+
getFlag(name: string): boolean;
|
|
13
|
+
/** Resolves whenDone. Idempotent — safe to call multiple times. */
|
|
14
|
+
done(): void;
|
|
15
|
+
readonly whenDone: Promise<void>;
|
|
16
|
+
/** Restores Math.random. Idempotent. */
|
|
17
|
+
end(): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a deterministic bench session. Installs a SeededRNG-backed Math.random.
|
|
21
|
+
*
|
|
22
|
+
* Sessions must be ended LIFO if nested. Callers should wrap usage in try/finally
|
|
23
|
+
* so a throw between install and end() cannot leak the patched Math.random.
|
|
24
|
+
*/
|
|
25
|
+
declare function createBenchSession(opts?: BenchSessionOptions): BenchSession;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/define-snapshot.d.ts
|
|
28
|
+
interface SnapshotProjector {
|
|
29
|
+
readonly query: readonly ComponentDef<unknown>[];
|
|
30
|
+
project(world: World, id: number): unknown;
|
|
31
|
+
}
|
|
32
|
+
interface SnapshotSchema {
|
|
33
|
+
readonly [key: string]: SnapshotProjector;
|
|
34
|
+
}
|
|
35
|
+
declare function defineSnapshot<S extends SnapshotSchema>(schema: S): (world: World) => { readonly [K in keyof S]: readonly unknown[]; };
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/fake-clock.d.ts
|
|
6
38
|
/**
|
|
7
39
|
* Fake monotonic clock for driving `GameLoop` deterministically in tests.
|
|
8
40
|
*
|
|
@@ -14,71 +46,47 @@ import { SeededRNG } from '@flare-engine/math';
|
|
|
14
46
|
* fake.advance(1 / 60); // runs one frame
|
|
15
47
|
*/
|
|
16
48
|
interface FakeClock {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
49
|
+
/** Current fake timestamp in milliseconds. */
|
|
50
|
+
readonly now: number;
|
|
51
|
+
/** rAF-compatible request — stores the callback for the next `advance`. */
|
|
52
|
+
requestFrame(callback: (time: number) => void): number;
|
|
53
|
+
/** rAF-compatible cancel. */
|
|
54
|
+
cancelFrame(id: number): void;
|
|
55
|
+
/** Advance time by `seconds` and fire every pending callback once. */
|
|
56
|
+
advance(seconds: number): void;
|
|
57
|
+
/** Reset time and cancel all pending callbacks. */
|
|
58
|
+
reset(): void;
|
|
27
59
|
}
|
|
28
60
|
declare function createFakeClock(): FakeClock;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/** ECS world. */
|
|
32
|
-
readonly world: World;
|
|
33
|
-
/** Game loop wired to a fake clock. */
|
|
34
|
-
readonly loop: GameLoop;
|
|
35
|
-
/** Fake clock driving the loop. */
|
|
36
|
-
readonly clock: FakeClock;
|
|
37
|
-
/** Advance one frame of `dt` seconds. Runs the loop's fixed + variable update. */
|
|
38
|
-
step(dt: number): void;
|
|
39
|
-
/** Advance `frames` frames of `dt` seconds each. */
|
|
40
|
-
stepFrames(frames: number, dt?: number): void;
|
|
41
|
-
}
|
|
42
|
-
interface CreateTestWorldOptions {
|
|
43
|
-
/** Fixed timestep passed to `GameLoop`. Defaults to 1/60. */
|
|
44
|
-
fixedDt?: number;
|
|
45
|
-
/** Maximum raw dt cap passed to `GameLoop`. Defaults to 0.25s. */
|
|
46
|
-
maxDt?: number;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Create a World + GameLoop + FakeClock wired together for deterministic
|
|
50
|
-
* testing. `step()` calls the loop's `step()` directly so fixed and variable
|
|
51
|
-
* updates fire for the exact dt you pass, without needing to start the rAF
|
|
52
|
-
* loop.
|
|
53
|
-
*/
|
|
54
|
-
declare function createTestWorld(options?: CreateTestWorldOptions): TestWorld;
|
|
55
|
-
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/mock-input.d.ts
|
|
56
63
|
/**
|
|
57
64
|
* `InputManager` subclass with scripted helpers for tests. Drives the same
|
|
58
65
|
* internal state the real manager uses, so any system reading
|
|
59
66
|
* `.pointer` / `.touches` sees identical data.
|
|
60
67
|
*/
|
|
61
68
|
declare class MockInputManager extends InputManager {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
/** Press a pointer at `(x, y)`. `id` defaults to 0 (primary). */
|
|
70
|
+
press(x: number, y: number, id?: number): void;
|
|
71
|
+
/** Move a pointer to `(x, y)`. */
|
|
72
|
+
move(x: number, y: number, id?: number): void;
|
|
73
|
+
/** Release a pointer at `(x, y)`. */
|
|
74
|
+
release(x: number, y: number, id?: number): void;
|
|
75
|
+
/** Full tap: press → release in one call. */
|
|
76
|
+
tap(x: number, y: number, id?: number): void;
|
|
70
77
|
}
|
|
71
78
|
declare function createMockInputManager(): MockInputManager;
|
|
72
|
-
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/scene-snapshot.d.ts
|
|
73
81
|
/**
|
|
74
82
|
* A single entity in a snapshot. Component names come from `ComponentDef.name`.
|
|
75
83
|
*/
|
|
76
84
|
interface SceneSnapshotEntity {
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
id: number;
|
|
86
|
+
components: Record<string, unknown>;
|
|
79
87
|
}
|
|
80
88
|
interface SceneSnapshot {
|
|
81
|
-
|
|
89
|
+
entities: SceneSnapshotEntity[];
|
|
82
90
|
}
|
|
83
91
|
/**
|
|
84
92
|
* Serialize every entity that has at least one of the supplied components into
|
|
@@ -91,37 +99,33 @@ declare function serializeScene(world: World, components: readonly ComponentDef<
|
|
|
91
99
|
* objects, arrays, and primitives — no Date, Map, Set, or cyclic graphs.
|
|
92
100
|
*/
|
|
93
101
|
declare function snapshotsEqual(a: SceneSnapshot, b: SceneSnapshot): boolean;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/test-world.d.ts
|
|
104
|
+
interface TestWorld {
|
|
105
|
+
/** ECS world. */
|
|
106
|
+
readonly world: World;
|
|
107
|
+
/** Game loop wired to a fake clock. */
|
|
108
|
+
readonly loop: GameLoop;
|
|
109
|
+
/** Fake clock driving the loop. */
|
|
110
|
+
readonly clock: FakeClock;
|
|
111
|
+
/** Advance one frame of `dt` seconds. Runs the loop's fixed + variable update. */
|
|
112
|
+
step(dt: number): void;
|
|
113
|
+
/** Advance `frames` frames of `dt` seconds each. */
|
|
114
|
+
stepFrames(frames: number, dt?: number): void;
|
|
97
115
|
}
|
|
98
|
-
interface
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
done(): void;
|
|
104
|
-
readonly whenDone: Promise<void>;
|
|
105
|
-
/** Restores Math.random. Idempotent. */
|
|
106
|
-
end(): void;
|
|
116
|
+
interface CreateTestWorldOptions {
|
|
117
|
+
/** Fixed timestep passed to `GameLoop`. Defaults to 1/60. */
|
|
118
|
+
fixedDt?: number;
|
|
119
|
+
/** Maximum raw dt cap passed to `GameLoop`. Defaults to 0.25s. */
|
|
120
|
+
maxDt?: number;
|
|
107
121
|
}
|
|
108
122
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
123
|
+
* Create a World + GameLoop + FakeClock wired together for deterministic
|
|
124
|
+
* testing. `step()` calls the loop's `step()` directly so fixed and variable
|
|
125
|
+
* updates fire for the exact dt you pass, without needing to start the rAF
|
|
126
|
+
* loop.
|
|
113
127
|
*/
|
|
114
|
-
declare function
|
|
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
|
-
|
|
128
|
+
declare function createTestWorld(options?: CreateTestWorldOptions): TestWorld;
|
|
129
|
+
//#endregion
|
|
127
130
|
export { type BenchSession, type BenchSessionOptions, type CreateTestWorldOptions, type FakeClock, MockInputManager, type SceneSnapshot, type SceneSnapshotEntity, type SnapshotProjector, type SnapshotSchema, type TestWorld, createBenchSession, createFakeClock, createMockInputManager, createTestWorld, defineSnapshot, serializeScene, snapshotsEqual };
|
|
131
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/bench-session.ts","../src/define-snapshot.ts","../src/fake-clock.ts","../src/mock-input.ts","../src/scene-snapshot.ts","../src/test-world.ts"],"mappings":";;;;;UAGiB;EACf;;UAGe;WACN,KAAK;EACd,QAAQ,cAAc;EACtB,QAAQ;;EAER;WACS,UAAU;;EAEnB;;;;;;;;iBASc,mBAAmB,OAAM,sBAA2B;;;UCtBnD;WACN,gBAAgB;EACzB,QAAQ,OAAO,OAAO;;UAGP;YACL,cAAc;;iBAGV,eAAe,UAAU,gBACvC,QAAQ,KACN,OAAO,sBAAsB,WAAW;;;;;;;;;;;;;UCH3B;;WAEN;;EAET,aAAa,WAAW;;EAExB,YAAY;;EAEZ,QAAQ;;EAER;;iBAGc,mBAAmB;;;;;;;;cChBtB,yBAAyB;;EAEpC,MAAM,WAAW,WAAW;;EAI5B,KAAK,WAAW,WAAW;;EAI3B,QAAQ,WAAW,WAAW;;EAI9B,IAAI,WAAW,WAAW;;iBAMZ,0BAA0B;;;;;;UCDzB;EACf;EACA,YAAY;;UAGG;EACf,UAAU;;;;;;;iBAQI,eACd,OAAO,OACP,qBAAqB,0BACpB;;;;;iBAyBa,eAAe,GAAG,eAAe,GAAG;;;UChEnC;;WAEN,OAAO;;WAEP,MAAM;;WAEN,OAAO;;EAEhB,KAAK;;EAEL,WAAW,gBAAgB;;UAGZ;;EAEf;;EAEA;;;;;;;;iBASc,gBAAgB,UAAS,yBAA8B"}
|