Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/fn/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export { dip } from "./dip"
export { pdip } from "./pdip"
export { spdip } from "./spdip"
export { diode } from "./diode"
export { cap } from "./cap"
export { led } from "./led"
Expand Down
13 changes: 13 additions & 0 deletions src/fn/pdip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { AnyCircuitElement } from "circuit-json"
import { dip, extendDipDef } from "./dip"

export const pdip_def = extendDipDef({
w: "300mil",
p: "2.54mm",
})

export const pdip = (
raw_params: Record<string, unknown>,
): { circuitJson: AnyCircuitElement[]; parameters: any } => {
return dip(raw_params as any)
}
14 changes: 14 additions & 0 deletions src/fn/spdip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { AnyCircuitElement } from "circuit-json"
import { dip, extendDipDef } from "./dip"

export const spdip_def = extendDipDef({
w: "300mil",
p: "1.778mm",
})

export const spdip = (
raw_params: Record<string, unknown>,
): { circuitJson: AnyCircuitElement[]; parameters: any } => {
const parameters = spdip_def.parse(raw_params)
return dip({ ...parameters, dip: true } as any)
}
6 changes: 6 additions & 0 deletions src/footprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export type Footprinter = {
dip: (
num_pins?: number,
) => FootprinterParamsBuilder<"w" | "p" | "id" | "od" | "wide" | "narrow">
pdip: (
num_pins?: number,
) => FootprinterParamsBuilder<"w" | "p" | "id" | "od" | "wide" | "narrow">
spdip: (
num_pins?: number,
) => FootprinterParamsBuilder<"w" | "p" | "id" | "od" | "wide" | "narrow">
cap: () => FootprinterParamsBuilder<CommonPassiveOptionKey>
res: () => FootprinterParamsBuilder<CommonPassiveOptionKey>
diode: () => FootprinterParamsBuilder<CommonPassiveOptionKey>
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/pdip8.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/__snapshots__/spdip28.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions tests/pdip.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { test, expect } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { fp } from "../src/footprinter"
import type { AnyCircuitElement } from "circuit-json"

test("pdip8 generates 8 plated holes", () => {
const circuitJson = fp.string("pdip8").circuitJson() as AnyCircuitElement[]
const platedHoles = circuitJson.filter((el) => el.type === "pcb_plated_hole")
expect(platedHoles.length).toBe(8)
})

test("pdip8 has standard DIP pitch (2.54mm)", () => {
const params = fp.string("pdip8").json()
expect(params.p).toBeCloseTo(2.54, 2)
})

test("PDIP8 case-insensitive", () => {
const uppercaseJson = fp.string("PDIP8").json()
const lowercaseJson = fp.string("pdip8").json()
expect(uppercaseJson).toEqual(lowercaseJson)
})

test("pdip8 svg snapshot", () => {
const circuitJson = fp.string("pdip8").circuitJson() as AnyCircuitElement[]
const svgContent = convertCircuitJsonToPcbSvg(circuitJson)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "pdip8")
})

test("spdip28 generates 28 plated holes", () => {
const circuitJson = fp.string("spdip28").circuitJson() as AnyCircuitElement[]
const platedHoles = circuitJson.filter((el) => el.type === "pcb_plated_hole")
expect(platedHoles.length).toBe(28)
})
Comment on lines +1 to +33
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file contains 6 test() functions (lines 6, 12, 18, 26, 32, and 38), which violates the rule that a *.test.ts file may have AT MOST one test(...). After the first test, the user should split into multiple numbered files. To fix this, split the tests into separate files like pdip1.test.ts, pdip2.test.ts, pdip3.test.ts, pdip4.test.ts, pdip5.test.ts, and pdip6.test.ts, with each file containing only one test() function.

Spotted by Graphite (based on custom rule: Custom rule)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.


test("spdip28 has shrink pitch (1.778mm)", () => {
const params = fp.string("spdip28").json()
expect(params.p).toBeCloseTo(1.778, 2)
})

test("spdip28 svg snapshot", () => {
const circuitJson = fp.string("spdip28").circuitJson() as AnyCircuitElement[]
const svgContent = convertCircuitJsonToPcbSvg(circuitJson)
expect(svgContent).toMatchSvgSnapshot(import.meta.path, "spdip28")
})
Loading