mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
test(routes): consolidate JavaScript route behavior coverage
This commit is contained in:
1 parent
e6e4215227
commit
b2af0d77e0
5 files changed
+447
-532
No files matched your search
@@ -6,12 +6,11 @@ import { createJavaScriptNextAppContext } from "./JavaScriptNextAppContext.js";
|
||||
|
||||
const contextFor = (
|
||||
files: readonly JavaScriptArtifactFile[],
|
||||
documents: JavaScriptJsonDocuments,
|
||||
directories: ReadonlySet<string>,
|
||||
) =>
|
||||
createJavaScriptNextAppContext(
|
||||
{ files, unavailable_relevant_files: [] },
|
||||
documents,
|
||||
new JavaScriptJsonDocuments(),
|
||||
directories,
|
||||
{ scope: "container-entries", status: "complete" },
|
||||
);
|
||||
@@ -27,7 +26,7 @@ const file = (path: string, text = ""): JavaScriptArtifactFile => ({
|
||||
text: { included: true, value: text },
|
||||
});
|
||||
|
||||
it("keeps package applicability and its root cache scoped to the source container", () => {
|
||||
it("keeps readable package applicability scoped to its source container", () => {
|
||||
const manifest = file("package.json", '{"dependencies":{"next":"16.4.2"}}');
|
||||
const foreign = {
|
||||
...file("package.json", '{"name":"plain"}'),
|
||||
@@ -37,7 +36,6 @@ it("keeps package applicability and its root cache scoped to the source containe
|
||||
const foreignPage = { ...page, container_sha256: foreign.container_sha256 };
|
||||
const context = contextFor(
|
||||
[manifest, foreign, page, foreignPage],
|
||||
new JavaScriptJsonDocuments(),
|
||||
new Set(["app"]),
|
||||
);
|
||||
expect(context(page)).toMatchObject({
|
||||
@@ -48,80 +46,20 @@ it("keeps package applicability and its root cache scoped to the source containe
|
||||
kind: "unknown",
|
||||
package: { container_sha256: foreign.container_sha256 },
|
||||
});
|
||||
expect(context(page).kind).toBe("app-directory");
|
||||
});
|
||||
|
||||
it("uses the nearest declared Next package and root directory precedence", () => {
|
||||
const files = [
|
||||
file("package.json", '{"dependencies":{"next":"16.4.2"}}'),
|
||||
file("app/page.js"),
|
||||
file("src/app/control/page.js"),
|
||||
file("pages/app/page.js"),
|
||||
file("components/app/page.js"),
|
||||
file("node_modules/ordinary/package.json", '{"name":"ordinary"}'),
|
||||
file("node_modules/ordinary/app/page.js"),
|
||||
];
|
||||
const context = contextFor(
|
||||
files,
|
||||
new JavaScriptJsonDocuments(),
|
||||
new Set([
|
||||
"app",
|
||||
"src/app",
|
||||
"pages",
|
||||
"components/app",
|
||||
"node_modules/ordinary/app",
|
||||
]),
|
||||
);
|
||||
expect(context(files[1]!)).toMatchObject({
|
||||
kind: "app-directory",
|
||||
directory: "app",
|
||||
package: { path: "package.json" },
|
||||
});
|
||||
for (const source of files.slice(2, 5))
|
||||
expect(context(source).kind).toBe("outside-app-directory");
|
||||
expect(context(files[6]!)).toMatchObject({
|
||||
kind: "unknown",
|
||||
package: { path: "node_modules/ordinary/package.json" },
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps default compiled output under its declared package and unrelated chunk-like paths unknown", () => {
|
||||
const manifest = file("package.json", '{"dependencies":{"next":"16.4.2"}}');
|
||||
const chunk = file(".next/static/chunks/app/build/page-abc.js");
|
||||
const context = contextFor(
|
||||
[manifest, chunk],
|
||||
new JavaScriptJsonDocuments(),
|
||||
new Set(),
|
||||
);
|
||||
const context = contextFor([manifest, chunk], new Set());
|
||||
expect(context(chunk)).toMatchObject({
|
||||
kind: "compiled-directory",
|
||||
directory: ".next/static/chunks/app",
|
||||
});
|
||||
expect(
|
||||
contextFor([chunk], new JavaScriptJsonDocuments(), new Set())(chunk),
|
||||
).toMatchObject({ kind: "unknown" });
|
||||
});
|
||||
|
||||
it("supports src/app only when app is not inventoried and retains missing framework identity", () => {
|
||||
const manifest = file(
|
||||
"package.json",
|
||||
'{"devDependencies":{"next":"16.4.2"}}',
|
||||
);
|
||||
const page = file("src/app/control/page.js");
|
||||
expect(
|
||||
contextFor(
|
||||
[manifest, page],
|
||||
new JavaScriptJsonDocuments(),
|
||||
new Set(["src/app"]),
|
||||
)(page),
|
||||
).toMatchObject({ kind: "app-directory", directory: "src/app" });
|
||||
expect(
|
||||
contextFor(
|
||||
[page],
|
||||
new JavaScriptJsonDocuments(),
|
||||
new Set(["src/app"]),
|
||||
)(page),
|
||||
).toMatchObject({ kind: "unknown", package: null });
|
||||
expect(contextFor([chunk], new Set())(chunk)).toMatchObject({
|
||||
kind: "unknown",
|
||||
package: null,
|
||||
});
|
||||
});
|
||||
|
||||
it("does not infer absent manifests or higher-priority directories from incomplete traversal", () => {
|
||||
@@ -140,14 +78,7 @@ it("does not infer absent manifests or higher-priority directories from incomple
|
||||
reason: expect.stringContaining("src/app/control/package.json"),
|
||||
});
|
||||
const rootPage = file("page.js");
|
||||
expect(
|
||||
createJavaScriptNextAppContext(
|
||||
files,
|
||||
new JavaScriptJsonDocuments(),
|
||||
new Set(["src/app"]),
|
||||
{ scope: "container-entries", status: "unknown" },
|
||||
)(rootPage),
|
||||
).toMatchObject({
|
||||
expect(context(rootPage)).toMatchObject({
|
||||
kind: "unknown",
|
||||
package: { path: "package.json" },
|
||||
reason: expect.stringContaining("higher-priority app directory"),
|
||||
@@ -167,39 +98,28 @@ it("retains the nearest unavailable manifest's evidence instead of borrowing an
|
||||
kind: "package-json" as const,
|
||||
limitations: ["The unpacked package companion is missing."],
|
||||
};
|
||||
const foreignContainer = "c".repeat(64);
|
||||
const foreignParent = { ...parent, container_sha256: foreignContainer };
|
||||
const foreignPage = { ...page, container_sha256: foreignContainer };
|
||||
const context = createJavaScriptNextAppContext(
|
||||
{ files: [parent, page], unavailable_relevant_files: [unavailable] },
|
||||
new JavaScriptJsonDocuments(),
|
||||
new Set(["app", "app/widget/app"]),
|
||||
{ scope: "container-entries", status: "complete" },
|
||||
);
|
||||
expect(context(page)).toMatchObject({
|
||||
kind: "unknown",
|
||||
package: null,
|
||||
reason: expect.stringContaining(unavailable.path),
|
||||
});
|
||||
const result = context(page);
|
||||
if (result.kind !== "unknown")
|
||||
throw new Error("Expected unknown package ownership");
|
||||
expect(result.reason).toContain(unavailable.inventory_occurrence_id);
|
||||
expect(result.reason).toContain(unavailable.limitations[0]);
|
||||
expect(context(file("app/page.js"))).toMatchObject({
|
||||
kind: "app-directory",
|
||||
package: { path: parent.path },
|
||||
});
|
||||
const foreign = createJavaScriptNextAppContext(
|
||||
{
|
||||
files: [parent, page],
|
||||
unavailable_relevant_files: [
|
||||
{ ...unavailable, container_sha256: "c".repeat(64) },
|
||||
],
|
||||
files: [parent, page, foreignParent, foreignPage],
|
||||
unavailable_relevant_files: [unavailable],
|
||||
},
|
||||
new JavaScriptJsonDocuments(),
|
||||
new Set(["app", "app/widget/app"]),
|
||||
{ scope: "container-entries", status: "complete" },
|
||||
);
|
||||
expect(foreign(page)).toMatchObject({
|
||||
const result = context(page);
|
||||
expect(result).toMatchObject({ kind: "unknown", package: null });
|
||||
if (result.kind !== "unknown")
|
||||
throw new Error("Expected unknown package ownership");
|
||||
expect(result.reason).toContain(unavailable.path);
|
||||
expect(result.reason).toContain(unavailable.inventory_occurrence_id);
|
||||
expect(result.reason).toContain(unavailable.limitations[0]);
|
||||
expect(context(foreignPage)).toMatchObject({
|
||||
kind: "app-directory",
|
||||
package: { path: parent.path },
|
||||
directory: "app",
|
||||
package: { path: parent.path, container_sha256: foreignContainer },
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user