Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions tests/features/kicad-jst-xh-connector-footprint.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { expect, test } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"

const KICAD_FOOTPRINT_CACHE_URL = "https://kicad-mod-cache.tscircuit.com"

test(
"kicad JST XH connector footprint loads correctly",
async () => {
const { circuit } = getTestFixture({
platform: {
footprintLibraryMap: {
kicad: async (footprintName: string) => {
const baseUrl = `${KICAD_FOOTPRINT_CACHE_URL}/${footprintName}`
const circuitJsonUrl = `${baseUrl}.circuit.json`
const res = await fetch(circuitJsonUrl)
if (!res.ok) {
throw new Error(
`Failed to load KiCad footprint "${footprintName}" (HTTP ${res.status})`,
)
}
const raw: any[] = await res.json()
const filtered = raw.filter((el) =>
el?.type === "pcb_silkscreen_text" ? el?.text === "REF**" : true,
)
return { footprintCircuitJson: filtered }
},
},
},
})

circuit.add(
<board routingDisabled>
<chip
name="U1"
footprint="kicad:Connector_JST/JST_XH_B3B-XH-AM_1x03_P2.50mm_Vertical"
/>
</board>,
)

await circuit.renderUntilSettled()

const circuitJson = circuit.getCircuitJson()

const errors = circuitJson.filter(
(el) => el.type.includes("error") || el.type.includes("warning"),
)

expect(errors).toHaveLength(0)

const holes = circuitJson.filter((el) => el.type === "pcb_plated_hole")
expect(holes).toHaveLength(3)

expect(convertCircuitJsonToPcbSvg(circuitJson as any)).toMatchSvgSnapshot(
import.meta.path,
)
},
30 * 1000,
)