@tscircuit/eval 0.0.362 → 0.0.364
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/dist/blob-url.js +1 -1
- package/dist/webworker/entrypoint.js +120 -120
- package/package.json +7 -4
- package/.github/workflows/bun-formatcheck.yml +0 -27
- package/.github/workflows/bun-pver-release.yml +0 -70
- package/.github/workflows/bun-test.yml +0 -87
- package/.github/workflows/bun-typecheck.yml +0 -27
- package/.github/workflows/playwright.yml +0 -40
- package/.github/workflows/update-deps.yml +0 -47
- package/.github/workflows/update-tscircuit-core.yml +0 -59
- package/biome.json +0 -50
- package/browser-tests/browser.test.ts +0 -15
- package/browser-tests/browsertest.html +0 -15
- package/browser-tests/browsertest.ts +0 -53
- package/bunfig.toml +0 -6
- package/lib/getPlatformConfig.ts +0 -41
- package/lib/getPossibleEntrypointComponentPaths.ts +0 -42
- package/lib/index.ts +0 -5
- package/lib/runner/CircuitRunner.ts +0 -201
- package/lib/runner/index.ts +0 -4
- package/lib/runner/normalizeFsMap.ts +0 -20
- package/lib/runner/resolveFilePath.ts +0 -90
- package/lib/runner/runTscircuitCode.ts +0 -30
- package/lib/runner/runTscircuitModule.ts +0 -37
- package/lib/runner/setupDefaultEntrypointIfNeeded.ts +0 -81
- package/lib/shared/static-asset-extensions.ts +0 -10
- package/lib/shared/types.ts +0 -79
- package/lib/utils/dirname.ts +0 -21
- package/lib/utils/get-imports-from-code.ts +0 -23
- package/lib/utils/index.ts +0 -1
- package/lib/utils/resolve-node-module.ts +0 -193
- package/lib/worker.ts +0 -246
- package/playwright.config.ts +0 -23
- package/scripts/build-worker-blob-url.ts +0 -27
- package/scripts/copy-core-versions.ts +0 -81
- package/scripts/validate-test-matrix.js +0 -148
- package/tests/circuit-runner/circuitrunner1-readme-example.test.tsx +0 -29
- package/tests/custom-component-with-fsmap/should-reject-invalid-main-component-path.test.ts +0 -26
- package/tests/custom-component-with-fsmap/should-render-multiple-components-from-fsmap.test.ts +0 -46
- package/tests/custom-component-with-fsmap/should-render-single-component-from-fsmap.test.ts +0 -38
- package/tests/examples/__snapshots__/example18-kicad-footprint-server.snap.svg +0 -1
- package/tests/examples/example01-readme-example.test.tsx +0 -30
- package/tests/examples/example02-multiple-files.test.tsx +0 -45
- package/tests/examples/example03-encoded-url.test.tsx +0 -28
- package/tests/examples/example04-root-child-issue.test.tsx +0 -37
- package/tests/examples/example05-event-recording.test.tsx +0 -44
- package/tests/examples/example06-dynamic-load-blob-url.test.tsx +0 -29
- package/tests/examples/example07-import-default-and-namespace.test.tsx +0 -74
- package/tests/examples/example08-footprinter-to220.test.tsx +0 -30
- package/tests/examples/example09-not-defined-component.test.tsx +0 -24
- package/tests/examples/example10-run-tscircuit-code.test.tsx +0 -14
- package/tests/examples/example11-flexible-import-extensions.test.tsx +0 -20
- package/tests/examples/example12-import-from-subdirectory.test.tsx +0 -26
- package/tests/examples/example13-webworker-without-entrypoint.test.tsx +0 -32
- package/tests/examples/example14-run-tscircuit-module.test.tsx +0 -20
- package/tests/examples/example15-run-tscircuit-module-with-props.test.tsx +0 -24
- package/tests/examples/example16-parts-engine.test.tsx +0 -118
- package/tests/examples/example17-parse-tscircuit-config.test.tsx +0 -49
- package/tests/examples/example18-kicad-footprint-server.test.tsx +0 -39
- package/tests/examples/example19-support-backwards-compat.test.tsx +0 -31
- package/tests/examples/example20-kicad-import.test.tsx +0 -48
- package/tests/features/circuit-event-forwarding.test.tsx +0 -45
- package/tests/features/enable-debug.test.ts +0 -26
- package/tests/features/execute-component-runner.test.tsx +0 -47
- package/tests/features/execute-component-worker.test.tsx +0 -25
- package/tests/features/fetch-proxy/fetch-override.test.ts +0 -46
- package/tests/features/fetch-proxy/fetch-proxy-validation.test.ts +0 -95
- package/tests/features/kill.test.ts +0 -24
- package/tests/features/manual-edits.test.tsx +0 -118
- package/tests/features/npm-import.test.tsx +0 -47
- package/tests/features/parent-directory-import.test.tsx +0 -26
- package/tests/features/platform-config.test.tsx +0 -23
- package/tests/features/prioritize-default-export.test.tsx +0 -27
- package/tests/features/project-config.test.tsx +0 -25
- package/tests/features/static-file-imports/static-file-import.test.ts +0 -50
- package/tests/fixtures/preload.ts +0 -10
- package/tests/fixtures/resourcePaths.ts +0 -3
- package/tests/node-resolution/node-module-resolution-1.test.tsx +0 -32
- package/tests/node-resolution/node-module-resolution-10.test.tsx +0 -30
- package/tests/node-resolution/node-module-resolution-11.test.tsx +0 -41
- package/tests/node-resolution/node-module-resolution-2.test.tsx +0 -33
- package/tests/node-resolution/node-module-resolution-3.test.tsx +0 -38
- package/tests/node-resolution/node-module-resolution-4.test.tsx +0 -29
- package/tests/node-resolution/node-module-resolution-5.test.tsx +0 -38
- package/tests/node-resolution/node-module-resolution-6.test.tsx +0 -40
- package/tests/node-resolution/node-module-resolution-7.test.tsx +0 -43
- package/tests/node-resolution/node-module-resolution-8.test.tsx +0 -32
- package/tests/node-resolution/node-module-resolution-9.test.tsx +0 -29
- package/tests/node-resolution/node-modules-resolution-12.test.tsx +0 -30
- package/tests/repros/group-wrapper.test.tsx +0 -18
- package/tests/repros/nine-keyboard-default-export.test.tsx +0 -26
- package/tests/util-fns/get-imports-from-code.test.tsx +0 -93
- package/tests/util-fns/getPossibleEntrypointComponentPaths.test.ts +0 -35
- package/tsconfig.json +0 -34
- package/tsup-lib.config.ts +0 -11
- package/tsup-runner.config.ts +0 -12
- package/tsup-webworker.config.ts +0 -21
- package/webworker/entrypoint.ts +0 -227
- package/webworker/eval-compiled-js.ts +0 -61
- package/webworker/execution-context.ts +0 -64
- package/webworker/fetchProxy.ts +0 -83
- package/webworker/import-eval-path.ts +0 -78
- package/webworker/import-local-file.ts +0 -93
- package/webworker/import-node-module.ts +0 -54
- package/webworker/import-npm-package.ts +0 -77
- package/webworker/import-snippet.ts +0 -30
- package/webworker/index.ts +0 -1
- package/webworker/transform-with-sucrase.ts +0 -68
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { runTscircuitCode } from "lib/runner"
|
|
3
|
-
|
|
4
|
-
test("example11 flexible imports", async () => {
|
|
5
|
-
const circuitJson = await runTscircuitCode(
|
|
6
|
-
{
|
|
7
|
-
"resistor.tsx": `export default () => (<resistor name="R1" resistance="1k" />)`,
|
|
8
|
-
"user-code.tsx": `import Resistor from "./resistor";\nexport default () => (<Resistor />)`,
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
mainComponentPath: "user-code",
|
|
12
|
-
},
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
const resistor = circuitJson.find(
|
|
16
|
-
(element) => element.type === "source_component" && element.name === "R1",
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
expect(resistor).toBeDefined()
|
|
20
|
-
})
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { runTscircuitCode } from "lib/runner"
|
|
3
|
-
|
|
4
|
-
test("example12 subdirectory relative imports", async () => {
|
|
5
|
-
const circuitJson = await runTscircuitCode(
|
|
6
|
-
{
|
|
7
|
-
"lib/resistor-name.ts": `export const resistorName = "R1"`,
|
|
8
|
-
"lib/resistance-value.ts": `export const resistanceValue = "1k"`,
|
|
9
|
-
"lib/resistor.tsx": `
|
|
10
|
-
import { resistanceValue } from "./resistance-value"
|
|
11
|
-
import { resistorName } from "lib/resistor-name"
|
|
12
|
-
export default () => (<resistor name={resistorName} resistance={resistanceValue} />)
|
|
13
|
-
`,
|
|
14
|
-
"user-code.tsx": `import Resistor from "./lib/resistor";\nexport default () => (<Resistor />)`,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
mainComponentPath: "user-code",
|
|
18
|
-
},
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
const resistor = circuitJson.find(
|
|
22
|
-
(element) => element.type === "source_component" && element.name === "R1",
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
expect(resistor).toBeDefined()
|
|
26
|
-
})
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { createCircuitWebWorker } from "lib/worker"
|
|
2
|
-
import { expect, test } from "bun:test"
|
|
3
|
-
import type { SourceSimpleResistor } from "circuit-json"
|
|
4
|
-
|
|
5
|
-
test("example13-webworker-without-entrypoint", async () => {
|
|
6
|
-
const circuitWebWorker = await createCircuitWebWorker({
|
|
7
|
-
webWorkerUrl: new URL("../../webworker/entrypoint.ts", import.meta.url),
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
await circuitWebWorker.executeWithFsMap({
|
|
12
|
-
fsMap: {
|
|
13
|
-
"index.tsx": `
|
|
14
|
-
export default () => (<resistor name="R1" resistance="1k" />)
|
|
15
|
-
`,
|
|
16
|
-
},
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
await circuitWebWorker.renderUntilSettled()
|
|
20
|
-
|
|
21
|
-
const circuitJson = await circuitWebWorker.getCircuitJson()
|
|
22
|
-
|
|
23
|
-
const resistor = circuitJson.find(
|
|
24
|
-
(el: any) => el.type === "source_component" && el.name === "R1",
|
|
25
|
-
) as SourceSimpleResistor
|
|
26
|
-
|
|
27
|
-
expect(resistor).toBeDefined()
|
|
28
|
-
expect(resistor?.resistance).toBe(1000)
|
|
29
|
-
} finally {
|
|
30
|
-
await circuitWebWorker.kill()
|
|
31
|
-
}
|
|
32
|
-
})
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { runTscircuitModule } from "lib/runner"
|
|
3
|
-
|
|
4
|
-
test(
|
|
5
|
-
"example14 runTscircuitModule",
|
|
6
|
-
async () => {
|
|
7
|
-
const circuitJson = await runTscircuitModule(
|
|
8
|
-
"@tsci/seveibar.usb-c-flashlight",
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
expect(circuitJson).toBeDefined()
|
|
12
|
-
|
|
13
|
-
const sourceComponent = circuitJson.find(
|
|
14
|
-
(element) => element.type === "source_component",
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
expect(sourceComponent).toBeDefined()
|
|
18
|
-
},
|
|
19
|
-
{ timeout: 15000 }, // Increased timeout for potential network request
|
|
20
|
-
)
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { runTscircuitModule } from "lib/runner"
|
|
3
|
-
|
|
4
|
-
test(
|
|
5
|
-
"example15 runTscircuitModule with props",
|
|
6
|
-
async () => {
|
|
7
|
-
const circuitJson = await runTscircuitModule("@tsci/seveibar.key", {
|
|
8
|
-
props: {
|
|
9
|
-
name: "MyKey",
|
|
10
|
-
},
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
expect(circuitJson).toBeDefined()
|
|
14
|
-
|
|
15
|
-
const sourceComponent = circuitJson.find(
|
|
16
|
-
(element) => element.type === "source_component",
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
expect(sourceComponent?.name).toBe("MyKey")
|
|
20
|
-
|
|
21
|
-
expect(sourceComponent).toBeDefined()
|
|
22
|
-
},
|
|
23
|
-
{ timeout: 15000 }, // Increased timeout for potential network request
|
|
24
|
-
)
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { createCircuitWebWorker, runTscircuitCode } from "lib/index"
|
|
2
|
-
import { expect, test, beforeEach } from "bun:test"
|
|
3
|
-
import type { SourceComponentBase } from "circuit-json"
|
|
4
|
-
import { cache } from "@tscircuit/parts-engine"
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
cache.clear()
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
test("example16-jlc-parts-engine with entrypoint", async () => {
|
|
11
|
-
const circuitWebWorker = await createCircuitWebWorker({
|
|
12
|
-
webWorkerUrl: new URL("../../webworker/entrypoint.ts", import.meta.url),
|
|
13
|
-
verbose: true,
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
await circuitWebWorker.executeWithFsMap({
|
|
17
|
-
entrypoint: "index.tsx",
|
|
18
|
-
fsMap: {
|
|
19
|
-
"index.tsx": `
|
|
20
|
-
circuit.add(
|
|
21
|
-
<board>
|
|
22
|
-
<resistor name="R1" resistance="1k" footprint="0402" />
|
|
23
|
-
<capacitor name="C1" capacitance="100uF" footprint="1206" />
|
|
24
|
-
</board>
|
|
25
|
-
)
|
|
26
|
-
`,
|
|
27
|
-
},
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
await circuitWebWorker.renderUntilSettled()
|
|
31
|
-
|
|
32
|
-
const circuitJson = await circuitWebWorker.getCircuitJson()
|
|
33
|
-
|
|
34
|
-
const source_component = circuitJson.filter(
|
|
35
|
-
(el: any) => el.type === "source_component",
|
|
36
|
-
) as SourceComponentBase[]
|
|
37
|
-
expect(source_component).toBeDefined()
|
|
38
|
-
|
|
39
|
-
const jlcpcb_parts_list = source_component.map(
|
|
40
|
-
(el) => el.supplier_part_numbers?.jlcpcb,
|
|
41
|
-
)
|
|
42
|
-
for (const el of jlcpcb_parts_list) {
|
|
43
|
-
expect(el).toBeDefined()
|
|
44
|
-
expect(el?.length).toBeGreaterThan(0)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
await circuitWebWorker.kill()
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test("example16-jlc-parts-engine with mainComponentPath", async () => {
|
|
51
|
-
const circuitJson = await runTscircuitCode(
|
|
52
|
-
{
|
|
53
|
-
"user-code.tsx": `
|
|
54
|
-
export default () => (
|
|
55
|
-
<board>
|
|
56
|
-
<resistor name="R1" resistance="1k" footprint="0402" />
|
|
57
|
-
</board>
|
|
58
|
-
)
|
|
59
|
-
`,
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
mainComponentPath: "user-code",
|
|
63
|
-
},
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
const source_component = circuitJson.filter(
|
|
67
|
-
(el: any) => el.type === "source_component",
|
|
68
|
-
) as SourceComponentBase[]
|
|
69
|
-
expect(source_component).toBeDefined()
|
|
70
|
-
|
|
71
|
-
const supplier_part = source_component[0].supplier_part_numbers
|
|
72
|
-
expect(supplier_part).toBeDefined()
|
|
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
|
-
})
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { createCircuitWebWorker } from "lib"
|
|
2
|
-
import { expect, test } from "bun:test"
|
|
3
|
-
|
|
4
|
-
test("parse tscircuit.config.js with mainEntrypoint", async () => {
|
|
5
|
-
const circuitWebWorker = await createCircuitWebWorker({
|
|
6
|
-
webWorkerUrl: new URL("../../webworker/entrypoint.ts", import.meta.url),
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
await circuitWebWorker.executeWithFsMap({
|
|
10
|
-
fsMap: {
|
|
11
|
-
"tscircuit.config.json": `
|
|
12
|
-
{
|
|
13
|
-
"mainEntrypoint": "random1.tsx"
|
|
14
|
-
}
|
|
15
|
-
`,
|
|
16
|
-
"random1.tsx": `
|
|
17
|
-
import { MyLed } from "./random2.tsx"
|
|
18
|
-
import someJson from "./random3.json"
|
|
19
|
-
|
|
20
|
-
circuit.add(
|
|
21
|
-
<board width="10mm" height="10mm">
|
|
22
|
-
<MyLed name="LED1" />
|
|
23
|
-
</board>
|
|
24
|
-
)
|
|
25
|
-
`,
|
|
26
|
-
"random2.tsx": `
|
|
27
|
-
import { RedLed } from "@tsci/seveibar.red-led"
|
|
28
|
-
|
|
29
|
-
export const MyLed = ({ name }) => {
|
|
30
|
-
return <RedLed name={name} />
|
|
31
|
-
}
|
|
32
|
-
`,
|
|
33
|
-
"random3.json": `
|
|
34
|
-
{
|
|
35
|
-
"some": "value"
|
|
36
|
-
}
|
|
37
|
-
`,
|
|
38
|
-
},
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
await circuitWebWorker.renderUntilSettled()
|
|
42
|
-
|
|
43
|
-
const circuitJson = await circuitWebWorker.getCircuitJson()
|
|
44
|
-
|
|
45
|
-
const led = circuitJson.find((el: any) => el.name === "LED1")
|
|
46
|
-
expect(led?.type).toBe("source_component")
|
|
47
|
-
|
|
48
|
-
await circuitWebWorker.kill()
|
|
49
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createCircuitWebWorker } from "lib/index"
|
|
2
|
-
import { expect, test } from "bun:test"
|
|
3
|
-
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
|
|
4
|
-
|
|
5
|
-
test("example18-kicad-footprint-server", 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="kicad:Resistor_SMD.pretty/R_0402_1005Metric" pcbX={-2} />
|
|
18
|
-
<capacitor name="C1" capacitance="100uF" footprint="0402" pcbX={2} />
|
|
19
|
-
<trace from=".R1 > .pin2" to=".C1 > .pin1" />
|
|
20
|
-
</board>
|
|
21
|
-
)
|
|
22
|
-
`,
|
|
23
|
-
},
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
await circuitWebWorker.renderUntilSettled()
|
|
27
|
-
|
|
28
|
-
const circuitJson = await circuitWebWorker.getCircuitJson()
|
|
29
|
-
|
|
30
|
-
const pcb_trace = circuitJson.filter((el: any) => el.type === "pcb_trace")
|
|
31
|
-
expect(pcb_trace).toBeDefined()
|
|
32
|
-
expect(pcb_trace.length).toBe(1)
|
|
33
|
-
|
|
34
|
-
expect(convertCircuitJsonToPcbSvg(circuitJson)).toMatchSvgSnapshot(
|
|
35
|
-
import.meta.path,
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
await circuitWebWorker.kill()
|
|
39
|
-
})
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createCircuitWebWorker } from "lib"
|
|
2
|
-
import { expect, test } from "bun:test"
|
|
3
|
-
|
|
4
|
-
test("support backwards compat for the `.ts` extension files", async () => {
|
|
5
|
-
const circuitWebWorker = await createCircuitWebWorker({
|
|
6
|
-
webWorkerUrl: new URL("../../webworker/entrypoint.ts", import.meta.url),
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
await circuitWebWorker.executeWithFsMap({
|
|
10
|
-
fsMap: {
|
|
11
|
-
"index.ts": `
|
|
12
|
-
circuit.add(
|
|
13
|
-
<board width="10mm" height="10mm">
|
|
14
|
-
<resistor name="R1" resistance="1k" />
|
|
15
|
-
</board>
|
|
16
|
-
)
|
|
17
|
-
`,
|
|
18
|
-
},
|
|
19
|
-
entrypoint: "index.ts",
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
await circuitWebWorker.renderUntilSettled()
|
|
23
|
-
|
|
24
|
-
const circuitJson = await circuitWebWorker.getCircuitJson()
|
|
25
|
-
|
|
26
|
-
const component = circuitJson.find((el: any) => el.name === "R1")
|
|
27
|
-
expect(component).toBeDefined()
|
|
28
|
-
expect(component?.type).toBe("source_component")
|
|
29
|
-
|
|
30
|
-
await circuitWebWorker.kill()
|
|
31
|
-
})
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { CircuitRunner, getPlatformConfig } from "lib/index"
|
|
2
|
-
import { test } from "bun:test"
|
|
3
|
-
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
|
|
4
|
-
import { expect } from "bun:test"
|
|
5
|
-
|
|
6
|
-
test(
|
|
7
|
-
"example20-kicad-direct-import",
|
|
8
|
-
async () => {
|
|
9
|
-
const runner = new CircuitRunner({
|
|
10
|
-
platform: {
|
|
11
|
-
...getPlatformConfig(),
|
|
12
|
-
footprintFileParserMap: {
|
|
13
|
-
kicad_mod: {
|
|
14
|
-
loadFromUrl: async (url: string) => {
|
|
15
|
-
expect(url).toEqual("/poly.kicad_mod")
|
|
16
|
-
return {
|
|
17
|
-
footprintCircuitJson: [],
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
await runner.executeWithFsMap({
|
|
26
|
-
entrypoint: "index.tsx",
|
|
27
|
-
fsMap: {
|
|
28
|
-
"index.tsx": `
|
|
29
|
-
import kicadMod from "./poly.kicad_mod"
|
|
30
|
-
|
|
31
|
-
circuit.add(
|
|
32
|
-
<board width="10mm" height="10mm">
|
|
33
|
-
<chip
|
|
34
|
-
name="U1"
|
|
35
|
-
footprint={kicadMod}
|
|
36
|
-
/>
|
|
37
|
-
</board>
|
|
38
|
-
)
|
|
39
|
-
`,
|
|
40
|
-
"poly.kicad_mod": "__STATIC_ASSET__",
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
await runner.renderUntilSettled()
|
|
45
|
-
await runner.kill()
|
|
46
|
-
},
|
|
47
|
-
20 * 1000,
|
|
48
|
-
)
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { createCircuitWebWorker } from "lib"
|
|
2
|
-
import { expect, test } from "bun:test"
|
|
3
|
-
|
|
4
|
-
test("circuit-web-worker-events", async () => {
|
|
5
|
-
// Track events for verification
|
|
6
|
-
const capturedEvents: string[] = []
|
|
7
|
-
|
|
8
|
-
const circuitWebWorker = await createCircuitWebWorker({
|
|
9
|
-
webWorkerUrl: new URL("../../webworker/entrypoint.ts", import.meta.url),
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
await circuitWebWorker.execute(`
|
|
13
|
-
import { RedLed } from "@tsci/seveibar.red-led"
|
|
14
|
-
circuit.add(
|
|
15
|
-
<board width="10mm" height="10mm">
|
|
16
|
-
<RedLed name="LED1" x="5mm" y="5mm" />
|
|
17
|
-
</board>
|
|
18
|
-
)
|
|
19
|
-
`)
|
|
20
|
-
|
|
21
|
-
// Listen to events
|
|
22
|
-
circuitWebWorker.on(
|
|
23
|
-
"renderable:renderLifecycle:PcbComponentRender:start",
|
|
24
|
-
(eventData) => {
|
|
25
|
-
capturedEvents.push("pcbComponentRenderStart")
|
|
26
|
-
},
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
circuitWebWorker.on(
|
|
30
|
-
"renderable:renderLifecycle:PcbComponentRender:end",
|
|
31
|
-
(eventData) => {
|
|
32
|
-
capturedEvents.push("pcbComponentRenderEnd")
|
|
33
|
-
},
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
// Render until settled to trigger events
|
|
37
|
-
await circuitWebWorker.renderUntilSettled()
|
|
38
|
-
|
|
39
|
-
// Verify that some expected events were captured
|
|
40
|
-
expect(capturedEvents.length).toBeGreaterThan(0)
|
|
41
|
-
expect(capturedEvents).toContain("pcbComponentRenderStart")
|
|
42
|
-
expect(capturedEvents).toContain("pcbComponentRenderEnd")
|
|
43
|
-
|
|
44
|
-
await circuitWebWorker.kill()
|
|
45
|
-
})
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test"
|
|
2
|
-
import { CircuitRunner } from "lib/runner/CircuitRunner"
|
|
3
|
-
import { createCircuitWebWorker } from "lib"
|
|
4
|
-
import { repoFileUrl } from "tests/fixtures/resourcePaths"
|
|
5
|
-
|
|
6
|
-
test("CircuitWebWorker emits debug log", async () => {
|
|
7
|
-
const worker = await createCircuitWebWorker({
|
|
8
|
-
webWorkerUrl: repoFileUrl("dist/webworker/entrypoint.js").href,
|
|
9
|
-
})
|
|
10
|
-
const logs: any[] = []
|
|
11
|
-
worker.on("debug:logOutput", (output) => {
|
|
12
|
-
logs.push(output)
|
|
13
|
-
})
|
|
14
|
-
await worker.enableDebug("Group_doInitialSchematicTraceRender")
|
|
15
|
-
await worker.execute(`
|
|
16
|
-
circuit.add(<board>
|
|
17
|
-
<resistor name="R1" resistance="1k" footprint="0402" schX={-2} />
|
|
18
|
-
<resistor name="R2" resistance="1k" footprint="0402" connections={{ pin1: "R1.pin1" }} schX={2} />
|
|
19
|
-
</board>)
|
|
20
|
-
`)
|
|
21
|
-
|
|
22
|
-
await worker.renderUntilSettled()
|
|
23
|
-
|
|
24
|
-
expect(logs).toHaveLength(1)
|
|
25
|
-
await worker.kill()
|
|
26
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test"
|
|
2
|
-
import * as React from "react"
|
|
3
|
-
import { CircuitRunner } from "lib/runner/CircuitRunner"
|
|
4
|
-
|
|
5
|
-
test("CircuitRunner.executeComponent with React element", async () => {
|
|
6
|
-
const runner = new CircuitRunner()
|
|
7
|
-
const element = React.createElement(
|
|
8
|
-
"board",
|
|
9
|
-
{ width: "10mm", height: "10mm" },
|
|
10
|
-
React.createElement("resistor", {
|
|
11
|
-
name: "R1",
|
|
12
|
-
resistance: "1k",
|
|
13
|
-
footprint: "0402",
|
|
14
|
-
}),
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
await runner.executeComponent(element)
|
|
18
|
-
await runner.renderUntilSettled()
|
|
19
|
-
const circuitJson = await runner.getCircuitJson()
|
|
20
|
-
const r1 = circuitJson.find(
|
|
21
|
-
(el: any) => el.type === "source_component" && el.name === "R1",
|
|
22
|
-
)
|
|
23
|
-
expect(r1).toBeDefined()
|
|
24
|
-
await runner.kill()
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
test("CircuitRunner.executeComponent with factory function", async () => {
|
|
28
|
-
const runner = new CircuitRunner()
|
|
29
|
-
await runner.executeComponent(() =>
|
|
30
|
-
React.createElement(
|
|
31
|
-
"board",
|
|
32
|
-
{ width: "10mm", height: "10mm" },
|
|
33
|
-
React.createElement("resistor", {
|
|
34
|
-
name: "R2",
|
|
35
|
-
resistance: "2k",
|
|
36
|
-
footprint: "0402",
|
|
37
|
-
}),
|
|
38
|
-
),
|
|
39
|
-
)
|
|
40
|
-
await runner.renderUntilSettled()
|
|
41
|
-
const circuitJson = await runner.getCircuitJson()
|
|
42
|
-
const r2 = circuitJson.find(
|
|
43
|
-
(el: any) => el.type === "source_component" && el.name === "R2",
|
|
44
|
-
)
|
|
45
|
-
expect(r2).toBeDefined()
|
|
46
|
-
await runner.kill()
|
|
47
|
-
})
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test"
|
|
2
|
-
import * as React from "react"
|
|
3
|
-
import { createCircuitWebWorker } from "lib"
|
|
4
|
-
import { repoFileUrl } from "tests/fixtures/resourcePaths"
|
|
5
|
-
|
|
6
|
-
test("CircuitWebWorker.executeComponent with factory function", async () => {
|
|
7
|
-
const worker = await createCircuitWebWorker({
|
|
8
|
-
webWorkerUrl: repoFileUrl("dist/webworker/entrypoint.js").href,
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
await worker.executeComponent(
|
|
12
|
-
<board>
|
|
13
|
-
<resistor name="R1" resistance="1k" />
|
|
14
|
-
</board>,
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
await worker.renderUntilSettled()
|
|
18
|
-
const circuitJson = await worker.getCircuitJson()
|
|
19
|
-
const R1 = circuitJson.find(
|
|
20
|
-
(el: any) => el.type === "source_component" && el.name === "R1",
|
|
21
|
-
)
|
|
22
|
-
expect(R1).toBeDefined()
|
|
23
|
-
|
|
24
|
-
await worker.kill()
|
|
25
|
-
})
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "bun:test"
|
|
2
|
-
import { createCircuitWebWorker } from "lib"
|
|
3
|
-
import { repoFileUrl } from "tests/fixtures/resourcePaths"
|
|
4
|
-
|
|
5
|
-
describe("fetch override", () => {
|
|
6
|
-
it("allows worker to fetch via parent and propagates errors", async () => {
|
|
7
|
-
const originalFetch = globalThis.fetch
|
|
8
|
-
const fakeFetch = async (input: RequestInfo, init?: RequestInit) => {
|
|
9
|
-
if (typeof input === "string" && input.includes("cjs.tscircuit.com")) {
|
|
10
|
-
return new Response("module.exports = { default: 123 };", {
|
|
11
|
-
status: 200,
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
throw new Error("fake fail")
|
|
15
|
-
}
|
|
16
|
-
globalThis.fetch = fakeFetch as any
|
|
17
|
-
|
|
18
|
-
const worker = await createCircuitWebWorker({
|
|
19
|
-
webWorkerUrl: repoFileUrl("dist/webworker/entrypoint.js").href,
|
|
20
|
-
enableFetchProxy: true,
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const rawWorker: Worker = (worker as any).__rawWorker
|
|
24
|
-
const messages: any[] = []
|
|
25
|
-
rawWorker.addEventListener("message", (event) => {
|
|
26
|
-
if (event.data?.type === "fetch_error") messages.push(event.data)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
await worker.execute(`
|
|
30
|
-
import val from "@tsci/test.snippet";
|
|
31
|
-
if (val !== 123) { throw new Error("snippet failed"); }
|
|
32
|
-
fetch("https://fail.test").catch(e => {
|
|
33
|
-
postMessage({ type: "fetch_error", name: e.name, message: e.message });
|
|
34
|
-
});
|
|
35
|
-
`)
|
|
36
|
-
|
|
37
|
-
await new Promise((r) => setTimeout(r, 10))
|
|
38
|
-
|
|
39
|
-
expect(messages).toEqual([
|
|
40
|
-
{ type: "fetch_error", name: "Error", message: "fake fail" },
|
|
41
|
-
])
|
|
42
|
-
|
|
43
|
-
await worker.kill()
|
|
44
|
-
globalThis.fetch = originalFetch
|
|
45
|
-
})
|
|
46
|
-
})
|