Split the monolithic `src/csv-loader/loader.test.ts` into multiple specialized test files to improve maintainability and readability: - `parseCsv-basic.test.ts`: Primitive types, arrays, and tuples - `parseCsv-caching.test.ts`: Table caching logic - `parseCsv-circular.test.ts`: Circular reference detection - `parseCsv-combinators.test.ts`: References in unions and tuples - `parseCsv-noResolveRefs.
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { parseCsv } from "../loader";
|
|
import * as path from "path";
|
|
import { fixturesDir, readFixture } from "../test-utils";
|
|
|
|
describe("parseCsv - circular reference detection", () => {
|
|
it("should detect self-referencing circular reference", () => {
|
|
const csv = ["id,name,parent", "string,string,@self_ref", "1,Root,2"].join(
|
|
"\n",
|
|
);
|
|
|
|
expect(() =>
|
|
parseCsv(csv, {
|
|
emitTypes: false,
|
|
currentFilePath: path.join(fixturesDir, "self_ref.csv"),
|
|
}),
|
|
).toThrow(/Circular reference detected/);
|
|
});
|
|
|
|
it("should detect mutual circular reference (A -> B -> A)", () => {
|
|
const csv = readFixture("circular_a.csv");
|
|
|
|
expect(() =>
|
|
parseCsv(csv, {
|
|
emitTypes: false,
|
|
currentFilePath: path.join(fixturesDir, "circular_a.csv"),
|
|
}),
|
|
).toThrow(/Circular reference detected/);
|
|
});
|
|
|
|
it("should allow same table referenced from multiple columns without circular reference", () => {
|
|
const usersCsv = readFixture("users.csv");
|
|
const csv = ["id,creator,reviewer", "string,@users,@users", "1,1,2"].join(
|
|
"\n",
|
|
);
|
|
|
|
const result = parseCsv(csv, {
|
|
emitTypes: false,
|
|
currentFilePath: path.join(fixturesDir, "test.csv"),
|
|
});
|
|
|
|
expect(result.data[0].creator).toEqual({
|
|
id: "1",
|
|
name: "Alice",
|
|
email: "alice@example.com",
|
|
});
|
|
expect(result.data[0].reviewer).toEqual({
|
|
id: "2",
|
|
name: "Bob",
|
|
email: "bob@example.com",
|
|
});
|
|
});
|
|
});
|