import { describe, expect, it } from "@suaveplan/testing/runner"; import { parseSdl, stripCommentsAndDescriptions } from "./parse-sdl.js"; describe("parseSdl", () => { it("recognises type and extend blocks", { timeout: 5000 }, () => { const blocks = parseSdl( "type Invoice { id: ID! } extend type Query { invoices: [Invoice!]! }" ); expect(blocks).toHaveLength(2); expect(blocks[0]?.kind).toBe("type"); expect(blocks[0]?.typeName).toBe("Invoice"); expect(blocks[1]?.kind).toBe("extend"); expect(blocks[1]?.typeName).toBe("Query"); }); it("extracts field names", { timeout: 5000 }, () => { const blocks = parseSdl(` type Invoice { id: ID! total: Int! lines(limit: Int): [Line!]! } `); expect(blocks[0]?.fields).toEqual(["id", "total", "lines"]); }); it("strips comments before parsing", { timeout: 5000 }, () => { const blocks = parseSdl(` # leading comment type Q { a: Int! # inline comment } `); expect(blocks[0]?.fields).toEqual(["a"]); }); it("strips block-string descriptions", { timeout: 5000 }, () => { const stripped = stripCommentsAndDescriptions( '"""description""" type X { a: Int! }' ); expect(stripped).not.toContain("description"); expect(stripped).toContain("type X"); }); it("ignores empty bodies gracefully", { timeout: 5000 }, () => { const blocks = parseSdl("type X { }"); expect(blocks[0]?.fields).toEqual([]); }); it("handles implements clause", { timeout: 5000 }, () => { const blocks = parseSdl( "type Invoice implements Node & Audited { id: ID! }" ); expect(blocks[0]?.typeName).toBe("Invoice"); expect(blocks[0]?.fields).toEqual(["id"]); }); it("returns empty list for non-type SDL", { timeout: 5000 }, () => { const blocks = parseSdl("scalar DateTime"); expect(blocks).toEqual([]); }); });