@moku-labs/game 0.15.31 → 0.15.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/page.mjs +16 -1
- package/dist/app.mjs +1 -1
- package/dist/{fake-6mazmHK3.mjs → fake-hnJcJeYf.mjs} +7 -1
- package/dist/testing.mjs +1 -1
- package/dist/{visual-HGn_TF2x.d.mts → visual-DEo5Hndx.d.mts} +12 -5
- package/dist/visual.d.mts +1 -1
- package/dist/visual.mjs +90 -29
- package/llms.txt +1 -1
- package/package.json +1 -1
package/dist/app/page.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { r as systemSource, t as memory } from "../memory-CWlqhS7l.mjs";
|
|
2
2
|
import { t as applyTo } from "../drafts-BawpSaVp.mjs";
|
|
3
3
|
import { i as isControl } from "../dev-BNndV-hU.mjs";
|
|
4
|
+
import { n as fakeClock, t as VISUAL_CLOCK } from "../fake-hnJcJeYf.mjs";
|
|
4
5
|
import { n as read, r as watch, t as sources } from "../sources-DM5Zcl4o.mjs";
|
|
5
6
|
import { t as resolveConfig } from "../config-B87aFTW-.mjs";
|
|
6
7
|
//#region src/app/save.ts
|
|
@@ -211,6 +212,20 @@ function toError(thrown) {
|
|
|
211
212
|
return thrown instanceof Error ? thrown : new Error(String(thrown));
|
|
212
213
|
}
|
|
213
214
|
/**
|
|
215
|
+
* The clock of the page: the device clock; on a dev page a visual test's pixel leg opened, the fake
|
|
216
|
+
* clock its headless leg runs on, standing at the same moment (F86). The leg puts the moment on the
|
|
217
|
+
* page before it loads, so the app never sees the device time.
|
|
218
|
+
*
|
|
219
|
+
* @returns The clock source of the page.
|
|
220
|
+
*/
|
|
221
|
+
function pageClock() {
|
|
222
|
+
if (typeof __MOKU_GAME_DEV__ !== "undefined" && __MOKU_GAME_DEV__) {
|
|
223
|
+
const moment = Reflect.get(globalThis, VISUAL_CLOCK);
|
|
224
|
+
if (typeof moment === "number") return fakeClock(moment);
|
|
225
|
+
}
|
|
226
|
+
return systemSource();
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
214
229
|
* Picks the start of the page from `?player=`: the named scenario's player and session, at the
|
|
215
230
|
* device time. An unknown name is reported, and the page starts from the starting player.
|
|
216
231
|
*
|
|
@@ -382,7 +397,7 @@ async function startPage(game, config, options = {}) {
|
|
|
382
397
|
const settings = resolveConfig(config);
|
|
383
398
|
const query = new URLSearchParams(location.search);
|
|
384
399
|
const { report, attach } = lateReporter();
|
|
385
|
-
const clock =
|
|
400
|
+
const clock = pageClock();
|
|
386
401
|
const start = scenarioStart(query.get("player"), options.scenarios ?? {}, clock.now(), report);
|
|
387
402
|
const shell = options.system === void 0 ? void 0 : await options.system(settings, report);
|
|
388
403
|
const namespace = settings.native?.identifier ?? "moku-game";
|
package/dist/app.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ft as audioPlugin, H as platformPlugin, i as screen, m as flattenFeatures, t as createApp, wt as effectsPlugin } from "./src-5qdNjLKN.mjs";
|
|
2
2
|
import { t as memory } from "./memory-CWlqhS7l.mjs";
|
|
3
|
-
import { n as
|
|
3
|
+
import { n as fakeClock, r as isFakeClock } from "./fake-hnJcJeYf.mjs";
|
|
4
4
|
//#region src/app/define.ts
|
|
5
5
|
/**
|
|
6
6
|
* The moment the default fake clock starts at, in epoch milliseconds. A test stamps times from it.
|
|
@@ -101,5 +101,11 @@ function fakeClock(start = 0) {
|
|
|
101
101
|
function isFakeClock(source) {
|
|
102
102
|
return fakeClocks.has(source);
|
|
103
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* The global a visual test's pixel leg sets on the dev page before it loads (F86): the moment of
|
|
106
|
+
* the fake clock its headless leg runs on. The page of a dev build then runs on `fakeClock` at
|
|
107
|
+
* that moment, so both legs see the same `clock.now()`. Not in the root.
|
|
108
|
+
*/
|
|
109
|
+
const VISUAL_CLOCK = "__mokuVisualClock";
|
|
104
110
|
//#endregion
|
|
105
|
-
export {
|
|
111
|
+
export { fakeClock as n, isFakeClock as r, VISUAL_CLOCK as t };
|
package/dist/testing.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { en as refuseStart, in as type, m as flattenFeatures, t as createApp, tn as exit } from "./src-5qdNjLKN.mjs";
|
|
2
2
|
import { n as saveOf, t as memory } from "./memory-CWlqhS7l.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { n as fakeClock } from "./fake-hnJcJeYf.mjs";
|
|
4
4
|
import { i as stepFrames, r as runRepro, t as createHeadless } from "./headless-Bxxl_mQX.mjs";
|
|
5
5
|
//#region src/testing/fake-fx.ts
|
|
6
6
|
/** The node path a refused `fx.start` names when the test gives none. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Vr as Api$3, Y as Api, nn as Api$1, wr as Api$2 } from "./types-D27I4Q7b.mjs";
|
|
1
|
+
import { Vr as Api$3, Y as Api, nn as Api$1, vr as Api$4, wr as Api$2 } from "./types-D27I4Q7b.mjs";
|
|
2
2
|
import { P as AnimApi, r as UiApi } from "./types-DHamyZq1.mjs";
|
|
3
3
|
import { N as InputApi } from "./types-BAp9HdR4.mjs";
|
|
4
4
|
import { r as Repro } from "./headless-f31cEZ7f.mjs";
|
|
@@ -32,7 +32,9 @@ type StepCommand = Exclude<keyof Catalogue, "bookmark" | "capture" | "debug">;
|
|
|
32
32
|
type VisualStart = Omit<Repro, "route">;
|
|
33
33
|
/**
|
|
34
34
|
* One step of a visual test: a `/control` command by its short name with that command's input,
|
|
35
|
-
* typed from the catalogue, or a checkpoint by its name.
|
|
35
|
+
* typed from the catalogue, or a checkpoint by its name. A checkpoint lands every motion
|
|
36
|
+
* (`anim.finishAll()`) before its snapshot; with `finish: false` it does not, and the snapshot
|
|
37
|
+
* shows the motions where they stand after the same frames in both legs (F87).
|
|
36
38
|
*
|
|
37
39
|
* @example
|
|
38
40
|
* ```ts
|
|
@@ -40,12 +42,15 @@ type VisualStart = Omit<Repro, "route">;
|
|
|
40
42
|
* const steps: VisualStep[] = [
|
|
41
43
|
* { tap: { key: "play" } },
|
|
42
44
|
* { answer: { intent: "deliver", payload: { orderId: "o1" } } },
|
|
43
|
-
* { checkpoint: "open" }
|
|
45
|
+
* { checkpoint: "open" },
|
|
46
|
+
* // The hint that fades out at the end of its animation, caught while it still shows.
|
|
47
|
+
* { checkpoint: "hint", finish: false }
|
|
44
48
|
* ];
|
|
45
49
|
* ```
|
|
46
50
|
*/
|
|
47
51
|
type VisualStep = {
|
|
48
52
|
checkpoint: string;
|
|
53
|
+
finish?: boolean;
|
|
49
54
|
} | { [K in StepCommand]: { [P in K]: InputOf<Catalogue[K]["input"]> } }[StepCommand];
|
|
50
55
|
/**
|
|
51
56
|
* A visual test as `defineVisualTest` answers it: its name, where it starts, its steps, and
|
|
@@ -84,7 +89,8 @@ type VisualApp = ControlApp & {
|
|
|
84
89
|
readonly world: Api$1;
|
|
85
90
|
readonly model: Api$2;
|
|
86
91
|
readonly input: InputApi;
|
|
87
|
-
readonly lifecycle: Api$3;
|
|
92
|
+
readonly lifecycle: Api$3; /** The clock: the pixel leg puts its moment on the page, so both legs see one `clock.now()`. */
|
|
93
|
+
readonly clock: Api$4;
|
|
88
94
|
};
|
|
89
95
|
/**
|
|
90
96
|
* The dev page the browser leg opens: its URL, the viewport width in CSS px (390 by default), the
|
|
@@ -254,7 +260,8 @@ type VisualFlags = {
|
|
|
254
260
|
/**
|
|
255
261
|
* Defines a visual test: where it starts, what `game.restore` loads, and its steps. A step is a
|
|
256
262
|
* `/control` command by its short name with that command's input, or `{ checkpoint: name }`,
|
|
257
|
-
* where the runner saves `state.json` and `describe.json` next to the test
|
|
263
|
+
* where the runner lands every motion and saves `state.json` and `describe.json` next to the test;
|
|
264
|
+
* `{ checkpoint: name, finish: false }` keeps the motions running for the snapshot. `walk` runs fast: a
|
|
258
265
|
* popup its last node opens never mounts, so the step before a checkpoint that shows a node's
|
|
259
266
|
* result is `answer` or `tap`. With `webgl: true` the test also runs in the WebGL leg
|
|
260
267
|
* (`--webgl`), whose pictures go to `screen.webgl.webp`: set it on a screen with a custom filter.
|
package/dist/visual.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as VisualApp, c as VisualRenderer, d as VisualStart, f as VisualStep, h as VisualTolerance, i as CheckpointResult, l as VisualReport, m as VisualTestResult, n as runVisualTests, o as VisualOptions, p as VisualTest, r as defineVisualTest, s as VisualPage, t as parseVisualArgv, u as VisualSetup } from "./visual-
|
|
1
|
+
import { a as VisualApp, c as VisualRenderer, d as VisualStart, f as VisualStep, h as VisualTolerance, i as CheckpointResult, l as VisualReport, m as VisualTestResult, n as runVisualTests, o as VisualOptions, p as VisualTest, r as defineVisualTest, s as VisualPage, t as parseVisualArgv, u as VisualSetup } from "./visual-DEo5Hndx.mjs";
|
|
2
2
|
export { type CheckpointResult, type VisualApp, type VisualOptions, type VisualPage, type VisualRenderer, type VisualReport, type VisualSetup, type VisualStart, type VisualStep, type VisualTest, type VisualTestResult, type VisualTolerance, defineVisualTest, parseVisualArgv, runVisualTests };
|
package/dist/visual.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as VISUAL_CLOCK } from "./fake-hnJcJeYf.mjs";
|
|
1
2
|
import { n as read, t as sources } from "./sources-DM5Zcl4o.mjs";
|
|
2
3
|
import { n as commands, t as run } from "./run-BnriyKUu.mjs";
|
|
3
4
|
import path from "node:path";
|
|
@@ -62,15 +63,41 @@ function stepNames() {
|
|
|
62
63
|
return Object.keys(commands).filter((name) => isStepCommand(name)).join(", ");
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
|
-
* Takes
|
|
66
|
-
*
|
|
66
|
+
* Takes a checkpoint step apart: its name, a string, and `finish`, a boolean when it is there; no
|
|
67
|
+
* other key.
|
|
68
|
+
*
|
|
69
|
+
* @param at - The test and the step, for the message.
|
|
70
|
+
* @param fields - The step.
|
|
71
|
+
* @returns The checkpoint.
|
|
72
|
+
* @throws {Error} When the name is not a string, `finish` not a boolean, or another key is there.
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* checkpointEntry('[game] Visual test "fade", step 2', { checkpoint: "glow", finish: false }); // { kind: "checkpoint", name: "glow", finish: false }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
function checkpointEntry(at, fields) {
|
|
79
|
+
const { checkpoint: name, finish = true, ...others } = fields;
|
|
80
|
+
if (Object.keys(others).length > 0) throw new Error(`${at} is not one command.\n A checkpoint takes its name and finish, like { checkpoint: "name", finish: false }.`);
|
|
81
|
+
if (typeof name !== "string") throw new TypeError(`${at}: the checkpoint name is not a string.\n Write the checkpoint as { checkpoint: "name" }.`);
|
|
82
|
+
if (typeof finish !== "boolean") throw new TypeError(`${at}: finish of the checkpoint "${name}" is not a boolean.\n Write finish: false to keep the motions running, or leave it out.`);
|
|
83
|
+
return {
|
|
84
|
+
kind: "checkpoint",
|
|
85
|
+
name,
|
|
86
|
+
finish
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Takes one step apart and checks its shape: a checkpoint (its name, and `finish` when it is
|
|
91
|
+
* there), or exactly one step command with an input object. The checkpoint name is checked by the
|
|
92
|
+
* caller.
|
|
67
93
|
*
|
|
68
94
|
* @param test - The test name, for the message.
|
|
69
95
|
* @param step - The step.
|
|
70
96
|
* @param index - Its index in the steps, from 0.
|
|
71
97
|
* @returns The checkpoint or the command with its input.
|
|
72
98
|
* @throws {Error} When the step holds no key or more than one, names something that is not a
|
|
73
|
-
* step, gives a command no input object, or a checkpoint no string
|
|
99
|
+
* step, gives a command no input object, or a checkpoint no string name or a `finish` that is
|
|
100
|
+
* not a boolean.
|
|
74
101
|
* @example
|
|
75
102
|
* ```ts
|
|
76
103
|
* stepEntry("reward-popup", { tap: { key: "play" } }, 0); // { kind: "command", name: "tap", input: { key: "play" } }
|
|
@@ -80,15 +107,9 @@ function stepEntry(test, step, index) {
|
|
|
80
107
|
const fields = step;
|
|
81
108
|
const [name, ...others] = Object.keys(fields);
|
|
82
109
|
const at = `[game] Visual test "${test}", step ${index + 1}`;
|
|
110
|
+
if (Object.hasOwn(fields, "checkpoint")) return checkpointEntry(at, fields);
|
|
83
111
|
if (name === void 0 || others.length > 0) throw new Error(`${at} is not one command.\n Write one command by its short name, or { checkpoint: "name" }.`);
|
|
84
112
|
const value = fields[name];
|
|
85
|
-
if (name === "checkpoint") {
|
|
86
|
-
if (typeof value === "string") return {
|
|
87
|
-
kind: "checkpoint",
|
|
88
|
-
name: value
|
|
89
|
-
};
|
|
90
|
-
throw new Error(`${at}: the checkpoint name is not a string.\n Write the checkpoint as { checkpoint: "name" }.`);
|
|
91
|
-
}
|
|
92
113
|
if (!isStepCommand(name)) throw new Error(`${at} names "${name}", which is not a step.\n Use a checkpoint or one of: ${stepNames()}.`);
|
|
93
114
|
if (!isInputObject(value)) throw new Error(`${at} (${name}) has no input object.\n Pass the input of the command, like { tap: { key: "play" } }.`);
|
|
94
115
|
return {
|
|
@@ -173,7 +194,8 @@ function checkVisualTest(name, steps) {
|
|
|
173
194
|
/**
|
|
174
195
|
* Defines a visual test: where it starts, what `game.restore` loads, and its steps. A step is a
|
|
175
196
|
* `/control` command by its short name with that command's input, or `{ checkpoint: name }`,
|
|
176
|
-
* where the runner saves `state.json` and `describe.json` next to the test
|
|
197
|
+
* where the runner lands every motion and saves `state.json` and `describe.json` next to the test;
|
|
198
|
+
* `{ checkpoint: name, finish: false }` keeps the motions running for the snapshot. `walk` runs fast: a
|
|
177
199
|
* popup its last node opens never mounts, so the step before a checkpoint that shows a node's
|
|
178
200
|
* result is `answer` or `tap`. With `webgl: true` the test also runs in the WebGL leg
|
|
179
201
|
* (`--webgl`), whose pictures go to `screen.webgl.webp`: set it on a screen with a custom filter.
|
|
@@ -773,17 +795,19 @@ async function settleAt(play, where) {
|
|
|
773
795
|
if (play.loop.error !== void 0) throw play.loop.error;
|
|
774
796
|
}
|
|
775
797
|
/**
|
|
776
|
-
* Plays a checkpoint: settle, land every track and loop
|
|
798
|
+
* Plays a checkpoint: settle, land every track and loop unless it says `finish: false`, two
|
|
799
|
+
* frames, then read and compare.
|
|
777
800
|
*
|
|
778
801
|
* @param play - The test being played.
|
|
779
|
-
* @param
|
|
802
|
+
* @param entry - The checkpoint: its name, and whether it lands the motions.
|
|
780
803
|
* @param where - The step, for the message.
|
|
781
804
|
* @returns The outcome of the checkpoint; `pixels` is skipped in this leg.
|
|
782
805
|
*/
|
|
783
|
-
async function checkpoint$1(play,
|
|
806
|
+
async function checkpoint$1(play, entry, where) {
|
|
784
807
|
const { app, test, run: options } = play;
|
|
808
|
+
const { name } = entry;
|
|
785
809
|
await settleAt(play, where);
|
|
786
|
-
app.anim.finishAll();
|
|
810
|
+
if (entry.finish) app.anim.finishAll();
|
|
787
811
|
await frames(app, REST_FRAMES);
|
|
788
812
|
const file = (kind) => baselineFile(options.dir, test.name, name, kind);
|
|
789
813
|
const state = await checkBaseline(file("state.json"), stableJson(stateOf(app)), options.update);
|
|
@@ -819,7 +843,7 @@ async function playSteps$1(play, checkpoints) {
|
|
|
819
843
|
const entry = stepEntry(test.name, step, index);
|
|
820
844
|
const where = `step ${index + 1} (${entry.kind === "checkpoint" ? "checkpoint" : entry.name})`;
|
|
821
845
|
if (entry.kind === "checkpoint") {
|
|
822
|
-
checkpoints.push(await checkpoint$1(play, entry
|
|
846
|
+
checkpoints.push(await checkpoint$1(play, entry, where));
|
|
823
847
|
continue;
|
|
824
848
|
}
|
|
825
849
|
await failing(test.name, where, () => runStep(app, entry.name, entry.input));
|
|
@@ -1234,13 +1258,16 @@ async function pageStep(argument) {
|
|
|
1234
1258
|
}
|
|
1235
1259
|
}
|
|
1236
1260
|
/**
|
|
1237
|
-
* Plays a checkpoint in the page: settle, land every track and loop
|
|
1261
|
+
* Plays a checkpoint in the page: settle, land every track and loop unless the step says
|
|
1262
|
+
* `finish: false` (F87), two stepped frames, then the
|
|
1238
1263
|
* picture of the whole canvas as lossless WebP and the state through the doors. The game is
|
|
1239
1264
|
* paused, so the picture is the stage after the last stepped frame. With the frame check on, a
|
|
1240
1265
|
* missed frame or mark logged in the meantime fails the checkpoint.
|
|
1241
1266
|
*
|
|
1242
|
-
* @param argument - The test and the step,
|
|
1267
|
+
* @param argument - The test and the step, the most frames to settle, and whether to land the
|
|
1268
|
+
* motions.
|
|
1243
1269
|
* @param argument.settleFrames - The most frames to settle.
|
|
1270
|
+
* @param argument.finish - True to land every motion before the picture.
|
|
1244
1271
|
* @returns The state and the picture, or why the checkpoint failed.
|
|
1245
1272
|
*/
|
|
1246
1273
|
async function pageCheckpoint(argument) {
|
|
@@ -1252,7 +1279,7 @@ async function pageCheckpoint(argument) {
|
|
|
1252
1279
|
ok: false,
|
|
1253
1280
|
error: unsettled
|
|
1254
1281
|
};
|
|
1255
|
-
game.anim.finishAll();
|
|
1282
|
+
if (argument.finish) game.anim.finishAll();
|
|
1256
1283
|
await pageTick(handles);
|
|
1257
1284
|
await pageTick(handles);
|
|
1258
1285
|
const captured = await game.renderer.capture();
|
|
@@ -1497,6 +1524,17 @@ function pageScript() {
|
|
|
1497
1524
|
}
|
|
1498
1525
|
//#endregion
|
|
1499
1526
|
//#region src/visual/leg-browser.ts
|
|
1527
|
+
/**
|
|
1528
|
+
* @file visual — the browser leg: Chrome with WebGPU on a Mac, driven by Playwright. It loads
|
|
1529
|
+
* `playwright-core` with a dynamic import only here, opens the dev page once per test, waits until
|
|
1530
|
+
* the page has loaded what it asked for, turns on the renderer's check of skipped frames
|
|
1531
|
+
* (`debug.verifyFrames`), pauses the game and steps it to the start time, plays the
|
|
1532
|
+
* test inside the page through `globalThis.game` and `globalThis.doors` on stepped frames, and at
|
|
1533
|
+
* each checkpoint checks the page's state against `state.json` and its picture against
|
|
1534
|
+
* `screen.webp`. The WebGL leg opens the page with `?renderer=webgl` and keeps its pictures in
|
|
1535
|
+
* `screen.webgl.webp`. The pixels are compared in the page (`page-script.ts`); the files are written by
|
|
1536
|
+
* `files.ts`. A failure of the page itself fails the leg; a failure of a step ends its test only.
|
|
1537
|
+
*/
|
|
1500
1538
|
/** The Chrome flags of `.planning/e2e/run.mjs`: WebGPU on Metal, on any GPU. */
|
|
1501
1539
|
const WEBGPU_FLAGS = [
|
|
1502
1540
|
"--enable-unsafe-webgpu",
|
|
@@ -1636,6 +1674,20 @@ async function launchChrome(chromium, browser) {
|
|
|
1636
1674
|
throw new Error(`[game] No Chrome launched: ${own.reason}.\n Install Playwright's Chromium (bunx playwright-core install chromium), set page.browser, or run with --no-pixels.`);
|
|
1637
1675
|
}
|
|
1638
1676
|
/**
|
|
1677
|
+
* The init script that puts the moment of the headless leg's clock on the page before it loads
|
|
1678
|
+
* (F86): a dev page then runs its app on a fake clock standing there, as the headless leg does.
|
|
1679
|
+
*
|
|
1680
|
+
* @param moment - The moment, epoch milliseconds.
|
|
1681
|
+
* @returns The script.
|
|
1682
|
+
* @example
|
|
1683
|
+
* ```ts
|
|
1684
|
+
* clockScript(1_000_000); // 'globalThis["__mokuVisualClock"] = 1000000;'
|
|
1685
|
+
* ```
|
|
1686
|
+
*/
|
|
1687
|
+
function clockScript(moment) {
|
|
1688
|
+
return `globalThis[${JSON.stringify(VISUAL_CLOCK)}] = ${JSON.stringify(moment)};`;
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1639
1691
|
* Sizes the page: `page.width` CSS px wide (390), as tall as the inert frame of the game is at
|
|
1640
1692
|
* that width, so the reference frame of the page equals the one of the headless leg; a phone
|
|
1641
1693
|
* with touch at `page.deviceScaleFactor` (2). Builds one app of the setup, never started, to read
|
|
@@ -1762,14 +1814,16 @@ async function startPage(page, url, run) {
|
|
|
1762
1814
|
* @param context - The browser context.
|
|
1763
1815
|
* @param url - The URL of the page the leg opens.
|
|
1764
1816
|
* @param run - The run options, for `settleFrames` and `renderer`.
|
|
1817
|
+
* @param moment - The moment the headless leg's clock stands at, for the page's clock (F86).
|
|
1765
1818
|
* @returns The open page.
|
|
1766
1819
|
* @throws {Error} When the page does not open, never exposes `game` and `doors`, does not start,
|
|
1767
1820
|
* draws with another backend or never stops loading. The page is closed then.
|
|
1768
1821
|
*/
|
|
1769
|
-
async function openPage(context, url, run) {
|
|
1822
|
+
async function openPage(context, url, run, moment) {
|
|
1770
1823
|
const page = await context.newPage();
|
|
1771
1824
|
try {
|
|
1772
1825
|
await page.addInitScript({ content: pageScript() });
|
|
1826
|
+
await page.addInitScript({ content: clockScript(moment) });
|
|
1773
1827
|
await page.goto(url).catch((error) => {
|
|
1774
1828
|
throw new Error(`[game] The page at ${url} did not open: ${firstLine(error)}.\n Serve the dev page (moku-game dev), or run with --no-pixels.`);
|
|
1775
1829
|
});
|
|
@@ -1825,17 +1879,19 @@ async function checkScreen(play, file, where, screen) {
|
|
|
1825
1879
|
* headless leg wrote, the picture against the baseline of the leg's backend.
|
|
1826
1880
|
*
|
|
1827
1881
|
* @param play - The test being played.
|
|
1828
|
-
* @param
|
|
1882
|
+
* @param entry - The checkpoint: its name, and whether it lands the motions.
|
|
1829
1883
|
* @param where - The step, for the message.
|
|
1830
1884
|
* @returns What the browser leg found there.
|
|
1831
1885
|
* @throws {Error} When the page did not settle, gave no picture, or broke.
|
|
1832
1886
|
*/
|
|
1833
|
-
async function checkpoint(play,
|
|
1887
|
+
async function checkpoint(play, entry, where) {
|
|
1834
1888
|
const { test, run } = play;
|
|
1889
|
+
const { name } = entry;
|
|
1835
1890
|
const shot = await callPage(play.page, pageCheckpoint, {
|
|
1836
1891
|
test: test.name,
|
|
1837
1892
|
where,
|
|
1838
|
-
settleFrames: run.settleFrames
|
|
1893
|
+
settleFrames: run.settleFrames,
|
|
1894
|
+
finish: entry.finish
|
|
1839
1895
|
});
|
|
1840
1896
|
if (shot.screen === void 0) throw new Error(`[game] Visual test "${test.name}", ${where}: the page gave no picture.\n Serve a dev build with ${BACKEND[run.renderer]}: renderer.capture() answers only there.`);
|
|
1841
1897
|
const file = (kind) => baselineFile(run.dir, test.name, name, kind);
|
|
@@ -1882,7 +1938,7 @@ async function playSteps(play, found) {
|
|
|
1882
1938
|
const entry = stepEntry(test.name, step, index);
|
|
1883
1939
|
const where = `step ${index + 1} (${entry.kind === "checkpoint" ? "checkpoint" : entry.name})`;
|
|
1884
1940
|
if (entry.kind === "checkpoint") {
|
|
1885
|
-
found.set(entry.name, await checkpoint(play, entry
|
|
1941
|
+
found.set(entry.name, await checkpoint(play, entry, where));
|
|
1886
1942
|
continue;
|
|
1887
1943
|
}
|
|
1888
1944
|
await callPage(play.page, pageStep, {
|
|
@@ -1901,13 +1957,15 @@ async function playSteps(play, found) {
|
|
|
1901
1957
|
* @param play - The test and the run options; the page is opened here.
|
|
1902
1958
|
* @param play.test - The test.
|
|
1903
1959
|
* @param play.run - The run options.
|
|
1904
|
-
* @param
|
|
1960
|
+
* @param target - The page the leg opens: its URL, and the moment of the headless leg's clock.
|
|
1961
|
+
* @param target.url - The URL.
|
|
1962
|
+
* @param target.moment - The moment, epoch milliseconds.
|
|
1905
1963
|
* @param headless - The result of the test in the headless leg.
|
|
1906
1964
|
* @returns The result of the test with its pixel fields.
|
|
1907
1965
|
* @throws {Error} When the page fails to open: that fails the leg.
|
|
1908
1966
|
*/
|
|
1909
|
-
async function browserTest(context, play,
|
|
1910
|
-
const page = await openPage(context, url, play.run);
|
|
1967
|
+
async function browserTest(context, play, target, headless) {
|
|
1968
|
+
const page = await openPage(context, target.url, play.run, target.moment);
|
|
1911
1969
|
const found = /* @__PURE__ */ new Map();
|
|
1912
1970
|
let failed;
|
|
1913
1971
|
try {
|
|
@@ -1954,7 +2012,10 @@ async function runBrowserLeg(setup, tests, run, headless, load = loadChromium) {
|
|
|
1954
2012
|
if (page === void 0) throw new Error("[game] The pixel leg needs the dev page.\n Pass page: { url } in the setup, or run with --no-pixels.");
|
|
1955
2013
|
const chromium = await load();
|
|
1956
2014
|
const options = pageSize(setup, page);
|
|
1957
|
-
const
|
|
2015
|
+
const target = {
|
|
2016
|
+
url: rendererUrl(page.url, run.renderer),
|
|
2017
|
+
moment: setup.app().clock.now()
|
|
2018
|
+
};
|
|
1958
2019
|
const browser = await launchChrome(chromium, page.browser);
|
|
1959
2020
|
try {
|
|
1960
2021
|
const context = await browser.newContext(options);
|
|
@@ -1967,7 +2028,7 @@ async function runBrowserLeg(setup, tests, run, headless, load = loadChromium) {
|
|
|
1967
2028
|
results.push(before.error === void 0 ? await browserTest(context, {
|
|
1968
2029
|
test,
|
|
1969
2030
|
run
|
|
1970
|
-
},
|
|
2031
|
+
}, target, before) : before);
|
|
1971
2032
|
}
|
|
1972
2033
|
return results;
|
|
1973
2034
|
} finally {
|
package/llms.txt
CHANGED
|
@@ -12,7 +12,7 @@ Facts: Bun only. ESM only. `"sideEffects"` lists the root entry `./dist/index.mj
|
|
|
12
12
|
- `@moku-labs/game/app/system` (the browser, the native shell): `systemShellOf`, `fromSystem`, `storeSave`, `createSystemApp`, the type `SystemModules`, over the optional peer `@moku-labs/system`. The one entry that names it, in types only: the page hands it the loaders.
|
|
13
13
|
- `@moku-labs/game/cli` (node and bun only): `runCli`, the bin `moku-game`, `preparePage`, the editor's dev page, `watchKeys`, the watch that keeps `generated/` fresh next to it, and `watchEngine`, the watch that tells when the installed engine changed.
|
|
14
14
|
- `@moku-labs/game/testing`: headless play, repro runs, isolated feature tests (`isolate`, `stub`), fake clock, the `fx` of a node for a unit test (`fakeFx`), in-memory save provider. No `node:` import.
|
|
15
|
-
- `@moku-labs/game/visual` (node and bun only): the visual tests `defineVisualTest`, `runVisualTests`, `parseVisualArgv`. The bin runs them: `moku-game visual`.
|
|
15
|
+
- `@moku-labs/game/visual` (node and bun only): the visual tests `defineVisualTest`, `runVisualTests`, `parseVisualArgv`. The bin runs them: `moku-game visual`. A step is a `/control` command or `{ checkpoint: name, finish?: boolean }`: a checkpoint lands every motion before its snapshot, `finish: false` keeps them running (same frames in both legs). Both legs run on one clock: the pixel leg's dev page runs on a fake clock at the headless app's `clock.now()` (`startMoment`), standing still like the headless one.
|
|
16
16
|
- `@moku-labs/game/assets` (node and bun only): the asset key scanner, the production packer and the string compiler. The package bin `moku-game-assets` runs it.
|
|
17
17
|
- `@moku-labs/game/inspect`: the read door of the editor, safe in a production build. See "Doors for the editor".
|
|
18
18
|
- `@moku-labs/game/control`: the write door of the editor, dev builds only. See "Doors for the editor".
|