This repository has been archived by the owner on Jan 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Gerber Exporting, add tests for gerber export (#185)
* minor improvements to header menu * add test for exporting gerbers for keyboard and simple chip board * deeper testing * formatbot: Automatically format code * disable color output in tests --------- Co-authored-by: tscircuitbot <[email protected]>
- Loading branch information
1 parent
bd2f94a
commit cff12dc
Showing
14 changed files
with
153 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,5 @@ package-lock.json | |
**/package-lock.json | ||
|
||
.yalc | ||
yalc.lock | ||
yalc.lock | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[test] | ||
preload = ["./cli/tests/fixtures/preload.ts"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { test, expect, describe } from "bun:test" | ||
import { $ } from "bun" | ||
import { temporaryDirectory } from "tempy" | ||
import { join } from "path" | ||
import { existsSync } from "fs" | ||
|
||
test("tsci export gerbers --input example-project/examples/macrokeypad.tsx", async () => { | ||
const tempDir = temporaryDirectory() | ||
const { stdout, stderr } = | ||
await $`bun cli/cli.ts export gerbers --input example-project/examples/macrokeypad.tsx --outputfile ${join(tempDir, "gerbers.zip")} --no-color` | ||
|
||
expect(stderr.toString()).toBe("") | ||
expect(stdout.toString()).toContain("gerbers.zip") | ||
|
||
expect(existsSync(join(tempDir, "gerbers.zip"))).toBe(true) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { test, expect, describe } from "bun:test" | ||
import { $ } from "bun" | ||
import { temporaryDirectory } from "tempy" | ||
import { join } from "path" | ||
import { existsSync, readdirSync, readFileSync } from "fs" | ||
import extract from "extract-zip" | ||
import pcbStackup from "pcb-stackup" | ||
|
||
test("tsci export gerbers --input example-project/examples/basic-chip.tsx", async () => { | ||
const tempDir = temporaryDirectory() | ||
const gerberPath = join(tempDir, "gerbers.zip") | ||
const { stdout, stderr } = | ||
await $`bun cli/cli.ts export gerbers --input example-project/examples/basic-chip.tsx --outputfile ${gerberPath} --no-color` | ||
|
||
expect(stderr.toString()).toBe("") | ||
expect(stdout.toString()).toContain("gerbers.zip") | ||
|
||
expect(existsSync(join(tempDir, "gerbers.zip"))).toBe(true) | ||
|
||
await extract(gerberPath, { dir: join(tempDir, "gerbers") }) | ||
|
||
const files = readdirSync(join(tempDir, "gerbers")) | ||
const expectedFiles = [ | ||
"F_Mask.gbr", | ||
"F_SilkScreen.gbr", | ||
"B_Cu.gbr", | ||
"plated.drl", | ||
"B_SilkScreen.gbr", | ||
"F_Cu.gbr", | ||
"B_Paste.gbr", | ||
"F_Paste.gbr", | ||
"B_Mask.gbr", | ||
"Edge_Cuts.gbr", | ||
] | ||
|
||
expectedFiles.forEach((file) => { | ||
expect(files).toContain(file) | ||
}) | ||
|
||
const gerberOutputMap = Object.entries( | ||
files.map((filename) => [ | ||
filename, | ||
readFileSync(join(tempDir, "gerbers", filename)), | ||
]), | ||
) | ||
|
||
// Unfortunately doesn't work in bun yet due to some bug in node:stream | ||
// expect(gerberOutputMap).toMatchGerberSnapshot(import.meta.path) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import "bun-match-svg" | ||
import { expect } from "bun:test" | ||
import pcbStackup, { type Stackup } from "pcb-stackup" | ||
import { Readable } from "stream" | ||
|
||
async function toMatchGerberSnapshot( | ||
this: any, | ||
gerberOutput: Record<string, string>, | ||
testPathOriginal: string, | ||
svgName?: string, | ||
) { | ||
// Create layers array from gerberOutput | ||
const layers = Object.entries(gerberOutput).map(([filename, content]) => ({ | ||
filename, | ||
gerber: Readable.from(content), | ||
})) | ||
|
||
try { | ||
const stackup = await pcbStackup(layers) | ||
const svgArray: string[] = [] | ||
const svgNames: string[] = [] | ||
|
||
for (const item of Object.keys(stackup!) as Array<keyof Stackup>) { | ||
const layer = stackup[item] as { svg: string } | ||
if (layer.svg) { | ||
svgArray.push(layer.svg) | ||
svgNames.push(`${svgName}-${item}`) | ||
} | ||
} | ||
return expect(svgArray).toMatchMultipleSvgSnapshots( | ||
testPathOriginal, | ||
svgNames, | ||
) | ||
} catch (error) { | ||
throw new Error(`Failed to generate PCB stackup: ${error}`) | ||
} | ||
} | ||
|
||
expect.extend({ | ||
// biome-ignore lint/suspicious/noExplicitAny: | ||
toMatchGerberSnapshot: toMatchGerberSnapshot as any, | ||
}) | ||
|
||
declare module "bun:test" { | ||
interface Matchers<T = unknown> { | ||
/** | ||
* This doesn't currently work in bun, some bug in node:stream | ||
*/ | ||
toMatchGerberSnapshot( | ||
testImportMetaPath: string, | ||
svgName?: string, | ||
): Promise<MatcherResult> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters