test: extract shared fixtures, drop knip carve-outs (#627)

* refactor(domain): consolidate canonical ordering and digest helpers (#624)

* refactor(domain): consolidate canonical ordering and digest helpers

Single owner for code-point ordering (domain/canonicalOrdering.ts)
and canonical JSON digests (domain/comparisonSemantics.ts). Delete
all local compareCodePoints/compareText/digestCanonical duplicates
and migrate every importer. No re-export shims.

* fix(ci): allow slower real browser startup

* chore(config): remove dead eslint, dedupe scripts, cacheable turbo tasks

Delete eslint.config.js (oxlint is the linter), drop lint:dead alias,
pin smol-toml, fold jscpd/scan:todos into check:pr, make test:run
cacheable, align oxlint ignores.

* fix(config): hash all test inputs for cached runs

* docs: fix architecture diagram and pretty-print tool catalog

Drop dangling REPLAY edges, add dotnet/reference/error/evaluation
nodes. Emit 2-space JSON from the catalog generator and regenerate.

* test: extract shared fixtures, drop knip carve-outs

Dedupe android/apple session tests, bundler adapter headers, and
reconstruction helpers into tests/support fixtures. Delete unused
type aliases and the knip ignoreIssues block. Lower jscpd threshold
2.7 to 2.5.
This commit is contained in:
morluto authored and GitHub committed 2026-10-06 05:00:16 +08:00
1 parent 5e7f35c7c3
commit 55e5eb090b
14 files changed
+375 -354

No files matched your search

@@ -1,29 +1,43 @@
import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { reconstructJavaScriptArtifact } from "../../../src/application/JavaScriptArtifactReconstruction.js";
import type {
ApplicationEdge,
ApplicationNode,
JavaScriptApplicationGraph,
} from "../../../src/domain/javascriptApplicationGraph.js";
import {
findChunkNode,
findGraphEdge,
findModuleNodeByKey,
reconstructJavaScriptFixture,
writeFixtureFiles,
} from "../../support/javascriptApplicationFixture.js";
describe("Webpack and Rspack runtime adapters", () => {
it("recovers runtime entry modules, async chunks, and factory require aliases", async () => {
const root = await bundlerFixture();
const result = await reconstructJavaScriptArtifact({ input_path: root });
const result = await reconstructJavaScriptFixture(root);
const graph = result.graph;
const webpackEntry = chunk(graph, "webpackChunkcustomPortal", "main");
const webpackLazy = chunk(graph, "webpackChunkcustomPortal", "lazy");
const webpackModule = moduleNode(graph, "10");
const rspackEntry = chunk(graph, "rspackChunkcustomPortal", "editor");
const rspackModel = chunk(graph, "rspackChunkcustomPortal", "model");
const rspackModule = moduleNode(graph, "src/entry.ts");
const webpackEntry = findChunkNode(
graph,
"webpackChunkcustomPortal",
"main",
);
const webpackLazy = findChunkNode(
graph,
"webpackChunkcustomPortal",
"lazy",
);
const webpackModule = findModuleNodeByKey(graph, "10");
const rspackEntry = findChunkNode(
graph,
"rspackChunkcustomPortal",
"editor",
);
const rspackModel = findChunkNode(
graph,
"rspackChunkcustomPortal",
"model",
);
const rspackModule = findModuleNodeByKey(graph, "src/entry.ts");
expect(webpackEntry?.observations[0]?.properties).toMatchObject({
bundler: "webpack",
@@ -49,32 +63,42 @@ describe("Webpack and Rspack runtime adapters", () => {
runtime_entry: true,
});
expect(edge(graph, webpackEntry, webpackModule, "loads")).toMatchObject({
expect(
findGraphEdge(graph, webpackEntry, webpackModule, "loads"),
).toMatchObject({
properties: expect.objectContaining({
kind: "bundler-entry-module",
resolution_status: "resolved",
}),
});
expect(edge(graph, webpackEntry, webpackLazy, "imports")).toMatchObject({
expect(
findGraphEdge(graph, webpackEntry, webpackLazy, "imports"),
).toMatchObject({
properties: expect.objectContaining({
kind: "bundler-async-chunk",
resolution_status: "resolved",
}),
});
expect(edge(graph, webpackModule, webpackLazy, "imports")).toMatchObject({
expect(
findGraphEdge(graph, webpackModule, webpackLazy, "imports"),
).toMatchObject({
properties: expect.objectContaining({
kind: "dynamic-import",
specifier: "chunk:lazy",
resolved_path: "renderer/chunks/runtime.js#chunk:lazy",
}),
});
expect(edge(graph, rspackEntry, rspackModel, "imports")).toMatchObject({
expect(
findGraphEdge(graph, rspackEntry, rspackModel, "imports"),
).toMatchObject({
properties: expect.objectContaining({
kind: "bundler-async-chunk",
resolution_status: "resolved",
}),
});
expect(edge(graph, rspackModule, rspackModel, "imports")).toMatchObject({
expect(
findGraphEdge(graph, rspackModule, rspackModel, "imports"),
).toMatchObject({
properties: expect.objectContaining({
kind: "dynamic-import",
specifier: "chunk:model",
@@ -103,11 +127,9 @@ describe("Webpack and Rspack runtime adapters", () => {
it("recovers esbuild wrapper modules and Vite preload dependencies", async () => {
const root = await esmRuntimeFixture();
const { graph } = await reconstructJavaScriptArtifact({
input_path: root,
});
const commonJsModule = moduleNode(graph, "src/dep.js");
const esmModule = moduleNode(graph, "src/core.js");
const { graph } = await reconstructJavaScriptFixture(root);
const commonJsModule = findModuleNodeByKey(graph, "src/dep.js");
const esmModule = findModuleNodeByKey(graph, "src/core.js");
expect(commonJsModule?.observations[0]?.properties).toMatchObject({
bundler: "esbuild",
@@ -132,10 +154,8 @@ describe("Webpack and Rspack runtime adapters", () => {
const bundlerFixture = async (): Promise<string> => {
const root = await createTestTempDirectory("rea-bundler-adapters-");
await mkdir(join(root, "renderer", "chunks"), { recursive: true });
await writeFile(
join(root, "renderer", "chunks", "runtime.js"),
`
await writeFixtureFiles(root, {
"renderer/chunks/runtime.js": `
var __webpack_module_cache__ = {};
(globalThis["webpackChunkcustomPortal"] = globalThis["webpackChunkcustomPortal"] || []).push([
["main"],
@@ -179,15 +199,14 @@ const bundlerFixture = async (): Promise<string> => {
}
]);
`,
);
});
return root;
};
const esmRuntimeFixture = async (): Promise<string> => {
const root = await createTestTempDirectory("rea-esm-runtime-adapters-");
await writeFile(
join(root, "main.js"),
`
await writeFixtureFiles(root, {
"main.js": `
const __vite__mapDeps = (indexes, map = __vite__mapDeps, dependencies =
(map.f || (map.f = ["./feature.js", "./main.css"]))) =>
indexes.map((index) => dependencies[index]);
@@ -204,51 +223,8 @@ const esmRuntimeFixture = async (): Promise<string> => {
__vite__mapDeps([0, 1]);
init_core();
`,
);
await writeFile(join(root, "feature.js"), "export const feature = true;");
await writeFile(join(root, "main.css"), ".app { color: green; }");
"feature.js": "export const feature = true;",
"main.css": ".app { color: green; }",
});
return root;
};
const chunk = (
graph: JavaScriptApplicationGraph,
runtime: string,
chunkKey: string,
): ApplicationNode | undefined =>
graph.nodes.find(
({ kind, observations }) =>
kind === "javascript-chunk" &&
observations.some(
({ properties }) =>
properties.runtime === runtime &&
Array.isArray(properties.chunk_keys) &&
properties.chunk_keys.includes(chunkKey),
),
);
const moduleNode = (
graph: JavaScriptApplicationGraph,
moduleKey: string,
): ApplicationNode | undefined =>
graph.nodes.find(
({ kind, observations }) =>
kind === "javascript-module" &&
observations.some(
({ properties }) => properties.module_key === moduleKey,
),
);
const edge = (
graph: JavaScriptApplicationGraph,
source: ApplicationNode | undefined,
target: ApplicationNode | undefined,
relation: string,
): ApplicationEdge | undefined =>
graph.edges.find(
({ source_node_id, target_node_id, relation: edgeRelation }) =>
source !== undefined &&
target !== undefined &&
source_node_id === source.node_id &&
target_node_id === target.node_id &&
edgeRelation === relation,
);