@unframework.dev/testing 0.0.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +31 -11
- package/dist/config/project-vite.d.ts +40 -0
- package/dist/config/project-vite.js +152 -0
- package/dist/harness.d.ts +5 -0
- package/dist/node/mode.d.ts +2 -0
- package/dist/node/mode.js +4 -1
- package/dist/node/visual.js +6 -3
- package/package.json +24 -13
package/README.md
CHANGED
|
@@ -76,6 +76,22 @@ one `browser:<target>` project in Chromium and one `ssr:<target>` project for ea
|
|
|
76
76
|
| `toolchainDirs` | `package.resolveFrom`, then the root | Where each target's compiler stack resolves from (Angular's) |
|
|
77
77
|
| `root` | the working directory | Where `unframework.config.ts` is: case ids are relative to it |
|
|
78
78
|
|
|
79
|
+
- **A project's Vite config** (ADR-0104), `vite` in `unframework.config.ts`: each `browser:` and
|
|
80
|
+
`ssr:` project calls it with `{ target, mode }` and merges what it gives with
|
|
81
|
+
`withProjectVite(config, vite, context)`: the project's plugins, flattened, before the
|
|
82
|
+
unplugin, and every other key through Vite's `mergeConfig` after the toolchain's fragment. It
|
|
83
|
+
refuses the keys a server owns (`OWNED_KEYS`, `OWNED_SERVER_KEYS`) and throws, naming the field
|
|
84
|
+
and the reason, on a function that throws, a promise that rejects, a value that is no config or
|
|
85
|
+
a plugin with no `name`. `projectPlugins(vite, context)` gives `ToolchainContext.plugins`, so
|
|
86
|
+
Astro's render server loads the plugins too. The preview builds its servers with both.
|
|
87
|
+
- **Pass-through declarations** (ADR-0104): `passThroughDeclarations(root)` writes
|
|
88
|
+
`node_modules/.cache/unframework/pass-through.d.ts`, with `declare module "virtual:*";` for each
|
|
89
|
+
default prefix, and every toolchain gets it as `ToolchainContext.declarations`, so Angular's
|
|
90
|
+
ngtsc takes any pass-through module with no type file from the project.
|
|
91
|
+
- **A project's live fonts** (ADR-0105): `liveFonts` reaches the run's `HarnessContext`, and in
|
|
92
|
+
a live comparison `captureAt`'s font audit lets a glyph in a listed family pass, as CDP names
|
|
93
|
+
it. A comparison with baselines takes Inter alone, whatever the list says.
|
|
94
|
+
|
|
79
95
|
- **A case** is a directory with one test file. Its id is its path from the root, and its main
|
|
80
96
|
source is `case.json`'s `main`, relative to the case and maybe outside it, or else its only
|
|
81
97
|
`.uf.tsx` (`discoverCases`, `src/config/cases.ts`). Two test files in one directory, no main
|
|
@@ -510,3 +526,12 @@ adapter, whose rerender needs the toolchain's render command (`vitest.config.ts`
|
|
|
510
526
|
`UF_UPDATE=1 pnpm exec vitest run --config test/parity/vitest.config.ts` rewrites the artefacts.
|
|
511
527
|
|
|
512
528
|
The `stub/matchers` case proves each matcher passes and fails with its message, and that Vitest's own `toMatchAriaInlineSnapshot` still behaves as Vitest's once the setup has run.
|
|
529
|
+
|
|
530
|
+
`test/project-plugins.test.ts` runs the fixture projects under `test/fixtures/` with their own
|
|
531
|
+
Vitest, as `unframework test` does: `project-plugins`, whose component imports
|
|
532
|
+
`virtual:uf-fixture`, which only the plugin its config's `vite` names serves, passes on all seven
|
|
533
|
+
targets with no declaration file, and `no-project-plugins`, the same component with no plugin,
|
|
534
|
+
fails to resolve the import. `test/project-vite.test.ts` covers the calls, the merge, the refused
|
|
535
|
+
keys, the failures and the declaration file, on throwaway projects, one of them on seven targets
|
|
536
|
+
under `test/fixtures/.config-*`. Their
|
|
537
|
+
expectations come from `unframework test --update`, run in the fixture's directory.
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PixelMode } from "../harness.js";
|
|
2
2
|
import { DiscoverOptions, ProjectCase, discoverCases } from "./cases.js";
|
|
3
|
+
import { OWNED_KEYS, OWNED_SERVER_KEYS, PASS_THROUGH_DECLARATIONS, ProjectPlugins, ProjectVite, passThroughDeclarations, projectPlugins, withProjectVite } from "./project-vite.js";
|
|
3
4
|
import { TargetName } from "@unframework.dev/compiler";
|
|
4
5
|
import { ViteUserConfig } from "vitest/config";
|
|
5
6
|
import { Toolchain } from "@unframework.dev/codegen";
|
|
@@ -78,4 +79,4 @@ export declare function loadToolchain(target: TargetName): Promise<Toolchain>;
|
|
|
78
79
|
*/
|
|
79
80
|
export declare function toolchainClientFile(toolchain: Toolchain): string;
|
|
80
81
|
//#endregion
|
|
81
|
-
export { type DiscoverOptions, type ProjectCase, discoverCases };
|
|
82
|
+
export { type DiscoverOptions, OWNED_KEYS, OWNED_SERVER_KEYS, PASS_THROUGH_DECLARATIONS, type ProjectCase, type ProjectPlugins, type ProjectVite, discoverCases, passThroughDeclarations, projectPlugins, withProjectVite };
|
package/dist/config/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { parityBrowser } from "../node/browser.js";
|
|
|
5
5
|
import { ufMapStack } from "../node/thrown.js";
|
|
6
6
|
import { noErrorBroadcast } from "./broadcast.js";
|
|
7
7
|
import { EXCLUDED, discoverCases } from "./cases.js";
|
|
8
|
+
import { OWNED_KEYS, OWNED_SERVER_KEYS, PASS_THROUGH_DECLARATIONS, passThroughDeclarations, projectPlugins, withProjectVite } from "./project-vite.js";
|
|
8
9
|
import { realpathSync } from "node:fs";
|
|
9
10
|
import { join, resolve } from "node:path";
|
|
10
11
|
import { TARGET_NAMES, builtinTargets, loadConfig, resolveConfig } from "@unframework.dev/compiler";
|
|
@@ -60,7 +61,8 @@ async function defineTestConfig(options = {}) {
|
|
|
60
61
|
mode,
|
|
61
62
|
quarantine: [],
|
|
62
63
|
cases: Object.fromEntries(cases.map((info) => [info.id, info.config])),
|
|
63
|
-
updateCommand: "unframework test --update"
|
|
64
|
+
updateCommand: "unframework test --update",
|
|
65
|
+
liveFonts: config.liveFonts
|
|
64
66
|
});
|
|
65
67
|
const named = caseReferences(harness);
|
|
66
68
|
checkTargets("a case's reference", named, targets);
|
|
@@ -71,7 +73,9 @@ async function defineTestConfig(options = {}) {
|
|
|
71
73
|
mode,
|
|
72
74
|
cases,
|
|
73
75
|
targets: run,
|
|
74
|
-
toolchainDir: (target) => toolchainDirOf(target, root, options.toolchainDirs, config.package?.resolveFrom)
|
|
76
|
+
toolchainDir: (target) => toolchainDirOf(target, root, options.toolchainDirs, config.package?.resolveFrom),
|
|
77
|
+
vite: config.vite,
|
|
78
|
+
declarations: passThroughDeclarations(root)
|
|
75
79
|
};
|
|
76
80
|
return { test: { projects: await Promise.all(run.flatMap((target) => [browserProject(setup, target), ssrProject(setup, target)])) } };
|
|
77
81
|
}
|
|
@@ -155,10 +159,20 @@ async function unpluginOf(target) {
|
|
|
155
159
|
onCompile: (event) => recordCompiledModule(event)
|
|
156
160
|
});
|
|
157
161
|
}
|
|
158
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Where a target's toolchain runs the project's tests: Angular's ngtsc compiles with the
|
|
164
|
+
* pass-through declarations, and a server of the toolchain's own (Astro's render server) loads
|
|
165
|
+
* the project's plugins for the same target and kind of server (ADR-0104).
|
|
166
|
+
*/
|
|
167
|
+
function toolchainContext(setup, target, mode) {
|
|
159
168
|
return {
|
|
160
169
|
toolchainDir: setup.toolchainDir(target),
|
|
161
|
-
root: setup.root
|
|
170
|
+
root: setup.root,
|
|
171
|
+
declarations: setup.declarations,
|
|
172
|
+
plugins: projectPlugins(setup.vite, {
|
|
173
|
+
target,
|
|
174
|
+
mode
|
|
175
|
+
})
|
|
162
176
|
};
|
|
163
177
|
}
|
|
164
178
|
/**
|
|
@@ -192,17 +206,20 @@ function toolchainClientFile(toolchain) {
|
|
|
192
206
|
async function browserProject(setup, target) {
|
|
193
207
|
const name = `browser:${target}`;
|
|
194
208
|
const toolchain = await loadToolchain(target);
|
|
195
|
-
const context = toolchainContext(setup, target);
|
|
209
|
+
const context = toolchainContext(setup, target, "browser");
|
|
196
210
|
const fragment = await toolchain.vite("browser", context);
|
|
197
211
|
return {
|
|
198
|
-
...mergeConfig({
|
|
212
|
+
...await withProjectVite(mergeConfig({
|
|
199
213
|
root: setup.root,
|
|
200
214
|
plugins: [...await unpluginOf(target), noErrorBroadcast()],
|
|
201
215
|
optimizeDeps: {
|
|
202
216
|
include: ["@unframework.dev/testing > axe-core", "@unframework.dev/testing > parse5"],
|
|
203
217
|
exclude: ["@unframework.dev/testing", "@unframework.dev/target-qwik"]
|
|
204
218
|
}
|
|
205
|
-
}, fragment),
|
|
219
|
+
}, fragment), setup.vite, {
|
|
220
|
+
target,
|
|
221
|
+
mode: "browser"
|
|
222
|
+
}),
|
|
206
223
|
extends: false,
|
|
207
224
|
test: projectTest(target, fragment.test, {
|
|
208
225
|
testTimeout: TEST_TIMEOUT,
|
|
@@ -238,11 +255,14 @@ async function browserProject(setup, target) {
|
|
|
238
255
|
}
|
|
239
256
|
async function ssrProject(setup, target) {
|
|
240
257
|
const toolchain = await loadToolchain(target);
|
|
241
|
-
const fragment = await toolchain.vite("ssr", toolchainContext(setup, target));
|
|
242
|
-
const config = mergeConfig({
|
|
258
|
+
const fragment = await toolchain.vite("ssr", toolchainContext(setup, target, "ssr"));
|
|
259
|
+
const config = await withProjectVite(mergeConfig({
|
|
243
260
|
root: setup.root,
|
|
244
261
|
plugins: await unpluginOf(target)
|
|
245
|
-
}, fragment)
|
|
262
|
+
}, fragment), setup.vite, {
|
|
263
|
+
target,
|
|
264
|
+
mode: "ssr"
|
|
265
|
+
});
|
|
246
266
|
const cases = setup.cases.map((info) => ({
|
|
247
267
|
id: info.id,
|
|
248
268
|
dir: info.dir,
|
|
@@ -272,4 +292,4 @@ async function ssrProject(setup, target) {
|
|
|
272
292
|
};
|
|
273
293
|
}
|
|
274
294
|
//#endregion
|
|
275
|
-
export { DEFAULT_INCLUDE, TARGET_PACKAGES, TESTING_PACKAGE, defineTestConfig, discoverCases, loadToolchain, runTargets, selectedTargets, toolchainClientFile, toolchainDirOf };
|
|
295
|
+
export { DEFAULT_INCLUDE, OWNED_KEYS, OWNED_SERVER_KEYS, PASS_THROUGH_DECLARATIONS, TARGET_PACKAGES, TESTING_PACKAGE, defineTestConfig, discoverCases, loadToolchain, passThroughDeclarations, projectPlugins, runTargets, selectedTargets, toolchainClientFile, toolchainDirOf, withProjectVite };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { UnframeworkConfig, ViteContext } from "@unframework.dev/compiler";
|
|
2
|
+
import { ToolchainContext } from "@unframework.dev/codegen";
|
|
3
|
+
//#region src/config/project-vite.d.ts
|
|
4
|
+
/** The project's `vite` function, as `unframework.config.ts` gives it. */
|
|
5
|
+
export type ProjectVite = UnframeworkConfig["vite"];
|
|
6
|
+
/** What `ToolchainContext.plugins` takes: a function that makes a fresh set of Vite plugins. */
|
|
7
|
+
export type ProjectPlugins = NonNullable<ToolchainContext["plugins"]>;
|
|
8
|
+
/**
|
|
9
|
+
* The keys every server sets for itself, which the project's config may not set: its root, its
|
|
10
|
+
* caches, its Vitest options, and the preview's refusal to load a Vite config of its own or to
|
|
11
|
+
* listen beyond this machine (ADR-0088).
|
|
12
|
+
*/
|
|
13
|
+
export declare const OWNED_KEYS: readonly string[];
|
|
14
|
+
/**
|
|
15
|
+
* The `server` keys every server sets for itself: the preview listens on `127.0.0.1` alone, and an
|
|
16
|
+
* HMR server of its own (`server.hmr`) would open a WebSocket server that listens beyond it.
|
|
17
|
+
*/
|
|
18
|
+
export declare const OWNED_SERVER_KEYS: readonly string[];
|
|
19
|
+
/**
|
|
20
|
+
* A server's config with the project's merged in (ADR-0104): the project's plugins first, before
|
|
21
|
+
* the unframework plugin, and every other key merged after the server's own with Vite's
|
|
22
|
+
* `mergeConfig`, so a list such as `optimizeDeps.include` adds to the server's.
|
|
23
|
+
*/
|
|
24
|
+
export declare function withProjectVite<T extends object>(config: T, vite: ProjectVite, context: ViteContext): Promise<T>;
|
|
25
|
+
/**
|
|
26
|
+
* The project's plugins for one server, as `ToolchainContext.plugins` takes them: each call makes
|
|
27
|
+
* a fresh set for a server of the toolchain's own, such as Astro's render server, which takes
|
|
28
|
+
* the plugins alone.
|
|
29
|
+
*/
|
|
30
|
+
export declare function projectPlugins(vite: ProjectVite, context: ViteContext): ProjectPlugins;
|
|
31
|
+
/** The declaration file's contents: one wildcard module for each pass-through prefix. */
|
|
32
|
+
export declare const PASS_THROUGH_DECLARATIONS: string;
|
|
33
|
+
/**
|
|
34
|
+
* The declarations every toolchain reads beside the outputs (`ToolchainContext.declarations`):
|
|
35
|
+
* one file, written under the root's `node_modules/.cache/unframework/`, since the packages ship
|
|
36
|
+
* `dist` alone. It is written only when it differs, through a rename, so runs that share a root
|
|
37
|
+
* never read half of it.
|
|
38
|
+
*/
|
|
39
|
+
export declare function passThroughDeclarations(root: string): string[];
|
|
40
|
+
//#endregion
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { DEFAULT_PASS_THROUGH } from "@unframework.dev/compiler";
|
|
4
|
+
import { mergeConfig } from "vitest/config";
|
|
5
|
+
//#region src/config/project-vite.ts
|
|
6
|
+
/**
|
|
7
|
+
* The keys every server sets for itself, which the project's config may not set: its root, its
|
|
8
|
+
* caches, its Vitest options, and the preview's refusal to load a Vite config of its own or to
|
|
9
|
+
* listen beyond this machine (ADR-0088).
|
|
10
|
+
*/
|
|
11
|
+
const OWNED_KEYS = [
|
|
12
|
+
"root",
|
|
13
|
+
"base",
|
|
14
|
+
"cacheDir",
|
|
15
|
+
"test",
|
|
16
|
+
"configFile",
|
|
17
|
+
"envDir"
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* The `server` keys every server sets for itself: the preview listens on `127.0.0.1` alone, and an
|
|
21
|
+
* HMR server of its own (`server.hmr`) would open a WebSocket server that listens beyond it.
|
|
22
|
+
*/
|
|
23
|
+
const OWNED_SERVER_KEYS = [
|
|
24
|
+
"host",
|
|
25
|
+
"port",
|
|
26
|
+
"strictPort",
|
|
27
|
+
"hmr"
|
|
28
|
+
];
|
|
29
|
+
/** Where every message about the field points. */
|
|
30
|
+
const FIELD = "vite in unframework.config.ts";
|
|
31
|
+
/**
|
|
32
|
+
* Calls the project's `vite` for one server, and checks what it gives. Throws, naming the field
|
|
33
|
+
* and the reason, when it throws, a promise it gives rejects, it gives something that is no
|
|
34
|
+
* config or no plugin, or it sets a key the server owns: a check that cannot start fails, and
|
|
35
|
+
* says why.
|
|
36
|
+
*/
|
|
37
|
+
async function serverConfig(vite, context) {
|
|
38
|
+
if (!vite) return {
|
|
39
|
+
plugins: [],
|
|
40
|
+
rest: {}
|
|
41
|
+
};
|
|
42
|
+
let made;
|
|
43
|
+
try {
|
|
44
|
+
made = await vite(context);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw failed("threw", error);
|
|
47
|
+
}
|
|
48
|
+
if (typeof made !== "object" || made === null || Array.isArray(made)) throw new Error(`[uf] ${FIELD} gave ${describeValue(made)}, which is no Vite config: return an object, such as \`{ plugins: [engine()] }\`.`);
|
|
49
|
+
const { plugins, ...rest } = made;
|
|
50
|
+
const owned = OWNED_KEYS.filter((key) => key in rest);
|
|
51
|
+
const server = rest.server;
|
|
52
|
+
if ("server" in rest && (typeof server !== "object" || server === null || Array.isArray(server))) throw new Error(`[uf] ${FIELD} gives \`server\` as ${describeValue(server)}, which is no object: give the server keys it may set, such as \`{ fs: { allow: [".."] } }\`.`);
|
|
53
|
+
if (server) {
|
|
54
|
+
const keys = Object.keys(server);
|
|
55
|
+
owned.push(...OWNED_SERVER_KEYS.filter((key) => keys.includes(key)).map((key) => `server.${key}`));
|
|
56
|
+
}
|
|
57
|
+
if (owned.length) throw new Error(`[uf] ${FIELD} sets ${owned.map((key) => `\`${key}\``).join(", ")}, which the ${context.mode} server for ${context.target} sets itself: leave ${owned.length > 1 ? "them" : "it"} out.`);
|
|
58
|
+
return {
|
|
59
|
+
plugins: await flattenPlugins(plugins),
|
|
60
|
+
rest
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A server's config with the project's merged in (ADR-0104): the project's plugins first, before
|
|
65
|
+
* the unframework plugin, and every other key merged after the server's own with Vite's
|
|
66
|
+
* `mergeConfig`, so a list such as `optimizeDeps.include` adds to the server's.
|
|
67
|
+
*/
|
|
68
|
+
async function withProjectVite(config, vite, context) {
|
|
69
|
+
const project = await serverConfig(vite, context);
|
|
70
|
+
const own = config.plugins;
|
|
71
|
+
return {
|
|
72
|
+
...mergeConfig(config, project.rest),
|
|
73
|
+
plugins: [...project.plugins, ...Array.isArray(own) ? own : []]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The project's plugins for one server, as `ToolchainContext.plugins` takes them: each call makes
|
|
78
|
+
* a fresh set for a server of the toolchain's own, such as Astro's render server, which takes
|
|
79
|
+
* the plugins alone.
|
|
80
|
+
*/
|
|
81
|
+
function projectPlugins(vite, context) {
|
|
82
|
+
return async () => (await serverConfig(vite, context)).plugins;
|
|
83
|
+
}
|
|
84
|
+
/** A plugin option in any shape Vite's `plugins` takes, flattened: read as `unknown`, since the project's code gives it. */
|
|
85
|
+
async function flattenPlugins(option) {
|
|
86
|
+
let value;
|
|
87
|
+
try {
|
|
88
|
+
value = await option;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
throw failed("gave a promise that rejected", error);
|
|
91
|
+
}
|
|
92
|
+
if (value === false || value === null || value === void 0) return [];
|
|
93
|
+
if (Array.isArray(value)) return (await Promise.all(value.map((each) => flattenPlugins(each)))).flat();
|
|
94
|
+
if (typeof value !== "object" || typeof value.name !== "string") throw new Error(`[uf] ${FIELD} gave ${describeValue(value)} among its plugins, which is no Vite plugin: a plugin is an object with a name.`);
|
|
95
|
+
return [value];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The error of a function or a promise of the field's that failed. The CLI prints a message
|
|
99
|
+
* alone, so the reason is in it, as well as in `cause`.
|
|
100
|
+
*/
|
|
101
|
+
function failed(what, error) {
|
|
102
|
+
const reason = error instanceof Error ? String(error.message) || "an error with no message" : describeValue(error);
|
|
103
|
+
return new Error(`[uf] ${FIELD} ${what}: ${reason}`, { cause: error });
|
|
104
|
+
}
|
|
105
|
+
/** A value as a message names it, whatever it is. */
|
|
106
|
+
function describeValue(value) {
|
|
107
|
+
switch (typeof value) {
|
|
108
|
+
case "string": return JSON.stringify(value);
|
|
109
|
+
case "object":
|
|
110
|
+
if (value === null) return "null";
|
|
111
|
+
if (Array.isArray(value)) return "a list";
|
|
112
|
+
return "name" in value ? "an object whose name is no string" : "an object without a name";
|
|
113
|
+
case "function": return "a function";
|
|
114
|
+
case "symbol": return value.toString();
|
|
115
|
+
case "number":
|
|
116
|
+
case "bigint":
|
|
117
|
+
case "boolean": return `${value}`;
|
|
118
|
+
default: return "undefined";
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** The declaration file's contents: one wildcard module for each pass-through prefix. */
|
|
122
|
+
const PASS_THROUGH_DECLARATIONS = [
|
|
123
|
+
"// Written by @unframework.dev/testing (ADR-0104): Angular's compile in `unframework test`,",
|
|
124
|
+
"// `visual` and `preview` takes any module that passes through as written. The project's own",
|
|
125
|
+
"// source check (tsconfig.uf.json) reads the real types.",
|
|
126
|
+
...DEFAULT_PASS_THROUGH.map((prefix) => `declare module "${prefix}*";`),
|
|
127
|
+
""
|
|
128
|
+
].join("\n");
|
|
129
|
+
/**
|
|
130
|
+
* The declarations every toolchain reads beside the outputs (`ToolchainContext.declarations`):
|
|
131
|
+
* one file, written under the root's `node_modules/.cache/unframework/`, since the packages ship
|
|
132
|
+
* `dist` alone. It is written only when it differs, through a rename, so runs that share a root
|
|
133
|
+
* never read half of it.
|
|
134
|
+
*/
|
|
135
|
+
function passThroughDeclarations(root) {
|
|
136
|
+
const file = join(root, "node_modules", ".cache", "unframework", "pass-through.d.ts");
|
|
137
|
+
let current;
|
|
138
|
+
try {
|
|
139
|
+
current = readFileSync(file, "utf8");
|
|
140
|
+
} catch {
|
|
141
|
+
current = void 0;
|
|
142
|
+
}
|
|
143
|
+
if (current !== PASS_THROUGH_DECLARATIONS) {
|
|
144
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
145
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
146
|
+
writeFileSync(temporary, PASS_THROUGH_DECLARATIONS);
|
|
147
|
+
renameSync(temporary, file);
|
|
148
|
+
}
|
|
149
|
+
return [file];
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
export { OWNED_KEYS, OWNED_SERVER_KEYS, PASS_THROUGH_DECLARATIONS, passThroughDeclarations, projectPlugins, withProjectVite };
|
package/dist/harness.d.ts
CHANGED
|
@@ -79,6 +79,11 @@ export interface HarnessContext {
|
|
|
79
79
|
*/
|
|
80
80
|
updateCommand?: string;
|
|
81
81
|
pixels: PixelMode;
|
|
82
|
+
/**
|
|
83
|
+
* The font families that may draw text in a live capture besides the bundled Inter: the
|
|
84
|
+
* project's `liveFonts` (ADR-0105). A comparison with committed baselines ignores them.
|
|
85
|
+
*/
|
|
86
|
+
liveFonts?: readonly string[];
|
|
82
87
|
/** The canary installed in this run (`UF_CANARY`), or `null`. */
|
|
83
88
|
canary: string | null;
|
|
84
89
|
/**
|
package/dist/node/mode.d.ts
CHANGED
|
@@ -89,6 +89,8 @@ export interface HarnessRunOptions {
|
|
|
89
89
|
cases: Record<string, CaseConfig>;
|
|
90
90
|
/** The command a failure names to write the artefacts (`HarnessContext.updateCommand`). */
|
|
91
91
|
updateCommand?: string;
|
|
92
|
+
/** The font families a live capture may take (`HarnessContext.liveFonts`, ADR-0105). */
|
|
93
|
+
liveFonts?: readonly string[];
|
|
92
94
|
}
|
|
93
95
|
/**
|
|
94
96
|
* Creates the run's context, once per process: Vitest evaluates the config file more than once
|
package/dist/node/mode.js
CHANGED
|
@@ -138,6 +138,8 @@ function createHarnessRun(options) {
|
|
|
138
138
|
if (existing && existing.casesDir === options.casesDir) {
|
|
139
139
|
existing.cases = options.cases;
|
|
140
140
|
existing.quarantine = quarantine;
|
|
141
|
+
if (options.liveFonts === void 0) delete existing.liveFonts;
|
|
142
|
+
else existing.liveFonts = options.liveFonts;
|
|
141
143
|
return existing;
|
|
142
144
|
}
|
|
143
145
|
const runId = `${Date.now().toString(36)}-${process.pid}`;
|
|
@@ -161,7 +163,8 @@ function createHarnessRun(options) {
|
|
|
161
163
|
diffsDir: join(scratch.diffs, runId),
|
|
162
164
|
quarantine,
|
|
163
165
|
cases: options.cases,
|
|
164
|
-
...options.updateCommand === void 0 ? {} : { updateCommand: options.updateCommand }
|
|
166
|
+
...options.updateCommand === void 0 ? {} : { updateCommand: options.updateCommand },
|
|
167
|
+
...options.liveFonts === void 0 ? {} : { liveFonts: options.liveFonts }
|
|
165
168
|
};
|
|
166
169
|
store[RUN] = run;
|
|
167
170
|
return run;
|
package/dist/node/visual.js
CHANGED
|
@@ -77,7 +77,8 @@ async function captureAt(context, request, location) {
|
|
|
77
77
|
...location.capture && captured ? { capture: location.capture } : {},
|
|
78
78
|
...result
|
|
79
79
|
});
|
|
80
|
-
const
|
|
80
|
+
const families = harness.pixels === "live" ? harness.liveFonts ?? [] : [];
|
|
81
|
+
const fontViolations = harness.browser === "chromium" ? await fontAudit(context.page, request.marker, families) : [];
|
|
81
82
|
if (fontViolations.length) return done({
|
|
82
83
|
pass: false,
|
|
83
84
|
outcome: "font-fallback",
|
|
@@ -253,13 +254,14 @@ async function stableCapture(context, request) {
|
|
|
253
254
|
/**
|
|
254
255
|
* Lists every font Chromium used for text under the capture container that is not an allowed
|
|
255
256
|
* web font. CDP reports the font file's internal family name, so the bundled "UF Test Sans" is
|
|
256
|
-
* allowed as "Inter" plus `isCustomFont
|
|
257
|
+
* allowed as "Inter" plus `isCustomFont`, and each of `families` by that name, a web font or a
|
|
258
|
+
* system font alike.
|
|
257
259
|
*
|
|
258
260
|
* It walks the pierced DOM tree, so it reaches what a selector cannot: user-agent shadow roots
|
|
259
261
|
* (a `<textarea>`'s text, an `<input>`'s value and placeholder) and generated content
|
|
260
262
|
* (`::before`, `::after`, a list marker).
|
|
261
263
|
*/
|
|
262
|
-
async function fontAudit(page, marker) {
|
|
264
|
+
async function fontAudit(page, marker, families) {
|
|
263
265
|
let session = cdpSessions.get(page);
|
|
264
266
|
if (!session) {
|
|
265
267
|
session = (async () => {
|
|
@@ -310,6 +312,7 @@ async function fontAudit(page, marker) {
|
|
|
310
312
|
const { fonts } = await cdp.send("CSS.getPlatformFontsForNode", { nodeId });
|
|
311
313
|
for (const font of fonts) {
|
|
312
314
|
if (font.isCustomFont && ALLOWED_FONTS.includes(font.familyName)) continue;
|
|
315
|
+
if (families.includes(font.familyName)) continue;
|
|
313
316
|
violations.add(`${label} rendered ${font.glyphCount} glyph(s) with "${font.familyName}"${font.isCustomFont ? "" : " (system font)"}`);
|
|
314
317
|
}
|
|
315
318
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unframework.dev/testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "The cross-target test API: describeTargets, it, mount, mountScenario, the View with its parity checks, and the axe and ARIA matchers. The harness's machinery, the mount adapters, the SSR renderers and normalisation are internal subpaths. Private until its first release.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"testing",
|
|
@@ -100,31 +100,42 @@
|
|
|
100
100
|
"dependencies": {
|
|
101
101
|
"@fontsource/inter": "^5.3.0",
|
|
102
102
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
103
|
-
"@unframework.dev/codegen": "0.
|
|
104
|
-
"@unframework.dev/compiler": "0.
|
|
105
|
-
"@unframework.dev/ir": "0.
|
|
106
|
-
"@unframework.dev/target-angular": "0.
|
|
107
|
-
"@unframework.dev/target-astro": "0.
|
|
108
|
-
"@unframework.dev/target-qwik": "0.
|
|
109
|
-
"@unframework.dev/target-react": "0.
|
|
110
|
-
"@unframework.dev/target-solid": "0.
|
|
111
|
-
"@unframework.dev/target-svelte": "0.
|
|
112
|
-
"@unframework.dev/target-vue": "0.
|
|
113
|
-
"@unframework.dev/unplugin": "0.
|
|
103
|
+
"@unframework.dev/codegen": "0.1.1",
|
|
104
|
+
"@unframework.dev/compiler": "0.2.1",
|
|
105
|
+
"@unframework.dev/ir": "0.1.0",
|
|
106
|
+
"@unframework.dev/target-angular": "0.1.1",
|
|
107
|
+
"@unframework.dev/target-astro": "0.1.1",
|
|
108
|
+
"@unframework.dev/target-qwik": "0.1.1",
|
|
109
|
+
"@unframework.dev/target-react": "0.1.1",
|
|
110
|
+
"@unframework.dev/target-solid": "0.1.1",
|
|
111
|
+
"@unframework.dev/target-svelte": "0.1.1",
|
|
112
|
+
"@unframework.dev/target-vue": "0.1.1",
|
|
113
|
+
"@unframework.dev/unplugin": "0.1.2",
|
|
114
114
|
"axe-core": "4.13.0",
|
|
115
115
|
"parse5": "^8.0.1",
|
|
116
116
|
"pixelmatch": "^7.2.0",
|
|
117
117
|
"pngjs": "^7.0.0"
|
|
118
118
|
},
|
|
119
119
|
"devDependencies": {
|
|
120
|
+
"@angular/common": "22.2.1",
|
|
121
|
+
"@angular/core": "22.2.1",
|
|
122
|
+
"@babel/core": "7.29.7",
|
|
123
|
+
"@qwik.dev/core": "2.0.0-beta.47",
|
|
120
124
|
"@types/node": "^24.19.0",
|
|
121
125
|
"@types/pngjs": "^6.0.5",
|
|
122
126
|
"@uxfront/typescript-config": "^0.1.0",
|
|
123
127
|
"@vitest/browser-playwright": "5.0.3",
|
|
128
|
+
"astro": "7.3.5",
|
|
129
|
+
"babel-preset-solid": "1.9.15",
|
|
124
130
|
"playwright": "1.63.0",
|
|
131
|
+
"react": "19.3.0",
|
|
132
|
+
"react-dom": "19.3.0",
|
|
133
|
+
"solid-js": "1.9.15",
|
|
134
|
+
"svelte": "5.57.1",
|
|
125
135
|
"tsdown": "^0.23.0",
|
|
126
136
|
"vite": "8.3.1",
|
|
127
|
-
"vitest": "5.0.3"
|
|
137
|
+
"vitest": "5.0.3",
|
|
138
|
+
"vue": "3.5.43"
|
|
128
139
|
},
|
|
129
140
|
"peerDependencies": {
|
|
130
141
|
"@vitest/browser-playwright": "5.0.3",
|