|
| 1 | +import { createCircuitWebWorker, runTscircuitCode } from "lib/index" |
| 2 | +import { expect, test } from "bun:test" |
| 3 | +import type { SourceComponentBase } from "circuit-json" |
| 4 | + |
| 5 | +test("example16-jlc-parts-engine with entrypoint", async () => { |
| 6 | + const circuitWebWorker = await createCircuitWebWorker({ |
| 7 | + webWorkerUrl: new URL("../webworker/entrypoint.ts", import.meta.url), |
| 8 | + verbose: true, |
| 9 | + }) |
| 10 | + |
| 11 | + await circuitWebWorker.executeWithFsMap({ |
| 12 | + entrypoint: "index.tsx", |
| 13 | + fsMap: { |
| 14 | + "index.tsx": ` |
| 15 | + circuit.add( |
| 16 | + <board> |
| 17 | + <resistor name="R1" resistance="1k" footprint="0402" /> |
| 18 | + </board> |
| 19 | + ) |
| 20 | + `, |
| 21 | + }, |
| 22 | + }) |
| 23 | + |
| 24 | + await circuitWebWorker.renderUntilSettled() |
| 25 | + |
| 26 | + const circuitJson = await circuitWebWorker.getCircuitJson() |
| 27 | + |
| 28 | + const source_component = circuitJson.filter( |
| 29 | + (el: any) => el.type === "source_component", |
| 30 | + ) as SourceComponentBase[] |
| 31 | + expect(source_component).toBeDefined() |
| 32 | + |
| 33 | + const supplier_part = source_component[0].supplier_part_numbers |
| 34 | + expect(supplier_part).toBeDefined() |
| 35 | +}) |
| 36 | + |
| 37 | +test("example16-jlc-parts-engine with mainComponentPath", async () => { |
| 38 | + const circuitJson = await runTscircuitCode( |
| 39 | + { |
| 40 | + "user-code.tsx": ` |
| 41 | + export default () => ( |
| 42 | + <board> |
| 43 | + <resistor name="R1" resistance="1k" footprint="0402" /> |
| 44 | + </board> |
| 45 | + ) |
| 46 | + `, |
| 47 | + }, |
| 48 | + { |
| 49 | + mainComponentPath: "user-code", |
| 50 | + }, |
| 51 | + ) |
| 52 | + |
| 53 | + const source_component = circuitJson.filter( |
| 54 | + (el: any) => el.type === "source_component", |
| 55 | + ) as SourceComponentBase[] |
| 56 | + expect(source_component).toBeDefined() |
| 57 | + |
| 58 | + const supplier_part = source_component[0].supplier_part_numbers |
| 59 | + expect(supplier_part).toBeDefined() |
| 60 | +}) |
0 commit comments