@tscircuit/eval 0.0.333 → 0.0.334

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/eval",
3
3
  "main": "dist/lib/index.js",
4
- "version": "0.0.333",
4
+ "version": "0.0.334",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "bun run build:lib && bun run build:webworker && bun run build:blob-url && bun run build:runner && bun run build:worker-wrapper",
@@ -65,7 +65,7 @@
65
65
  "@tscircuit/matchpack": "^0.0.16",
66
66
  "@tscircuit/math-utils": "^0.0.21",
67
67
  "@tscircuit/miniflex": "^0.0.4",
68
- "@tscircuit/parts-engine": "^0.0.8",
68
+ "@tscircuit/parts-engine": "^0.0.11",
69
69
  "@tscircuit/props": "0.0.335",
70
70
  "@tscircuit/schematic-autolayout": "^0.0.6",
71
71
  "@tscircuit/schematic-match-adapt": "^0.0.16",
@@ -1,6 +1,11 @@
1
1
  import { createCircuitWebWorker, runTscircuitCode } from "lib/index"
2
- import { expect, test } from "bun:test"
2
+ import { expect, test, beforeEach } from "bun:test"
3
3
  import type { SourceComponentBase } from "circuit-json"
4
+ import { cache } from "@tscircuit/parts-engine"
5
+
6
+ beforeEach(() => {
7
+ cache.clear()
8
+ })
4
9
 
5
10
  test("example16-jlc-parts-engine with entrypoint", async () => {
6
11
  const circuitWebWorker = await createCircuitWebWorker({
@@ -66,3 +71,48 @@ test("example16-jlc-parts-engine with mainComponentPath", async () => {
66
71
  const supplier_part = source_component[0].supplier_part_numbers
67
72
  expect(supplier_part).toBeDefined()
68
73
  })
74
+
75
+ test("should prefer basic parts when available for resistors", async () => {
76
+ const originalFetch = globalThis.fetch
77
+ globalThis.fetch = (async (url: RequestInfo | URL, init?: RequestInit) => {
78
+ const urlString = url.toString()
79
+ if (urlString.includes("search") && urlString.includes("resistors")) {
80
+ return new Response(
81
+ JSON.stringify({
82
+ resistors: [
83
+ { lcsc: "1111" }, // is_basic is undefined, treated as false
84
+ { lcsc: "2222", is_basic: true },
85
+ { lcsc: "3333", is_basic: false },
86
+ { lcsc: "4444", is_basic: true },
87
+ { lcsc: "5555" },
88
+ ],
89
+ }),
90
+ {
91
+ headers: { "Content-Type": "application/json" },
92
+ },
93
+ )
94
+ }
95
+ return originalFetch(url, init)
96
+ }) as any
97
+
98
+ try {
99
+ const circuitJson = await runTscircuitCode(
100
+ `
101
+ export default () => (
102
+ <board>
103
+ <resistor name="R1" resistance="10k" footprint="0402" />
104
+ </board>
105
+ )
106
+ `,
107
+ )
108
+ const source_component = circuitJson.find(
109
+ (el: any) => el.type === "source_component" && el.name === "R1",
110
+ ) as SourceComponentBase
111
+ expect(source_component).toBeDefined()
112
+
113
+ const supplier_part = source_component.supplier_part_numbers
114
+ expect(supplier_part?.jlcpcb).toEqual(["C2222", "C4444", "C1111"])
115
+ } finally {
116
+ globalThis.fetch = originalFetch
117
+ }
118
+ })