Skip to content

Commit

Permalink
checkpoint gerber rendering with snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Aug 28, 2024
1 parent 572957b commit 513a8a7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
preload = ["./tests/fixtures/preload.ts"]
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
1 change: 1 addition & 0 deletions tests/fixtures/__snapshots__/simple1.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions tests/fixtures/preload.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>,
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<T = unknown> {
toMatchGerberSnapshot(
testPath: string,
svgName?: string,
): Promise<MatcherResult>
}
}
15 changes: 13 additions & 2 deletions tests/generate-board-outline-gerber.test.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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(
})

0 comments on commit 513a8a7

Please sign in to comment.