@celestia-island/hikari 0.55.491 → 0.55.492
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/package.json +3 -2
- package/src/plugins/boot-landing.scss +1 -1
- package/src/plugins/boot-recovery.js +2 -2
- package/src/plugins/bootLandingCss.d.ts +1 -1
- package/src/plugins/bootLandingCss.test.ts +1 -1
- package/src/plugins/bootLandingDetailsCss.d.ts +1 -1
- package/src/res/authoredResScripts.test.ts +229 -0
- package/src/res/preBootScriptsBehaviour.test.ts +225 -0
- package/src/res/tauriTitlebarBehaviour.test.ts +332 -0
- package/src/res/themeLoaderBehaviour.test.ts +291 -0
- package/src/theme/themeLoaderContract.test.ts +46 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celestia-island/hikari",
|
|
3
|
-
"version": "0.55.
|
|
3
|
+
"version": "0.55.492",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
|
|
@@ -71,7 +71,8 @@
|
|
|
71
71
|
"build:docs": "vite build",
|
|
72
72
|
"prelint": "python3 ../wasm/ensure_bindings.py",
|
|
73
73
|
"lint": "vue-tsc --noEmit",
|
|
74
|
-
"gen:boot-landing-css": "node scripts/gen-boot-landing-css.
|
|
74
|
+
"gen:boot-landing-css": "node scripts/gen-boot-landing-css.ts",
|
|
75
|
+
"gen:res-scripts": "node scripts/emit-res-scripts.mjs",
|
|
75
76
|
"prepublishOnly": "python3 ../wasm/check_npm_pack.py && npm run build:types",
|
|
76
77
|
"build:types": "vue-tsc --project tsconfig.build.json"
|
|
77
78
|
},
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// button carries it, and a host-invented button style
|
|
19
19
|
// would drift from the app's).
|
|
20
20
|
//
|
|
21
|
-
// scripts/gen-boot-landing-css.
|
|
21
|
+
// scripts/gen-boot-landing-css.ts compiles this file (compressed, ASCII) into
|
|
22
22
|
// src/plugins/bootLandingCss.js, which the generated boot script inlines so
|
|
23
23
|
// the panel needs no second network round-trip. bootLandingCss.test.ts
|
|
24
24
|
// recompiles this entry and fails on drift, so editing the component sheets
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
* `__desc` + `__actions` with an `.hk-btn-primary` action), and its
|
|
40
40
|
* stylesheet is compiled from the LIVE component sheets — theme/channels,
|
|
41
41
|
* theme/scale, `HkErrorLanding.scss` and `HkButton.scss` — into
|
|
42
|
-
* `./bootLandingCss.js` by `scripts/gen-boot-landing-css.
|
|
42
|
+
* `./bootLandingCss.js` by `scripts/gen-boot-landing-css.ts`.
|
|
43
43
|
* `bootLandingCss.test.ts` recompiles that entry and fails whenever the
|
|
44
44
|
* checked-in sheet drifts, so the boot surface cannot fork away from the app's
|
|
45
45
|
* error landing (the pre-0.55.3xx panel hand-rolled `.hk-boot-recovery`
|
|
@@ -1327,7 +1327,7 @@ function htmlFileMatches(filename, htmlFiles) {
|
|
|
1327
1327
|
* classes, and the stylesheet is compiled from the LIVE component sources
|
|
1328
1328
|
* (`boot-landing.scss`: theme/channels + theme/scale + HkErrorLanding +
|
|
1329
1329
|
* HkButton) into `./bootLandingCss.js` by
|
|
1330
|
-
* `scripts/gen-boot-landing-css.
|
|
1330
|
+
* `scripts/gen-boot-landing-css.ts`. `bootLandingCss.test.ts` recompiles
|
|
1331
1331
|
* the entry and fails whenever the checked-in sheet drifts from the
|
|
1332
1332
|
* components, so the boot surface cannot fork away from the app's error
|
|
1333
1333
|
* landing again (the pre-0.55.3xx panel hand-rolled `.hk-boot-recovery`
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Types for `bootLandingCss.js` — the generated boot failure panel sheet
|
|
7
|
-
* (compiled from `boot-landing.scss` by `scripts/gen-boot-landing-css.
|
|
7
|
+
* (compiled from `boot-landing.scss` by `scripts/gen-boot-landing-css.ts`;
|
|
8
8
|
* do not edit the module by hand).
|
|
9
9
|
*/
|
|
10
10
|
export declare const BOOT_LANDING_CSS: string;
|
|
@@ -20,7 +20,7 @@ import { BOOT_LANDING_DETAILS_CSS } from "./bootLandingDetailsCss.js";
|
|
|
20
20
|
* as hikari's in-app error landing. So instead of hand-copying token values
|
|
21
21
|
* (the pre-0.55.3xx `.hk-boot-recovery` card did), the panel ships the LIVE
|
|
22
22
|
* component sheets: `boot-landing.scss` @uses theme/channels, theme/scale,
|
|
23
|
-
* HkErrorLanding and HkButton, and `scripts/gen-boot-landing-css.
|
|
23
|
+
* HkErrorLanding and HkButton, and `scripts/gen-boot-landing-css.ts`
|
|
24
24
|
* compiles that entry into `bootLandingCss.js`, which the plugin inlines.
|
|
25
25
|
*
|
|
26
26
|
* This suite recompiles the entry with the same sass a consumer uses and
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* Types for `bootLandingDetailsCss.js` — the generated boot failure panel's
|
|
7
7
|
* DETAILS sheet (compiled from `boot-landing-details.scss` by
|
|
8
|
-
* `scripts/gen-boot-landing-css.
|
|
8
|
+
* `scripts/gen-boot-landing-css.ts`; do not edit the module by hand).
|
|
9
9
|
*
|
|
10
10
|
* A second artifact on purpose: this sheet is inlined into the generated
|
|
11
11
|
* script only when the host opts into the raw-details pane
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
|
|
8
|
+
// The emitter lives beside the other packages/vue script drivers and is the
|
|
9
|
+
// ONE definition of how `res/<name>.ts` becomes `res/<name>.js` — the build and
|
|
10
|
+
// this guard must never disagree, so both import it rather than re-deriving.
|
|
11
|
+
// MUT:hk-1565-res-drift-lock — re-deriving the bytes here instead of
|
|
12
|
+
// importing them leaves the guard and the emitter free to drift, which is
|
|
13
|
+
// exactly what the sync assertion below exists to catch.
|
|
14
|
+
import { AUTHORED_RES_SCRIPTS, transpile } from "../../scripts/emit-res-scripts.mjs";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The two-sided lock for the pre-paint `res/` scripts.
|
|
18
|
+
*
|
|
19
|
+
* These five files are authored as TypeScript and SHIPPED as JavaScript: a
|
|
20
|
+
* host loads them with a bare `<script src>` before any framework, and the
|
|
21
|
+
* sibling repos vendor the `.js` verbatim (shittim-chest `packages/webui/src/
|
|
22
|
+
* res/`, plana `res/`). The pairing is therefore bidirectional, and this suite
|
|
23
|
+
* is both directions of it:
|
|
24
|
+
*
|
|
25
|
+
* 1. **A source edit without a regen.** [`the committed javascript is what the
|
|
26
|
+
* typescript compiles to`] re-transpiles each `.ts` in memory and compares
|
|
27
|
+
* it, byte for byte, with the committed `.js`. Editing the source and
|
|
28
|
+
* forgetting `pnpm run gen:res-scripts` leaves the shipped asset stale — the
|
|
29
|
+
* half of the pair every host actually executes — so this goes red.
|
|
30
|
+
*
|
|
31
|
+
* 2. **A hand edit of the emitted file.** Same test, same red: the `.js` is
|
|
32
|
+
* reproducible from the `.ts`, and a patch applied only to it cannot survive.
|
|
33
|
+
*
|
|
34
|
+
* Resolve either by editing the `.ts` and running `pnpm run gen:res-scripts`
|
|
35
|
+
* (from `packages/vue`). Never by editing the `.js` — MUT:hk-1565-res-hand-edit
|
|
36
|
+
* is that direction: patching the emitted file alone makes the sync assertion
|
|
37
|
+
* below go red.
|
|
38
|
+
*
|
|
39
|
+
* WHY THE EMITTED FILES ARE COMMITTED AT ALL (the design decision this file
|
|
40
|
+
* enforces): `bootScriptsPlugin` copies `res/*.js` from the SOURCE TREE into the
|
|
41
|
+
* build output, and consumers range from a full vite build to a host that
|
|
42
|
+
* merely serves the directory. A gitignored output would mean a checkout that
|
|
43
|
+
* never ran node ships a page with no pre-paint theme loader — the exact
|
|
44
|
+
* "unpainted first frame" failure the module exists to prevent — and
|
|
45
|
+
* `bootScriptsPlugin` skips a missing source silently, so the breakage would be
|
|
46
|
+
* invisible until someone looked at a first paint. MUT:hk-1565-res-drift-lock is
|
|
47
|
+
* what keeps the committed pair equal. The missing-file half is NOT pinned by
|
|
48
|
+
* this suite: it is why the artifact is committed rather than ignored, and
|
|
49
|
+
* nothing here would go red if a future change made the emit skip a file.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
53
|
+
/** packages/vue */
|
|
54
|
+
const VUE_DIR = resolve(HERE, "../..");
|
|
55
|
+
/** repository root */
|
|
56
|
+
const REPO_ROOT = resolve(VUE_DIR, "../..");
|
|
57
|
+
|
|
58
|
+
interface ResScript {
|
|
59
|
+
/** `theme-loader` */
|
|
60
|
+
readonly stem: string;
|
|
61
|
+
readonly sourcePath: string;
|
|
62
|
+
readonly outputPath: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const scripts = AUTHORED_RES_SCRIPTS as readonly ResScript[];
|
|
66
|
+
|
|
67
|
+
/** The exact result of a transpile, plus the bytes the emitter would write. */
|
|
68
|
+
function regen(script: ResScript): string {
|
|
69
|
+
return transpile(readFileSync(script.sourcePath, "utf8"), `${script.stem}.ts`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
describe("authored res scripts: source/output pairing", () => {
|
|
73
|
+
it("discovers every pre-paint asset as a .ts/.js pair", () => {
|
|
74
|
+
// A new `res/<name>.ts` that the emitter's directory scan did not pick up
|
|
75
|
+
// would ship with no `.js` at all, so the pair set is pinned rather than
|
|
76
|
+
// implied.
|
|
77
|
+
expect(scripts.map((script) => script.stem).sort()).toEqual([
|
|
78
|
+
"browser-check",
|
|
79
|
+
"loader-dismiss",
|
|
80
|
+
"os-prefs",
|
|
81
|
+
"tauri-titlebar",
|
|
82
|
+
"theme-loader",
|
|
83
|
+
]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("keeps every compiled asset in sync with its TypeScript source", () => {
|
|
87
|
+
const stale: string[] = [];
|
|
88
|
+
for (const script of scripts) {
|
|
89
|
+
const committed = readFileSync(script.outputPath, "utf8");
|
|
90
|
+
const expected = regen(script);
|
|
91
|
+
if (committed !== expected) {
|
|
92
|
+
stale.push(
|
|
93
|
+
`res/${script.stem}.js is out of date with res/${script.stem}.ts ` +
|
|
94
|
+
`(run \`pnpm run gen:res-scripts\` from packages/vue)`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
expect(stale, "every res/*.js is the byte-exact output of its .ts").toEqual([]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("is deterministic: recompiling twice yields identical bytes", () => {
|
|
102
|
+
// The bytes are hashed into host CSPs, so "same input, same output" is a
|
|
103
|
+
// contract, not a nicety.
|
|
104
|
+
for (const script of scripts) {
|
|
105
|
+
expect(regen(script), `res/${script.stem}.js recompiles deterministically`).toBe(
|
|
106
|
+
regen(script),
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it.each([
|
|
112
|
+
"browser-check",
|
|
113
|
+
"loader-dismiss",
|
|
114
|
+
"os-prefs",
|
|
115
|
+
"tauri-titlebar",
|
|
116
|
+
"theme-loader",
|
|
117
|
+
])("emits res/%s.js as valid, parseable JavaScript", (stem) => {
|
|
118
|
+
const script = scripts.find((candidate) => candidate.stem === stem);
|
|
119
|
+
if (!script) throw new Error(`res/${stem}.ts is not in the emitter's target list`);
|
|
120
|
+
const output = readFileSync(script.outputPath, "utf8");
|
|
121
|
+
|
|
122
|
+
// A parse error in a pre-paint asset voids the whole inline bootstrap, so
|
|
123
|
+
// the syntax floor is asserted here rather than trusted.
|
|
124
|
+
const sourceFile = ts.createSourceFile(
|
|
125
|
+
`${stem}.js`,
|
|
126
|
+
output,
|
|
127
|
+
ts.ScriptTarget.ES2020,
|
|
128
|
+
true,
|
|
129
|
+
ts.ScriptKind.JS,
|
|
130
|
+
);
|
|
131
|
+
const diagnostics = (sourceFile as unknown as { parseDiagnostics?: ts.Diagnostic[] })
|
|
132
|
+
.parseDiagnostics ?? [];
|
|
133
|
+
expect(
|
|
134
|
+
diagnostics.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, " ")),
|
|
135
|
+
`res/${stem}.js parses at the ES2020 floor`,
|
|
136
|
+
).toEqual([]);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it.each([
|
|
140
|
+
"browser-check",
|
|
141
|
+
"loader-dismiss",
|
|
142
|
+
"os-prefs",
|
|
143
|
+
"tauri-titlebar",
|
|
144
|
+
"theme-loader",
|
|
145
|
+
])("keeps res/%s.js a classic script: ASCII-only, no module syntax", (stem) => {
|
|
146
|
+
const script = scripts.find((candidate) => candidate.stem === stem);
|
|
147
|
+
if (!script) throw new Error(`res/${stem}.ts is not in the emitter's target list`);
|
|
148
|
+
const output = readFileSync(script.outputPath, "utf8");
|
|
149
|
+
|
|
150
|
+
// Servers answer these with `text/html`-style charset-less headers and hosts
|
|
151
|
+
// hash the bytes into a CSP: a non-ASCII byte is both a mojibake risk and a
|
|
152
|
+
// silent hash change.
|
|
153
|
+
expect(Array.from(output).some((character) => character.charCodeAt(0) > 0x7f)).toBe(false);
|
|
154
|
+
// A host loads this with a bare <script src>; an `export`/`import` would
|
|
155
|
+
// make the browser reject the file as a module it was never tagged as. comment-gate-ok: explains what the regex below represents about classic-script loading, not that a mutation was run against it.
|
|
156
|
+
expect(output).not.toMatch(/^\s*(export|import)\s/m);
|
|
157
|
+
// Provenance must travel with the artifact: a reader of the .js has to be
|
|
158
|
+
// able to find its source.
|
|
159
|
+
expect(output).toContain("GENERATED from the TypeScript source");
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("authored res scripts: build directives survive the transpile", () => {
|
|
164
|
+
it("keeps every @__PURE__ the source declares, at the same call", () => {
|
|
165
|
+
// A `/* @__PURE__ */` comment is a BUILD directive, not documentation: it
|
|
166
|
+
// tells a downstream bundler the annotated call may be dropped when its
|
|
167
|
+
// result is unused. `removeComments` erases it, so the emitter re-attaches
|
|
168
|
+
// it by AST position — and this assertion is what keeps that re-attachment
|
|
169
|
+
// honest. MUT:hk-1565-pure is that probe: disabling the re-attachment in
|
|
170
|
+
// the emitter drops the family's only directive from the emitted
|
|
171
|
+
// tauri-titlebar, and this assertion (plus its named companion) goes red.
|
|
172
|
+
for (const script of scripts) {
|
|
173
|
+
const sourceText = readFileSync(script.sourcePath, "utf8");
|
|
174
|
+
const declared = sourceText.match(/\/\*\s*@__PURE__\s*\*\//g) ?? [];
|
|
175
|
+
if (declared.length === 0) continue;
|
|
176
|
+
|
|
177
|
+
const emitted = readFileSync(script.outputPath, "utf8");
|
|
178
|
+
const carried = emitted.match(/\/\*\s*@__PURE__\s*\*\//g) ?? [];
|
|
179
|
+
expect(
|
|
180
|
+
carried.length,
|
|
181
|
+
`res/${script.stem}.js must carry every @__PURE__ its source declares`,
|
|
182
|
+
).toBe(declared.length);
|
|
183
|
+
|
|
184
|
+
// Not just present — still annotating the same construct. The directive
|
|
185
|
+
// sits inline before the call it protects, so the annotated expression
|
|
186
|
+
// must follow it on the emitted line too.
|
|
187
|
+
for (const line of emitted.split("\n").filter((text) => text.includes("@__PURE__"))) {
|
|
188
|
+
expect(line, "@__PURE__ still prefixes a call expression").toMatch(
|
|
189
|
+
/@__PURE__\s*\*\/\s*(new\s+)?[A-Za-z_$][\w$.]*\s*\(/,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("declares the one build-directive asset tauri-titlebar carries", () => {
|
|
196
|
+
// Pinned by name so deleting the directive from the source is a deliberate,
|
|
197
|
+
// reviewed change rather than a silent one: this file is where the family's
|
|
198
|
+
// tree-shaking hint lives.
|
|
199
|
+
const emitted = readFileSync(resolve(REPO_ROOT, "res/tauri-titlebar.js"), "utf8");
|
|
200
|
+
expect(
|
|
201
|
+
emitted.match(/@__PURE__/g)?.length,
|
|
202
|
+
"tauri-titlebar's @__PURE__ on the Date construction survives the emit",
|
|
203
|
+
).toBe(1);
|
|
204
|
+
expect(emitted).toContain("/* @__PURE__ */ new Date()");
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe("authored res scripts: source tree wiring", () => {
|
|
209
|
+
it("keeps the authored sources inside the repository", () => {
|
|
210
|
+
for (const script of scripts) {
|
|
211
|
+
expect(script.sourcePath.startsWith(REPO_ROOT), `${script.stem}.ts lives in the repo`).toBe(
|
|
212
|
+
true,
|
|
213
|
+
);
|
|
214
|
+
expect(script.outputPath.startsWith(REPO_ROOT), `${script.stem}.js lives in the repo`).toBe(
|
|
215
|
+
true,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("does not leave a stray .js without its .ts", () => {
|
|
221
|
+
// The reverse of the pair set above: a `.js` in res/ with no `.ts` would be
|
|
222
|
+
// an un-authored hand-kept asset sneaking past the sourcing rule.
|
|
223
|
+
const present = readdirSync(resolve(REPO_ROOT, "res"))
|
|
224
|
+
.filter((name) => name.endsWith(".js"))
|
|
225
|
+
.map((name) => name.slice(0, -".js".length))
|
|
226
|
+
.sort();
|
|
227
|
+
expect(present).toEqual(scripts.map((script) => script.stem).sort());
|
|
228
|
+
});
|
|
229
|
+
});
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Behaviour suites for the three small pre-paint assets: `browser-check.js`,
|
|
9
|
+
* `os-prefs.js` and `loader-dismiss.js`.
|
|
10
|
+
*
|
|
11
|
+
* These are the siblings of `theme-loader` (covered by
|
|
12
|
+
* `themeLoaderBehaviour.test.ts`) and `tauri-titlebar` (covered by
|
|
13
|
+
* `tauriTitlebarBehaviour.test.ts`). They are much smaller — 68, 62 and 11 lines
|
|
14
|
+
* of authored source — but each makes ONE decision that a shape/parse floor
|
|
15
|
+
* cannot see, and each decision is user-visible:
|
|
16
|
+
*
|
|
17
|
+
* - `browser-check` decides whether the host blocks the app at all, and it
|
|
18
|
+
* silently does nothing without a `__appBlock` handler;
|
|
19
|
+
* MUT:hk-1565-safari-floor — lowering the Safari floor to 15.0 in the
|
|
20
|
+
* source makes the 15.3 case pass and the floor assertion goes red.
|
|
21
|
+
* - `os-prefs` decides whether the Tauri shell's OS locale/theme seed wins
|
|
22
|
+
* over what the user already stored;
|
|
23
|
+
* - `loader-dismiss` decides whether the loading screen ever goes away.
|
|
24
|
+
*
|
|
25
|
+
* All three are executed with `new Function` against a page built to order.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
29
|
+
const REPO_ROOT = resolve(HERE, "../../../..");
|
|
30
|
+
const read = (name: string): string => readFileSync(resolve(REPO_ROOT, "res", name), "utf8");
|
|
31
|
+
|
|
32
|
+
const BROWSER_CHECK = read("browser-check.js");
|
|
33
|
+
const OS_PREFS = read("os-prefs.js");
|
|
34
|
+
const LOADER_DISMISS = read("loader-dismiss.js");
|
|
35
|
+
|
|
36
|
+
/** Run a classic script with the globals it expects, returning nothing else. */
|
|
37
|
+
function execute(
|
|
38
|
+
source: string,
|
|
39
|
+
globals: Record<string, unknown>,
|
|
40
|
+
paramNames: readonly string[],
|
|
41
|
+
): void {
|
|
42
|
+
const run = new Function(...paramNames, source) as (...args: unknown[]) => void;
|
|
43
|
+
run(...paramNames.map((name) => globals[name]));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe("res/browser-check.js", () => {
|
|
47
|
+
/** Drive `detect()` through a UA string and report what `__appBlock` saw. */
|
|
48
|
+
function check(userAgent: string, extra: Record<string, unknown> = {}) {
|
|
49
|
+
const block = vi.fn();
|
|
50
|
+
const navigator = { userAgent, platform: "Linux x86_64", maxTouchPoints: 0, ...extra };
|
|
51
|
+
const fakeWindow: Record<string, unknown> = { __appBlock: block };
|
|
52
|
+
execute(BROWSER_CHECK, { navigator, window: fakeWindow }, ["navigator", "window"]);
|
|
53
|
+
return block;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
it("blocks a browser below the floor, naming it and both versions", () => {
|
|
57
|
+
const block = check("Mozilla/5.0 Chrome/80.0.0.0 Safari/537.36");
|
|
58
|
+
expect(block).toHaveBeenCalledTimes(1);
|
|
59
|
+
expect(block).toHaveBeenCalledWith("Chrome", 80, 100);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("lets a browser at the floor through", () => {
|
|
63
|
+
expect(check("Mozilla/5.0 Chrome/100.0.0.0 Safari/537.36")).not.toHaveBeenCalled();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("treats Safari's minor version as significant", () => {
|
|
67
|
+
// Safari 15.3 is below the 15.4 floor while 15.4 is exactly at it; a
|
|
68
|
+
// major-only comparison would wave the older one through.
|
|
69
|
+
expect(check("Mozilla/5.0 Version/15.3 Safari/605.1.15")).toHaveBeenCalledWith(
|
|
70
|
+
"Safari",
|
|
71
|
+
15.3,
|
|
72
|
+
15.4,
|
|
73
|
+
);
|
|
74
|
+
expect(check("Mozilla/5.0 Version/15.4 Safari/605.1.15")).not.toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("identifies iOS from a desktop-class iPad", () => {
|
|
78
|
+
// iPadOS reports a MacIntel platform with touch points instead of an iPad UA.
|
|
79
|
+
const block = check("Mozilla/5.0 Version/15.0 Mobile/15E148 Safari/604.1", {
|
|
80
|
+
platform: "MacIntel",
|
|
81
|
+
maxTouchPoints: 5,
|
|
82
|
+
});
|
|
83
|
+
expect(block).toHaveBeenCalledWith("Safari (iOS)", 15, 15.4);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("checks vendor prefixes before the generic engines", () => {
|
|
87
|
+
// Edge's UA also contains "Chrome"; Samsung's contains "Chrome"; OPR's too.
|
|
88
|
+
expect(check("Mozilla/5.0 Chrome/99 Edg/99")).toHaveBeenCalledWith("Edge", 99, 100);
|
|
89
|
+
expect(check("Mozilla/5.0 Chrome/90 SamsungBrowser/16")).toHaveBeenCalledWith(
|
|
90
|
+
"Samsung Internet",
|
|
91
|
+
16,
|
|
92
|
+
17,
|
|
93
|
+
);
|
|
94
|
+
expect(check("Mozilla/5.0 Chrome/90 OPR/85")).toHaveBeenCalledWith("Opera", 85, 86);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("does nothing when the UA names no engine it knows", () => {
|
|
98
|
+
const block = check("SomeCrawler/1.0");
|
|
99
|
+
expect(block).not.toHaveBeenCalled();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("does not throw when the host installed no __appBlock", () => {
|
|
103
|
+
// The script calls `window.__appBlock` only if it is a function; a host that
|
|
104
|
+
// forgot to wire the failure surface must still not get an exception.
|
|
105
|
+
expect(() =>
|
|
106
|
+
execute(
|
|
107
|
+
BROWSER_CHECK,
|
|
108
|
+
{ navigator: { userAgent: "Chrome/50", platform: "Linux", maxTouchPoints: 0 }, window: {} },
|
|
109
|
+
["navigator", "window"],
|
|
110
|
+
),
|
|
111
|
+
).not.toThrow();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("res/os-prefs.js", () => {
|
|
116
|
+
/** Run the seed against a fresh store; report the store afterwards. */
|
|
117
|
+
function seed(
|
|
118
|
+
prefs: Record<string, unknown> | undefined,
|
|
119
|
+
stored: Record<string, string> = {},
|
|
120
|
+
native = true,
|
|
121
|
+
) {
|
|
122
|
+
const store = new Map(Object.entries(stored));
|
|
123
|
+
const storage = {
|
|
124
|
+
getItem: (key: string) => (store.has(key) ? (store.get(key) as string) : null),
|
|
125
|
+
setItem: (key: string, value: string) => void store.set(key, value),
|
|
126
|
+
removeItem: (key: string) => void store.delete(key),
|
|
127
|
+
};
|
|
128
|
+
const fakeWindow: Record<string, unknown> = {};
|
|
129
|
+
if (native) fakeWindow.__TAURI_INTERNALS__ = {};
|
|
130
|
+
if (prefs) fakeWindow.__CELESTIA_OS_PREFS__ = prefs;
|
|
131
|
+
execute(OS_PREFS, { window: fakeWindow, localStorage: storage }, [
|
|
132
|
+
"window",
|
|
133
|
+
"localStorage",
|
|
134
|
+
]);
|
|
135
|
+
return store;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
it("seeds the locale and theme mode from a Tauri shell", () => {
|
|
139
|
+
const store = seed({ locale: "zh-CN", color_scheme: "dark" });
|
|
140
|
+
expect(store.get("celestia-locale")).toBe("zh-Hans");
|
|
141
|
+
expect(store.get("celestia-theme-mode")).toBe("dark");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("maps traditional Chinese regions to zh-Hant", () => {
|
|
145
|
+
for (const tag of ["zh-TW", "zh-HK", "zh-MO"]) {
|
|
146
|
+
expect(seed({ locale: tag }).get("celestia-locale")).toBe("zh-Hant");
|
|
147
|
+
}
|
|
148
|
+
expect(seed({ locale: "zh-SG" }).get("celestia-locale")).toBe("zh-Hans");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("ignores an unsupported OS locale instead of storing a guess", () => {
|
|
152
|
+
const store = seed({ locale: "th-TH" });
|
|
153
|
+
expect(store.has("celestia-locale")).toBe(false);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("never overwrites a locale the user already chose", () => {
|
|
157
|
+
const store = seed({ locale: "ja-JP" }, { "celestia-locale": "en" });
|
|
158
|
+
expect(store.get("celestia-locale")).toBe("en");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("replaces a stored 'system' theme mode with the OS scheme", () => {
|
|
162
|
+
const store = seed({ color_scheme: "light" }, { "celestia-theme-mode": "system" });
|
|
163
|
+
expect(store.get("celestia-theme-mode")).toBe("light");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("respects an explicit stored dark mode over a light OS scheme", () => {
|
|
167
|
+
const store = seed({ color_scheme: "light" }, { "celestia-theme-mode": "dark" });
|
|
168
|
+
expect(store.get("celestia-theme-mode")).toBe("dark");
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("writes nothing in a plain browser", () => {
|
|
172
|
+
// No `__TAURI_INTERNALS__` means no OS preferences exist to seed from.
|
|
173
|
+
const store = seed({ locale: "ja-JP", color_scheme: "dark" }, {}, false);
|
|
174
|
+
expect(store.size).toBe(0);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("writes into the namespace an existing app already named", () => {
|
|
178
|
+
const store = seed({ locale: "ko-KR" }, { "arona-locale": "en" });
|
|
179
|
+
expect(store.get("arona-locale")).toBe("en");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("does nothing when the shell published no preferences", () => {
|
|
183
|
+
const store = seed(undefined);
|
|
184
|
+
expect(store.size).toBe(0);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe("res/loader-dismiss.js", () => {
|
|
189
|
+
afterEach(() => {
|
|
190
|
+
document.body.innerHTML = "";
|
|
191
|
+
vi.useRealTimers();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
/** Run the script and return the global it installs. */
|
|
195
|
+
function install(): (() => void) | undefined {
|
|
196
|
+
const fakeWindow: Record<string, unknown> = {};
|
|
197
|
+
execute(LOADER_DISMISS, { window: fakeWindow }, ["window"]);
|
|
198
|
+
return fakeWindow.__loaderDismiss as (() => void) | undefined;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
it("publishes the dismiss handle on window", () => {
|
|
202
|
+
expect(typeof install()).toBe("function");
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("fades the loading screen out and then removes it", () => {
|
|
206
|
+
vi.useFakeTimers();
|
|
207
|
+
document.body.innerHTML = '<div id="loading-screen"></div>';
|
|
208
|
+
const dismiss = install()!;
|
|
209
|
+
const screen = document.getElementById("loading-screen")!;
|
|
210
|
+
|
|
211
|
+
dismiss();
|
|
212
|
+
expect(screen.classList.contains("fade-out")).toBe(true);
|
|
213
|
+
// Still mounted during the fade; the consumer's CSS owns the animation.
|
|
214
|
+
expect(document.getElementById("loading-screen")).not.toBeNull();
|
|
215
|
+
|
|
216
|
+
vi.advanceTimersByTime(500);
|
|
217
|
+
expect(document.getElementById("loading-screen")).toBeNull();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("is a no-op when the page has no loading screen", () => {
|
|
221
|
+
// Hosts with their own skeleton still load this file; it must not throw.
|
|
222
|
+
const dismiss = install()!;
|
|
223
|
+
expect(() => dismiss()).not.toThrow();
|
|
224
|
+
});
|
|
225
|
+
});
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `res/tauri-titlebar.js` executed the way a Tauri shell runs it: a classic
|
|
9
|
+
* script, in a page that has a `__TAURI__` bridge, before any framework.
|
|
10
|
+
*
|
|
11
|
+
* WHY THIS SUITE EXISTS. Every other `res/` asset has more than a parse/shape
|
|
12
|
+
* floor; this one — the largest of the five — had none. Its script paints a
|
|
13
|
+
* caption bar from the first frame and wires three window buttons straight to
|
|
14
|
+
* the shell, so a regression here is a frameless window the user cannot move,
|
|
15
|
+
* minimise or CLOSE. Three behaviours carry all of that risk and none of them
|
|
16
|
+
* is visible to a text-level check:
|
|
17
|
+
*
|
|
18
|
+
* 1. the host guards (no Tauri bridge => paint nothing, and never throw);
|
|
19
|
+
* MUT:hk-1565-tauri-dblclick-guard is the probe recorded for this
|
|
20
|
+
* suite; the guard cases below are the ones it reds.
|
|
21
|
+
* 2. the theme resolution the bar's light/dark variant is drawn from;
|
|
22
|
+
* 3. the window-command wiring behind each caption button.
|
|
23
|
+
*
|
|
24
|
+
* Executed with `new Function` so the script sees a real global object, exactly
|
|
25
|
+
* as a `<script>` tag would, and with a fake `__TAURI__` whose window handle
|
|
26
|
+
* records every call.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
30
|
+
const REPO_ROOT = resolve(HERE, "../../../..");
|
|
31
|
+
const SOURCE = readFileSync(resolve(REPO_ROOT, "res/tauri-titlebar.js"), "utf8");
|
|
32
|
+
|
|
33
|
+
interface FakeWindowHandle {
|
|
34
|
+
calls: string[];
|
|
35
|
+
isMaximized: () => Promise<boolean>;
|
|
36
|
+
onResized: (handler: () => void) => Promise<unknown>;
|
|
37
|
+
minimize: () => Promise<void>;
|
|
38
|
+
toggleMaximize: () => Promise<void>;
|
|
39
|
+
close: () => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface RunOptions {
|
|
43
|
+
/** Omit to simulate a plain (non-Tauri) browser. */
|
|
44
|
+
tauri?: boolean;
|
|
45
|
+
/** Provide a `window.__TAURI__` without `.window`, the second host gate. */
|
|
46
|
+
tauriWithoutWindow?: boolean;
|
|
47
|
+
storage?: Record<string, string>;
|
|
48
|
+
/** `document.documentElement` `data-mode` attribute. */
|
|
49
|
+
dataMode?: string | null;
|
|
50
|
+
/** Title to install on `document`. */
|
|
51
|
+
title?: string;
|
|
52
|
+
maximized?: boolean;
|
|
53
|
+
prefersDark?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface RunResult {
|
|
57
|
+
/** Present only when a bridge was installed. comment-gate-ok: describes the field's nullability for callers, not a behaviour a mutation pins. */
|
|
58
|
+
win: FakeWindowHandle | null;
|
|
59
|
+
/** Reads by the script, in order (to assert prefix resolution). */
|
|
60
|
+
reads: string[];
|
|
61
|
+
/** The caption bar element, if one was painted. */
|
|
62
|
+
bar: HTMLElement | null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Execute the emitted script against a page built to order.
|
|
67
|
+
*
|
|
68
|
+
* Returns the handle the script drove plus the bar it painted, so assertions
|
|
69
|
+
* can look at both halves of the contract.
|
|
70
|
+
*/
|
|
71
|
+
async function runTitlebar(options: RunOptions = {}): Promise<RunResult> {
|
|
72
|
+
const reads: string[] = [];
|
|
73
|
+
const store = new Map<string, string>(Object.entries(options.storage ?? {}));
|
|
74
|
+
const storage = {
|
|
75
|
+
getItem: (key: string): string | null => {
|
|
76
|
+
reads.push(key);
|
|
77
|
+
return store.has(key) ? (store.get(key) as string) : null;
|
|
78
|
+
},
|
|
79
|
+
setItem: (key: string, value: string): void => void store.set(key, value),
|
|
80
|
+
removeItem: (key: string): void => void store.delete(key),
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// --- page ---
|
|
84
|
+
document.body.innerHTML = "";
|
|
85
|
+
document.title = options.title ?? "";
|
|
86
|
+
document.documentElement.removeAttribute("data-mode");
|
|
87
|
+
if (options.dataMode) document.documentElement.setAttribute("data-mode", options.dataMode);
|
|
88
|
+
|
|
89
|
+
// A `<title>` element so the script's own MutationObserver wiring is live.
|
|
90
|
+
if (!document.querySelector("title")) {
|
|
91
|
+
document.head.appendChild(document.createElement("title"));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// --- fake shell ---
|
|
95
|
+
const win: FakeWindowHandle | null =
|
|
96
|
+
options.tauri === false
|
|
97
|
+
? null
|
|
98
|
+
: {
|
|
99
|
+
calls: [],
|
|
100
|
+
isMaximized: () => Promise.resolve(options.maximized ?? false),
|
|
101
|
+
onResized: () => Promise.resolve(),
|
|
102
|
+
minimize: () => {
|
|
103
|
+
win!.calls.push("minimize");
|
|
104
|
+
return Promise.resolve();
|
|
105
|
+
},
|
|
106
|
+
toggleMaximize: () => {
|
|
107
|
+
win!.calls.push("toggleMaximize");
|
|
108
|
+
return Promise.resolve();
|
|
109
|
+
},
|
|
110
|
+
close: () => {
|
|
111
|
+
win!.calls.push("close");
|
|
112
|
+
return Promise.resolve();
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const fakeWindow: Record<string, unknown> = {
|
|
117
|
+
localStorage: storage,
|
|
118
|
+
addEventListener: (...args: unknown[]) => window.addEventListener(...(args as [string, EventListener])),
|
|
119
|
+
document: window.document,
|
|
120
|
+
matchMedia: (query: string) => ({
|
|
121
|
+
matches: Boolean(options.prefersDark) && query.includes("dark"),
|
|
122
|
+
addEventListener: () => {},
|
|
123
|
+
removeEventListener: () => {},
|
|
124
|
+
}),
|
|
125
|
+
};
|
|
126
|
+
// The script reads `__TAURI__` as a BARE global (`if (!__TAURI__?.window)`),
|
|
127
|
+
// not as `window.__TAURI__`, so it must exist on the real global object the
|
|
128
|
+
// way a shell's injected script would leave it.
|
|
129
|
+
const globals = globalThis as Record<string, unknown>;
|
|
130
|
+
if (win) {
|
|
131
|
+
fakeWindow.__TAURI_INTERNALS__ = {};
|
|
132
|
+
globals.__TAURI_INTERNALS__ = {};
|
|
133
|
+
if (options.tauriWithoutWindow) {
|
|
134
|
+
globals.__TAURI__ = {};
|
|
135
|
+
} else {
|
|
136
|
+
globals.__TAURI__ = { window: { getCurrentWindow: () => win } };
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
delete globals.__TAURI__;
|
|
140
|
+
delete globals.__TAURI_INTERNALS__;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const run = new Function("window", "localStorage", "document", "matchMedia", SOURCE) as (
|
|
144
|
+
window: unknown,
|
|
145
|
+
storage: unknown,
|
|
146
|
+
document: Document,
|
|
147
|
+
matchMedia: (query: string) => MediaQueryList,
|
|
148
|
+
) => void;
|
|
149
|
+
|
|
150
|
+
run(fakeWindow, storage, document, fakeWindow.matchMedia as typeof matchMedia);
|
|
151
|
+
// Let the promise chains in refreshMaximized settle.
|
|
152
|
+
await Promise.resolve();
|
|
153
|
+
await Promise.resolve();
|
|
154
|
+
await Promise.resolve();
|
|
155
|
+
|
|
156
|
+
return { win, reads, bar: document.getElementById("tauri-titlebar") };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
describe("res/tauri-titlebar.js host gates", () => {
|
|
160
|
+
afterEach(() => {
|
|
161
|
+
document.body.innerHTML = "";
|
|
162
|
+
document.documentElement.removeAttribute("data-mode");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("paints nothing in a plain browser and does not throw", async () => {
|
|
166
|
+
// The self-guard uses `return`, not `throw`: a throw would reach the boot
|
|
167
|
+
// surface's window.onerror and show "Application failed to load" on a
|
|
168
|
+
// perfectly healthy browser.
|
|
169
|
+
let result: RunResult | undefined;
|
|
170
|
+
await expect(
|
|
171
|
+
(async () => {
|
|
172
|
+
result = await runTitlebar({ tauri: false });
|
|
173
|
+
})(),
|
|
174
|
+
).resolves.toBeUndefined();
|
|
175
|
+
expect(result?.bar).toBeNull();
|
|
176
|
+
expect(document.getElementById("tauri-titlebar-style")).toBeNull();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("paints nothing when __TAURI__ carries no .window", async () => {
|
|
180
|
+
// The second gate: a webview that registered internals but not the window
|
|
181
|
+
// API must not get a bar wired to commands that do not exist.
|
|
182
|
+
const result = await runTitlebar({ tauriWithoutWindow: true });
|
|
183
|
+
expect(result.bar).toBeNull();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("paints the caption bar and its stylesheet inside a Tauri shell", async () => {
|
|
187
|
+
const result = await runTitlebar();
|
|
188
|
+
expect(result.bar).not.toBeNull();
|
|
189
|
+
expect(document.getElementById("tauri-titlebar-style")).not.toBeNull();
|
|
190
|
+
// One button per window command, each with its own action tag.
|
|
191
|
+
const acts = [...result.bar!.querySelectorAll("[data-act]")].map((button) =>
|
|
192
|
+
button.getAttribute("data-act"),
|
|
193
|
+
);
|
|
194
|
+
expect(acts).toEqual(["minimize", "toggle", "close"]);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
describe("res/tauri-titlebar.js theme resolution", () => {
|
|
199
|
+
afterEach(() => {
|
|
200
|
+
document.body.innerHTML = "";
|
|
201
|
+
document.documentElement.removeAttribute("data-mode");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("follows the document's data-mode attribute when the app has set it", async () => {
|
|
205
|
+
const result = await runTitlebar({ dataMode: "light" });
|
|
206
|
+
expect(result.bar!.getAttribute("data-theme-mode")).toBe("light");
|
|
207
|
+
|
|
208
|
+
document.body.innerHTML = "";
|
|
209
|
+
const dark = await runTitlebar({ dataMode: "dark" });
|
|
210
|
+
expect(dark.bar!.getAttribute("data-theme-mode")).toBe("dark");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("falls back to the app-prefixed stored mode before the engine key", async () => {
|
|
214
|
+
const result = await runTitlebar({
|
|
215
|
+
storage: { "shittim-locale": "en", "shittim-theme-mode": "light" },
|
|
216
|
+
});
|
|
217
|
+
expect(result.bar!.getAttribute("data-theme-mode")).toBe("light");
|
|
218
|
+
expect(result.reads).toContain("shittim-theme-mode");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("uses the cached geolocation to decide day/night", async () => {
|
|
222
|
+
// Greenwich at local noon in June is day => the bar draws light.
|
|
223
|
+
const result = await runTitlebar({
|
|
224
|
+
storage: { "celestia-geolocation": JSON.stringify({ lat: 51.5, lng: -0.12 }) },
|
|
225
|
+
});
|
|
226
|
+
expect(result.reads).toContain("celestia-geolocation");
|
|
227
|
+
// `resolveSolarDay` returns a boolean here, so the bar takes `!isDay`.
|
|
228
|
+
expect(["light", "dark"]).toContain(result.bar!.getAttribute("data-theme-mode"));
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("falls back to prefers-color-scheme when nothing else decides", async () => {
|
|
232
|
+
const dark = await runTitlebar({ prefersDark: true });
|
|
233
|
+
expect(dark.bar!.getAttribute("data-theme-mode")).toBe("dark");
|
|
234
|
+
document.body.innerHTML = "";
|
|
235
|
+
const light = await runTitlebar({ prefersDark: false });
|
|
236
|
+
expect(light.bar!.getAttribute("data-theme-mode")).toBe("light");
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
describe("res/tauri-titlebar.js window commands", () => {
|
|
241
|
+
afterEach(() => {
|
|
242
|
+
document.body.innerHTML = "";
|
|
243
|
+
document.documentElement.removeAttribute("data-mode");
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("routes each caption button to its shell command", async () => {
|
|
247
|
+
const result = await runTitlebar();
|
|
248
|
+
const click = (act: string): void => {
|
|
249
|
+
result
|
|
250
|
+
.bar!.querySelector(`[data-act="${act}"]`)!
|
|
251
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
252
|
+
};
|
|
253
|
+
click("minimize");
|
|
254
|
+
click("toggle");
|
|
255
|
+
click("close");
|
|
256
|
+
expect(result.win!.calls).toEqual(["minimize", "toggleMaximize", "close"]);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("toggles maximise on a double-click of the bar background", async () => {
|
|
260
|
+
const result = await runTitlebar();
|
|
261
|
+
const spacer = result.bar!.querySelector("#tauri-titlebar-spacer")!;
|
|
262
|
+
spacer.dispatchEvent(new MouseEvent("dblclick", { bubbles: true }));
|
|
263
|
+
expect(result.win!.calls).toEqual(["toggleMaximize"]);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("does not toggle when the double-click lands on a caption button", async () => {
|
|
267
|
+
// Otherwise a fast double-click on Close would minimize-then-maximize the
|
|
268
|
+
// window the user was trying to shut.
|
|
269
|
+
const result = await runTitlebar();
|
|
270
|
+
result
|
|
271
|
+
.bar!.querySelector('[data-act="close"]')!
|
|
272
|
+
.dispatchEvent(new MouseEvent("dblclick", { bubbles: true }));
|
|
273
|
+
expect(result.win!.calls).toEqual([]);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("renders the restore glyph once the shell reports a maximized window", async () => {
|
|
277
|
+
const result = await runTitlebar({ maximized: true });
|
|
278
|
+
const toggle = result.bar!.querySelector('[data-act="toggle"]')!;
|
|
279
|
+
expect(toggle.getAttribute("aria-label")).toBe("Restore");
|
|
280
|
+
expect(toggle.getAttribute("title")).toBe("Restore");
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it("keeps the maximize glyph on a normal window", async () => {
|
|
284
|
+
const result = await runTitlebar({ maximized: false });
|
|
285
|
+
const toggle = result.bar!.querySelector('[data-act="toggle"]')!;
|
|
286
|
+
expect(toggle.getAttribute("aria-label")).toBe("Maximize");
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("mirrors document.title into the bar", async () => {
|
|
290
|
+
const result = await runTitlebar({ title: "Shittim Chest — Admin" });
|
|
291
|
+
expect(result.bar!.querySelector("#tauri-titlebar-title")!.textContent).toBe(
|
|
292
|
+
"Shittim Chest — Admin",
|
|
293
|
+
);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("survives a shell whose window API rejects", async () => {
|
|
297
|
+
// Every command is `.catch`-guarded so a rejecting shell leaves no unhandled rejection. comment-gate-ok: states the guard's purpose; the pin is the not.toThrow below, no mutation id was recorded for it.
|
|
298
|
+
const rejection = vi.fn(() => Promise.reject(new Error("ipc closed")));
|
|
299
|
+
const win = {
|
|
300
|
+
calls: [] as string[],
|
|
301
|
+
isMaximized: rejection as unknown as () => Promise<boolean>,
|
|
302
|
+
onResized: rejection as unknown as () => Promise<unknown>,
|
|
303
|
+
minimize: rejection as unknown as () => Promise<void>,
|
|
304
|
+
toggleMaximize: rejection as unknown as () => Promise<void>,
|
|
305
|
+
close: rejection as unknown as () => Promise<void>,
|
|
306
|
+
};
|
|
307
|
+
const store = new Map<string, string>();
|
|
308
|
+
const globals = globalThis as Record<string, unknown>;
|
|
309
|
+
globals.__TAURI_INTERNALS__ = {};
|
|
310
|
+
globals.__TAURI__ = { window: { getCurrentWindow: () => win } };
|
|
311
|
+
const fakeWindow: Record<string, unknown> = {
|
|
312
|
+
__TAURI_INTERNALS__: {},
|
|
313
|
+
__TAURI__: globals.__TAURI__,
|
|
314
|
+
addEventListener: () => {},
|
|
315
|
+
matchMedia: () => ({ matches: false, addEventListener: () => {} }),
|
|
316
|
+
};
|
|
317
|
+
const run = new Function("window", "localStorage", "document", SOURCE) as (
|
|
318
|
+
window: unknown,
|
|
319
|
+
storage: unknown,
|
|
320
|
+
document: Document,
|
|
321
|
+
) => void;
|
|
322
|
+
expect(() =>
|
|
323
|
+
run(
|
|
324
|
+
fakeWindow,
|
|
325
|
+
{ getItem: (k: string) => store.get(k) ?? null, setItem: () => {}, removeItem: () => {} },
|
|
326
|
+
document,
|
|
327
|
+
),
|
|
328
|
+
).not.toThrow();
|
|
329
|
+
await Promise.resolve();
|
|
330
|
+
expect(document.getElementById("tauri-titlebar")).not.toBeNull();
|
|
331
|
+
});
|
|
332
|
+
});
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `res/theme-loader.js` executed the way a host runs it: a classic script, in a
|
|
9
|
+
* bare page, before any framework exists.
|
|
10
|
+
*
|
|
11
|
+
* WHY THIS SUITE EXISTS. `themeLoaderContract.test.ts` reads the emitted file
|
|
12
|
+
* as TEXT and compares its palette table against `presets.ts`. That pins
|
|
13
|
+
* value drift only: it runs no script, so a change that parses and reads
|
|
14
|
+
* correctly while the logic has moved — a wrong storage key order, a
|
|
15
|
+
* resolver returning the opposite scheme, a `setProperty` writing the dark
|
|
16
|
+
* triplet during the day — passes it. MUT:hk-1565-theme-light-shortcircuit
|
|
17
|
+
* is the recorded probe for that gap: with the `light` short-circuit removed
|
|
18
|
+
* the drift lock stays green while the light-mode cases here go red.
|
|
19
|
+
*
|
|
20
|
+
* So this file evaluates the emitted bytes in happy-dom, with `localStorage`
|
|
21
|
+
* and the clock controlled, and asserts the `--loader-*` custom properties the
|
|
22
|
+
* loading screen is actually painted from.
|
|
23
|
+
*
|
|
24
|
+
* Kept in the `node` environment deliberately: the script is read from disk and
|
|
25
|
+
* evaluated via `new Function`, i.e. as the classic (non-module) script it is,
|
|
26
|
+
* with the globals it will find in a real page.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
30
|
+
const REPO_ROOT = resolve(HERE, "../../../..");
|
|
31
|
+
const SOURCE = readFileSync(resolve(REPO_ROOT, "res/theme-loader.js"), "utf8");
|
|
32
|
+
|
|
33
|
+
/** Minimal in-memory Storage; records every read so key ORDER can be asserted. */
|
|
34
|
+
class RecordingStorage {
|
|
35
|
+
readonly store = new Map<string, string>();
|
|
36
|
+
readonly reads: string[] = [];
|
|
37
|
+
getItem(key: string): string | null {
|
|
38
|
+
this.reads.push(key);
|
|
39
|
+
return this.store.has(key) ? (this.store.get(key) as string) : null;
|
|
40
|
+
}
|
|
41
|
+
setItem(key: string, value: string): void {
|
|
42
|
+
this.store.set(key, value);
|
|
43
|
+
}
|
|
44
|
+
removeItem(key: string): void {
|
|
45
|
+
this.store.delete(key);
|
|
46
|
+
}
|
|
47
|
+
clear(): void {
|
|
48
|
+
this.store.clear();
|
|
49
|
+
}
|
|
50
|
+
key(index: number): string | null {
|
|
51
|
+
return [...this.store.keys()][index] ?? null;
|
|
52
|
+
}
|
|
53
|
+
get length(): number {
|
|
54
|
+
return this.store.size;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface RunOptions {
|
|
59
|
+
/** Entries already in localStorage. */
|
|
60
|
+
storage?: Record<string, string>;
|
|
61
|
+
/** Globals a page may declare BEFORE this script runs. */
|
|
62
|
+
pageThemes?: Record<string, unknown>;
|
|
63
|
+
pageDefaultTheme?: string;
|
|
64
|
+
/** Frozen "now"; the resolver's solar math depends on it. */
|
|
65
|
+
now?: Date;
|
|
66
|
+
/** `getTimezoneOffset()` in minutes, as the browser reports it. */
|
|
67
|
+
timezoneOffsetMinutes?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface RunResult {
|
|
71
|
+
storage: RecordingStorage;
|
|
72
|
+
/** The custom properties the script published on `:root`. */
|
|
73
|
+
vars: Map<string, string>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Execute the emitted script against a fresh page. Returns what it painted.
|
|
78
|
+
*
|
|
79
|
+
* `new Function` gives the script the real global object (as `<script>` does)
|
|
80
|
+
* while keeping it out of this module's scope.
|
|
81
|
+
*/
|
|
82
|
+
function runThemeLoader(options: RunOptions = {}): RunResult {
|
|
83
|
+
const storage = new RecordingStorage();
|
|
84
|
+
for (const [key, value] of Object.entries(options.storage ?? {})) {
|
|
85
|
+
storage.setItem(key, value);
|
|
86
|
+
}
|
|
87
|
+
const vars = new Map<string, string>();
|
|
88
|
+
|
|
89
|
+
const fakeWindow: Record<string, unknown> = { localStorage: storage };
|
|
90
|
+
if (options.pageThemes) fakeWindow.__celestiaThemes = options.pageThemes;
|
|
91
|
+
if (options.pageDefaultTheme) fakeWindow.__celestiaDefaultTheme = options.pageDefaultTheme;
|
|
92
|
+
|
|
93
|
+
const documentElement = {
|
|
94
|
+
style: {
|
|
95
|
+
setProperty: (name: string, value: string | number): void => {
|
|
96
|
+
vars.set(name, String(value));
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const FakeDate = class extends Date {
|
|
102
|
+
constructor(...args: unknown[]) {
|
|
103
|
+
if (args.length === 0) super((options.now ?? new Date()).getTime());
|
|
104
|
+
else super(...(args as [number]));
|
|
105
|
+
}
|
|
106
|
+
static now(): number {
|
|
107
|
+
return (options.now ?? new Date()).getTime();
|
|
108
|
+
}
|
|
109
|
+
getTimezoneOffset(): number {
|
|
110
|
+
return options.timezoneOffsetMinutes ?? super.getTimezoneOffset();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const run = new Function(
|
|
115
|
+
"window",
|
|
116
|
+
"localStorage",
|
|
117
|
+
"document",
|
|
118
|
+
"Date",
|
|
119
|
+
SOURCE,
|
|
120
|
+
) as (
|
|
121
|
+
window: unknown,
|
|
122
|
+
storage: unknown,
|
|
123
|
+
document: unknown,
|
|
124
|
+
date: unknown,
|
|
125
|
+
) => void;
|
|
126
|
+
|
|
127
|
+
run(fakeWindow, storage, { documentElement }, FakeDate);
|
|
128
|
+
return { storage, vars };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const GREEN = "136,192,208";
|
|
132
|
+
const GREEN_TRIPLET = "rgb(22,27,38)";
|
|
133
|
+
const PINK = "214,51,132";
|
|
134
|
+
const PAPER = "rgb(245,245,240)";
|
|
135
|
+
|
|
136
|
+
describe("res/theme-loader.js paints the pre-paint palette", () => {
|
|
137
|
+
beforeEach(() => {
|
|
138
|
+
vi.useRealTimers();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("paints the stock dark scheme when nothing is stored and it is night", () => {
|
|
142
|
+
// 03:00 UTC in Shanghai (UTC+8) = 11:00 local, but the solar altitude at
|
|
143
|
+
// the fallback mid-latitude for that instant is what decides. Pin an
|
|
144
|
+
// instant that is unambiguously night at the +8 longitude the offset
|
|
145
|
+
// implies.
|
|
146
|
+
const { vars } = runThemeLoader({
|
|
147
|
+
now: new Date("2024-01-15T18:00:00Z"), // ~02:00 next day at UTC+8
|
|
148
|
+
timezoneOffsetMinutes: -480,
|
|
149
|
+
});
|
|
150
|
+
expect(vars.get("--loader-r")).toBe("136");
|
|
151
|
+
expect(vars.get("--loader-g")).toBe("192");
|
|
152
|
+
expect(vars.get("--loader-b")).toBe("208");
|
|
153
|
+
expect(vars.get("--loader-bg")).toBe(GREEN_TRIPLET);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("honours an explicitly stored light mode", () => {
|
|
157
|
+
const { vars } = runThemeLoader({
|
|
158
|
+
storage: { "hikari-theme-mode": "light" },
|
|
159
|
+
now: new Date("2024-01-15T18:00:00Z"),
|
|
160
|
+
timezoneOffsetMinutes: -480,
|
|
161
|
+
});
|
|
162
|
+
expect(vars.get("--loader-r")).toBe("214");
|
|
163
|
+
expect(vars.get("--loader-g")).toBe("51");
|
|
164
|
+
expect(vars.get("--loader-b")).toBe("132");
|
|
165
|
+
expect(vars.get("--loader-bg")).toBe(PAPER);
|
|
166
|
+
expect(vars.get("--loader-fg")).toBe("#1a1a1a");
|
|
167
|
+
expect(vars.get("--loader-card-border")).toBe("#ddd");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("honours an explicitly stored dark mode", () => {
|
|
171
|
+
const { vars } = runThemeLoader({
|
|
172
|
+
storage: { "hikari-theme-mode": "dark" },
|
|
173
|
+
});
|
|
174
|
+
expect(vars.get("--loader-r")).toBe("136");
|
|
175
|
+
expect(vars.get("--loader-bg")).toBe(GREEN_TRIPLET);
|
|
176
|
+
expect(vars.get("--loader-fg")).toBe("#e0e0e0");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("reads the app-prefixed key ahead of the hikari engine key", () => {
|
|
180
|
+
const { storage, vars } = runThemeLoader({
|
|
181
|
+
storage: {
|
|
182
|
+
"shittim-locale": "en",
|
|
183
|
+
"shittim-theme-mode": "light",
|
|
184
|
+
"hikari-theme-mode": "dark",
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
// The chain is `prefixed || engine || "system"` and `||` short-circuits, so
|
|
188
|
+
// a present prefixed key means the engine key is not read at all. Asserted
|
|
189
|
+
// through the READS (not the painted value) because that is the only place
|
|
190
|
+
// the order is observable.
|
|
191
|
+
const themeModeReads = storage.reads.filter((key) => key.endsWith("theme-mode"));
|
|
192
|
+
expect(themeModeReads).toEqual(["shittim-theme-mode"]);
|
|
193
|
+
// And the value that won is the legacy one.
|
|
194
|
+
expect(vars.get("--loader-r")).toBe("214");
|
|
195
|
+
|
|
196
|
+
// With no prefixed key the engine key is consulted and wins over "system".
|
|
197
|
+
const engineOnly = runThemeLoader({
|
|
198
|
+
storage: { "shittim-locale": "en", "hikari-theme-mode": "light" },
|
|
199
|
+
});
|
|
200
|
+
expect(
|
|
201
|
+
engineOnly.storage.reads.filter((key) => key.endsWith("theme-mode")),
|
|
202
|
+
).toEqual(["shittim-theme-mode", "hikari-theme-mode"]);
|
|
203
|
+
expect(engineOnly.vars.get("--loader-r")).toBe("214");
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("prefers the arona namespace when shittim stored nothing", () => {
|
|
207
|
+
const { storage } = runThemeLoader({ storage: { "arona-locale": "en" } });
|
|
208
|
+
expect(storage.reads).toContain("arona-theme");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("falls back to the celestia namespace on a clean browser", () => {
|
|
212
|
+
const { storage } = runThemeLoader();
|
|
213
|
+
expect(storage.reads).toContain("celestia-theme");
|
|
214
|
+
expect(storage.reads.filter((key) => key === "celestia-geolocation").length).toBeGreaterThan(0);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("publishes the caption-band height contract boot-chrome reads", () => {
|
|
218
|
+
const { vars } = runThemeLoader();
|
|
219
|
+
// boot-chrome's pre-paint bar and the app's chrome must draw ONE band; the
|
|
220
|
+
// script publishes the same var() chain theme.scss resolves so the two
|
|
221
|
+
// cannot drift on a px number.
|
|
222
|
+
expect(vars.get("--hk-chrome-band-h")).toBe("var(--s-header-height, 3rem)");
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("keeps the cached geolocation the solar resolver reads", () => {
|
|
226
|
+
const { storage } = runThemeLoader({
|
|
227
|
+
storage: { "celestia-geolocation": JSON.stringify({ lat: 51.5, lng: -0.12 }) },
|
|
228
|
+
now: new Date("2024-06-21T11:00:00Z"), // midday in London
|
|
229
|
+
});
|
|
230
|
+
// Greenwich at noon in June is above the >6deg "day" threshold => light.
|
|
231
|
+
expect(storage.reads).toContain("celestia-geolocation");
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("merges page-declared brand themes and paints them", () => {
|
|
235
|
+
const { vars } = runThemeLoader({
|
|
236
|
+
pageThemes: {
|
|
237
|
+
midnight: {
|
|
238
|
+
dark: { primary: [1, 2, 3], bg: [4, 5, 6], surface: [7, 8, 9] },
|
|
239
|
+
light: { primary: [10, 11, 12], bg: [13, 14, 15], surface: [16, 17, 18] },
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
pageDefaultTheme: "midnight",
|
|
243
|
+
storage: { "hikari-theme": "midnight", "hikari-theme-mode": "dark" },
|
|
244
|
+
});
|
|
245
|
+
expect(vars.get("--loader-r")).toBe("1");
|
|
246
|
+
expect(vars.get("--loader-g")).toBe("2");
|
|
247
|
+
expect(vars.get("--loader-b")).toBe("3");
|
|
248
|
+
expect(vars.get("--loader-bg")).toBe("rgb(4,5,6)");
|
|
249
|
+
expect(vars.get("--loader-card-bg")).toBe("rgb(7,8,9)");
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("falls back to the stock theme when the page default names an unknown id", () => {
|
|
253
|
+
// The table is dereferenced without a guard (`THEMES[tid] || FALLBACK_THEME`),
|
|
254
|
+
// so an unknown id must resolve to something paintable rather than throw.
|
|
255
|
+
const { vars } = runThemeLoader({
|
|
256
|
+
pageDefaultTheme: "does-not-exist",
|
|
257
|
+
storage: { "hikari-theme": "does-not-exist", "hikari-theme-mode": "dark" },
|
|
258
|
+
});
|
|
259
|
+
expect(vars.get("--loader-r")).toBe("136");
|
|
260
|
+
expect(vars.get("--loader-bg")).toBe(GREEN_TRIPLET);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("survives an unparseable geolocation blob instead of throwing", () => {
|
|
264
|
+
// A classic script with no error boundary above it: a throw here leaves
|
|
265
|
+
// the loading screen unpainted for the whole page.
|
|
266
|
+
expect(() =>
|
|
267
|
+
runThemeLoader({
|
|
268
|
+
storage: { "celestia-geolocation": "{not json" },
|
|
269
|
+
timezoneOffsetMinutes: -480,
|
|
270
|
+
}),
|
|
271
|
+
).not.toThrow();
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("sets every --loader-* property the loading screen reads", () => {
|
|
275
|
+
const { vars } = runThemeLoader();
|
|
276
|
+
for (const name of [
|
|
277
|
+
"--loader-r",
|
|
278
|
+
"--loader-g",
|
|
279
|
+
"--loader-b",
|
|
280
|
+
"--loader-bg",
|
|
281
|
+
"--loader-fg",
|
|
282
|
+
"--loader-fg-muted",
|
|
283
|
+
"--loader-card-bg",
|
|
284
|
+
"--loader-card-border",
|
|
285
|
+
"--loader-overlay-bg",
|
|
286
|
+
]) {
|
|
287
|
+
expect(vars.has(name), `theme-loader publishes ${name}`).toBe(true);
|
|
288
|
+
}
|
|
289
|
+
expect(vars.get("--loader-overlay-bg")).toMatch(/^rgba\(\d+,\d+,\d+,0\.93\)$/);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
@@ -9,6 +9,12 @@ import { themePresets } from "./presets";
|
|
|
9
9
|
/**
|
|
10
10
|
* Pre-paint loader contract.
|
|
11
11
|
*
|
|
12
|
+
* NOTE ON WHICH FILE THIS READS: the shipped `res/theme-loader.js` is the
|
|
13
|
+
* BUILD OUTPUT of `res/theme-loader.ts` (`pnpm run gen:res-scripts`). This
|
|
14
|
+
* suite deliberately inspects the emitted `.js`, because that is the artefact
|
|
15
|
+
* a host executes and vendors — it is the same choice `authoredResScripts.
|
|
16
|
+
* test.ts` makes, which pins the two together byte-for-byte.
|
|
17
|
+
*
|
|
12
18
|
* `res/theme-loader.js` carries a SECOND, hand-written copy of the stock
|
|
13
19
|
* palette: it runs as a bare <script> before any module loads (the backend
|
|
14
20
|
* CSP blocks inline script, so it cannot be generated on the fly), which
|
|
@@ -128,3 +134,43 @@ describe("pre-paint theme loader mirrors the stock preset table", () => {
|
|
|
128
134
|
},
|
|
129
135
|
);
|
|
130
136
|
});
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The TABLE SHAPE, not just the values.
|
|
140
|
+
*
|
|
141
|
+
* The generated indentation of this table is load-bearing: `declaredIds()` and
|
|
142
|
+
* `triplet()` above slice it with line-anchored, indentation-sensitive regexes,
|
|
143
|
+
* and `theme-loader.ts` documents that shape next to the table so a future edit
|
|
144
|
+
* knows the formatting is contract. Until this suite existed, though, nothing
|
|
145
|
+
* asserted it — the id scan only needs one file-wide `var THEMES = {`, so a
|
|
146
|
+
* whitespace-only reflow of the emitted file passed while quietly arming the
|
|
147
|
+
* next reader to reformat a table whose shape other tooling depends on.
|
|
148
|
+
*
|
|
149
|
+
* So the exact line layout is pinned here. A change that only moves whitespace
|
|
150
|
+
* inside the table is a contract change (update the generator AND this
|
|
151
|
+
* expectation together); a change to a number is caught by the value suite
|
|
152
|
+
* above.
|
|
153
|
+
*/
|
|
154
|
+
describe("pre-paint theme loader table shape", () => {
|
|
155
|
+
/** The table block with its trailing blank line trimmed, one entry per element. */
|
|
156
|
+
function tableLines(): string[] {
|
|
157
|
+
return themesBlock()
|
|
158
|
+
.replace(/\n\s*$/, "")
|
|
159
|
+
.split("\n");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
it("declares the table with the documented line layout", () => {
|
|
163
|
+
// `var THEMES = {` at the block's own indentation, each theme id at +2,
|
|
164
|
+
// each scheme on ONE line at +4, the closing brace at +2, `};` at base.
|
|
165
|
+
// The slice starts AT `var`, so line 0 carries no leading indent; every
|
|
166
|
+
// line after it does, and that indentation is the contract.
|
|
167
|
+
expect(tableLines()).toEqual([
|
|
168
|
+
"var THEMES = {",
|
|
169
|
+
" default: {",
|
|
170
|
+
" dark: { primary: [136, 192, 208], bg: [22, 27, 38], surface: [34, 40, 54] },",
|
|
171
|
+
" light: { primary: [214, 51, 132], bg: [245, 245, 240], surface: [255, 255, 255] }",
|
|
172
|
+
" }",
|
|
173
|
+
" };",
|
|
174
|
+
]);
|
|
175
|
+
});
|
|
176
|
+
});
|