diff --git a/bun.lockb b/bun.lockb index 5d5fb02..c6a8fcd 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/bunfig.toml b/bunfig.toml new file mode 100644 index 0000000..25b636f --- /dev/null +++ b/bunfig.toml @@ -0,0 +1,2 @@ +[test] +preload = ["./tests/fixtures/preload.ts"] \ No newline at end of file diff --git a/package.json b/package.json index 73d12cd..afea9ee 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,14 @@ "devDependencies": { "@tscircuit/soup": "^0.0.58", "@types/bun": "latest", + "gerber-to-svg": "^4.2.8", "tsup": "^8.2.4" }, "peerDependencies": { "typescript": "^5.0.0" }, "dependencies": { + "bun-match-svg": "^0.0.1", "fast-json-stable-stringify": "^2.1.0" } } diff --git a/tests/fixtures/__snapshots__/simple1.snap.svg b/tests/fixtures/__snapshots__/simple1.snap.svg new file mode 100644 index 0000000..77bbd27 --- /dev/null +++ b/tests/fixtures/__snapshots__/simple1.snap.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/fixtures/preload.ts b/tests/fixtures/preload.ts new file mode 100644 index 0000000..a699a44 --- /dev/null +++ b/tests/fixtures/preload.ts @@ -0,0 +1,33 @@ +import "bun-match-svg" +import { expect } from "bun:test" +import gerberToSvg from "gerber-to-svg" + +async function toMatchGerberSnapshot( + this: any, + gerberOutput: Record, + testPathOriginal: string, + svgName?: string, +) { + const svg = await new Promise((resolve, reject) => { + gerberToSvg(gerberOutput.Edge_Cuts, {}, (err, svg) => { + if (err) return reject(err) + resolve(svg) + }) + }) + + return expect(svg).toMatchSvgSnapshot(import.meta.path, svgName) +} + +expect.extend({ + // biome-ignore lint/suspicious/noExplicitAny: + toMatchGerberSnapshot: toMatchGerberSnapshot as any, +}) + +declare module "bun:test" { + interface Matchers { + toMatchGerberSnapshot( + testPath: string, + svgName?: string, + ): Promise + } +} diff --git a/tests/generate-board-outline-gerber.test.ts b/tests/generate-board-outline-gerber.test.ts index 27ccae3..42b8007 100644 --- a/tests/generate-board-outline-gerber.test.ts +++ b/tests/generate-board-outline-gerber.test.ts @@ -1,10 +1,11 @@ -import { test } from "bun:test" +import { test, expect } from "bun:test" import { convertSoupToGerberCommands } from "src/convert-soup-to-gerber-commands" import { stringifyGerberCommandLayers, stringifyGerberCommands, } from "src/stringify-gerber" import { maybeOutputGerber } from "tests/fixtures/maybe-output-gerber" +import gerberToSvg from "gerber-to-svg" // If you're trying to test this, I would recommend opening up Kicad's Gerber // Viewer and loading in the files from the generated directory "gerber-output" @@ -27,5 +28,15 @@ test("Generate simple gerber with a single trace", async () => { // TODO parse gerber to check for correctness - await maybeOutputGerber(stringifyGerberCommandLayers(gerber_cmds)) + const gerberOutput = stringifyGerberCommandLayers(gerber_cmds) + + await maybeOutputGerber(gerberOutput) + + expect(gerberOutput).toMatchGerberSnapshot(import.meta.path, "simple1") + + // gerberToSvg(gerberOutput.Edge_Cuts, {}, (err, svg) => { + // expect(svg).toMatchSvgSnapshot(import.meta.path, "gerber-edge-cuts") + // }) + + // render( })