mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
test(reference-source): share file entry fixtures (#16099)
This commit is contained in:
1 parent
9880145c57
commit
64fcc7f65f
1 file changed
+24
-73
@@ -9,6 +9,17 @@ import {
|
||||
} from "../domain/referenceSourceGraph.js";
|
||||
import type { ReferenceSourceRead } from "../reference/ReferenceSourceReaderTypes.js";
|
||||
|
||||
const sourceFile = (
|
||||
path: string,
|
||||
content: string,
|
||||
): ReferenceSourceRead["entries"][number] => ({
|
||||
status: "read",
|
||||
kind: "file",
|
||||
path,
|
||||
bytes: Buffer.from(content),
|
||||
size: Buffer.byteLength(content),
|
||||
});
|
||||
|
||||
const readSourceFiles = (
|
||||
files: readonly (readonly [
|
||||
path: string,
|
||||
@@ -17,13 +28,7 @@ const readSourceFiles = (
|
||||
])[],
|
||||
): ReferenceSourceRead => ({
|
||||
root: "/selected/source",
|
||||
entries: files.map(([path, content]) => ({
|
||||
status: "read",
|
||||
kind: "file",
|
||||
path,
|
||||
bytes: Buffer.from(content),
|
||||
size: Buffer.byteLength(content),
|
||||
})),
|
||||
entries: files.map(([path, content]) => sourceFile(path, content)),
|
||||
bytesRead: files.reduce(
|
||||
(sum, [, content]) => sum + Buffer.byteLength(content),
|
||||
0,
|
||||
@@ -250,21 +255,7 @@ it("resolves declared package mains and index fallback from source-owned fields"
|
||||
["json-package/index.js", 'module.exports = "fallback index";\n'],
|
||||
["emitted.ts", 'export const value = "source counterpart";\n'],
|
||||
] as const;
|
||||
const read: ReferenceSourceRead = {
|
||||
root: "/selected/source",
|
||||
entries: files.map(([path, content]) => ({
|
||||
status: "read",
|
||||
kind: "file",
|
||||
path,
|
||||
bytes: Buffer.from(content),
|
||||
size: Buffer.byteLength(content),
|
||||
})),
|
||||
bytesRead: files.reduce(
|
||||
(sum, [, content]) => sum + Buffer.byteLength(content),
|
||||
0,
|
||||
),
|
||||
limitations: [],
|
||||
};
|
||||
const read = readSourceFiles(files);
|
||||
|
||||
const previous = Object.getOwnPropertyDescriptor(Object.prototype, "main");
|
||||
let parsed: ReturnType<typeof parseReferenceSourceEntries>;
|
||||
@@ -414,30 +405,20 @@ it("resolves extensionless imports and requires to .mts and .cts files and direc
|
||||
});
|
||||
|
||||
it("does not infer missing candidates or manifests from partial directory enumeration", () => {
|
||||
const file = (
|
||||
path: string,
|
||||
content: string,
|
||||
): ReferenceSourceRead["entries"][number] => ({
|
||||
status: "read",
|
||||
kind: "file",
|
||||
path,
|
||||
bytes: Buffer.from(content),
|
||||
size: Buffer.byteLength(content),
|
||||
});
|
||||
const read: ReferenceSourceRead = {
|
||||
root: "/selected/source",
|
||||
bytesRead: 0,
|
||||
limitations: [],
|
||||
entries: [
|
||||
file("package.json", '{"type":"commonjs"}'),
|
||||
file(
|
||||
sourceFile("package.json", '{"type":"commonjs"}'),
|
||||
sourceFile(
|
||||
"main.cjs",
|
||||
'require("./pkg"); require("./other"); require("./exact.js");',
|
||||
),
|
||||
file("pkg/index.js", "module.exports = 1;"),
|
||||
file("other/index.js", "module.exports = 1;"),
|
||||
file("exact.js", "module.exports = 1;"),
|
||||
file("pkg/source.js", 'require("../exact.js");'),
|
||||
sourceFile("pkg/index.js", "module.exports = 1;"),
|
||||
sourceFile("other/index.js", "module.exports = 1;"),
|
||||
sourceFile("exact.js", "module.exports = 1;"),
|
||||
sourceFile("pkg/source.js", 'require("../exact.js");'),
|
||||
{
|
||||
status: "failed",
|
||||
kind: "directory",
|
||||
@@ -492,13 +473,7 @@ it.each(["failed", "excluded"] as const)(
|
||||
bytesRead: 0,
|
||||
limitations: [],
|
||||
entries: [
|
||||
...files.map(([path, content]) => ({
|
||||
status: "read" as const,
|
||||
kind: "file" as const,
|
||||
path,
|
||||
bytes: Buffer.from(content),
|
||||
size: Buffer.byteLength(content),
|
||||
})),
|
||||
...files.map(([path, content]) => sourceFile(path, content)),
|
||||
...(state === "failed"
|
||||
? [
|
||||
{
|
||||
@@ -548,13 +523,7 @@ it("retains observed manifests and closer completed scopes inside a partial inve
|
||||
bytesRead: 0,
|
||||
limitations: [],
|
||||
entries: [
|
||||
...files.map(([path, content]) => ({
|
||||
status: "read" as const,
|
||||
kind: "file" as const,
|
||||
path,
|
||||
bytes: Buffer.from(content),
|
||||
size: Buffer.byteLength(content),
|
||||
})),
|
||||
...files.map(([path, content]) => sourceFile(path, content)),
|
||||
{
|
||||
status: "failed",
|
||||
kind: "directory",
|
||||
@@ -601,13 +570,7 @@ it("keeps ambiguous directory coverage unknown while honoring exact directory id
|
||||
bytesRead: 0,
|
||||
limitations: [],
|
||||
entries: [
|
||||
...files.map(([path, content]) => ({
|
||||
status: "read" as const,
|
||||
kind: "file" as const,
|
||||
path,
|
||||
bytes: Buffer.from(content),
|
||||
size: Buffer.byteLength(content),
|
||||
})),
|
||||
...files.map(([path, content]) => sourceFile(path, content)),
|
||||
{
|
||||
status: "failed",
|
||||
kind: "directory",
|
||||
@@ -644,13 +607,7 @@ it("does not skip an ambiguous higher priority file for an observed extension fa
|
||||
root: "/selected/source",
|
||||
bytesRead: 0,
|
||||
limitations: [],
|
||||
entries: files.map(([path, content]) => ({
|
||||
status: "read" as const,
|
||||
kind: "file" as const,
|
||||
path,
|
||||
bytes: Buffer.from(content),
|
||||
size: Buffer.byteLength(content),
|
||||
})),
|
||||
entries: files.map(([path, content]) => sourceFile(path, content)),
|
||||
},
|
||||
[],
|
||||
);
|
||||
@@ -673,13 +630,7 @@ it("prefers a later exact filename over an earlier unique canonical candidate",
|
||||
root: "/selected/source",
|
||||
bytesRead: 0,
|
||||
limitations: [],
|
||||
entries: files.map(([path, content]) => ({
|
||||
status: "read" as const,
|
||||
kind: "file" as const,
|
||||
path,
|
||||
bytes: Buffer.from(content),
|
||||
size: Buffer.byteLength(content),
|
||||
})),
|
||||
entries: files.map(([path, content]) => sourceFile(path, content)),
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user