@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,95 +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 proxy validation", () => {
|
|
6
|
-
it("should NOT proxy fetch requests when enableFetchProxy is false (default)", async () => {
|
|
7
|
-
const worker = await createCircuitWebWorker({
|
|
8
|
-
webWorkerUrl: repoFileUrl("dist/webworker/entrypoint.js").href,
|
|
9
|
-
// enableFetchProxy not set, should default to false
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
const rawWorker: Worker = (worker as any).__rawWorker
|
|
13
|
-
const messages: any[] = []
|
|
14
|
-
rawWorker.addEventListener("message", (event) => {
|
|
15
|
-
if (event.data?.type === "worker_fetch") messages.push(event.data)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
await worker.execute(`
|
|
19
|
-
// Test that fetch calls are NOT proxied when enableFetchProxy is false
|
|
20
|
-
fetch("https://example.com/test")
|
|
21
|
-
.catch(() => {}); // Ignore errors, we just want to see if it's proxied
|
|
22
|
-
`)
|
|
23
|
-
|
|
24
|
-
await new Promise((r) => setTimeout(r, 100))
|
|
25
|
-
|
|
26
|
-
// Should NOT have received any worker_fetch messages
|
|
27
|
-
expect(messages.length).toBe(0)
|
|
28
|
-
|
|
29
|
-
await worker.kill()
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it("should proxy fetch requests when enableFetchProxy is true", async () => {
|
|
33
|
-
const worker = await createCircuitWebWorker({
|
|
34
|
-
webWorkerUrl: repoFileUrl("dist/webworker/entrypoint.js").href,
|
|
35
|
-
enableFetchProxy: true,
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
const rawWorker: Worker = (worker as any).__rawWorker
|
|
39
|
-
const messages: any[] = []
|
|
40
|
-
rawWorker.addEventListener("message", (event) => {
|
|
41
|
-
if (event.data?.type === "worker_fetch") messages.push(event.data)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
await worker.execute(`
|
|
45
|
-
// Test that fetch calls are proxied when enableFetchProxy is true
|
|
46
|
-
fetch("https://example.com/test")
|
|
47
|
-
.catch(() => {}); // Ignore errors, we just want to see if it's proxied
|
|
48
|
-
`)
|
|
49
|
-
|
|
50
|
-
await new Promise((r) => setTimeout(r, 100))
|
|
51
|
-
|
|
52
|
-
// Should have received a worker_fetch message indicating the proxy is working
|
|
53
|
-
expect(messages.length).toBeGreaterThan(0)
|
|
54
|
-
expect(messages[0].type).toBe("worker_fetch")
|
|
55
|
-
expect(messages[0].input).toBe("https://example.com/test")
|
|
56
|
-
|
|
57
|
-
await worker.kill()
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it("should handle fetch errors properly through proxy when enabled", async () => {
|
|
61
|
-
// This test verifies that the fetch proxy correctly handles and forwards errors
|
|
62
|
-
const originalFetch = globalThis.fetch
|
|
63
|
-
const fakeFetch = async () => {
|
|
64
|
-
throw new Error("Network error")
|
|
65
|
-
}
|
|
66
|
-
globalThis.fetch = fakeFetch as any
|
|
67
|
-
|
|
68
|
-
const worker = await createCircuitWebWorker({
|
|
69
|
-
webWorkerUrl: repoFileUrl("dist/webworker/entrypoint.js").href,
|
|
70
|
-
enableFetchProxy: true,
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
const rawWorker: Worker = (worker as any).__rawWorker
|
|
74
|
-
const messages: any[] = []
|
|
75
|
-
rawWorker.addEventListener("message", (event) => {
|
|
76
|
-
if (event.data?.type === "fetch_error") messages.push(event.data)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
await worker.execute(`
|
|
80
|
-
fetch("https://example.com/test")
|
|
81
|
-
.catch(e => {
|
|
82
|
-
postMessage({ type: "fetch_error", name: e.name, message: e.message });
|
|
83
|
-
});
|
|
84
|
-
`)
|
|
85
|
-
|
|
86
|
-
await new Promise((r) => setTimeout(r, 100))
|
|
87
|
-
|
|
88
|
-
expect(messages).toEqual([
|
|
89
|
-
{ type: "fetch_error", name: "Error", message: "Network error" },
|
|
90
|
-
])
|
|
91
|
-
|
|
92
|
-
await worker.kill()
|
|
93
|
-
globalThis.fetch = originalFetch
|
|
94
|
-
})
|
|
95
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "bun:test"
|
|
2
|
-
import { createCircuitWebWorker } from "lib"
|
|
3
|
-
|
|
4
|
-
describe("kill method", () => {
|
|
5
|
-
it("should immediately terminate the worker", async () => {
|
|
6
|
-
const worker = await createCircuitWebWorker({
|
|
7
|
-
webWorkerUrl: new URL(
|
|
8
|
-
"../../dist/webworker/entrypoint.js",
|
|
9
|
-
import.meta.url,
|
|
10
|
-
).href,
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
// Ensure worker is running
|
|
14
|
-
await worker.execute(`console.log("Worker running");`)
|
|
15
|
-
|
|
16
|
-
// Kill the worker
|
|
17
|
-
await worker.kill()
|
|
18
|
-
|
|
19
|
-
// Verify worker is terminated by attempting to execute code
|
|
20
|
-
await expect(
|
|
21
|
-
worker.execute(`console.log("Should not execute");`),
|
|
22
|
-
).rejects.toThrow() // Worker termination should cause execution to fail
|
|
23
|
-
})
|
|
24
|
-
})
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test"
|
|
2
|
-
import { createCircuitWebWorker } from "lib/index"
|
|
3
|
-
import type { PcbComponent, SourceComponentBase } from "circuit-json"
|
|
4
|
-
|
|
5
|
-
const example1 = {
|
|
6
|
-
entrypoint: "entrypoint.tsx",
|
|
7
|
-
fsMap: {
|
|
8
|
-
"entrypoint.tsx": `
|
|
9
|
-
const manualEdits = {
|
|
10
|
-
pcb_placements: [
|
|
11
|
-
{
|
|
12
|
-
selector: "R1",
|
|
13
|
-
center: {
|
|
14
|
-
x: 5,
|
|
15
|
-
y: 5
|
|
16
|
-
},
|
|
17
|
-
relative_to: "group_center",
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
edit_events: [],
|
|
21
|
-
manual_trace_hints: []
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
circuit.add(
|
|
25
|
-
<board width="20mm" height="20mm"
|
|
26
|
-
manualEdits={manualEdits}
|
|
27
|
-
>
|
|
28
|
-
<resistor name="R1" resistance="10k" footprint="0402" />
|
|
29
|
-
</board>)
|
|
30
|
-
`,
|
|
31
|
-
},
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const example2 = {
|
|
35
|
-
entrypoint: "entrypoint.tsx",
|
|
36
|
-
fsMap: {
|
|
37
|
-
"entrypoint.tsx": `
|
|
38
|
-
import manualEdits from "./manual-edits.json"
|
|
39
|
-
circuit.add(<board width="20mm" height="20mm" manualEdits={manualEdits}><resistor name="R1" resistance="10k" footprint="0402" /></board>)
|
|
40
|
-
`,
|
|
41
|
-
"manual-edits.json": `
|
|
42
|
-
{
|
|
43
|
-
"pcb_placements": [
|
|
44
|
-
{
|
|
45
|
-
"selector": "R1",
|
|
46
|
-
"center": {
|
|
47
|
-
"x": 5,
|
|
48
|
-
"y": 5
|
|
49
|
-
},
|
|
50
|
-
"relative_to": "group_center"
|
|
51
|
-
}
|
|
52
|
-
],
|
|
53
|
-
"edit_events": [],
|
|
54
|
-
"manual_trace_hints": []
|
|
55
|
-
}
|
|
56
|
-
`,
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
test("example1: Manual edits in entrypoint.tsx file", async () => {
|
|
61
|
-
const circuitWebWorker = await createCircuitWebWorker({
|
|
62
|
-
webWorkerUrl: new URL("../../webworker/index.ts", import.meta.url),
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
await circuitWebWorker.executeWithFsMap({
|
|
66
|
-
fsMap: example1.fsMap,
|
|
67
|
-
entrypoint: example1.entrypoint,
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
await circuitWebWorker.renderUntilSettled()
|
|
71
|
-
|
|
72
|
-
const circuitJson = await circuitWebWorker.getCircuitJson()
|
|
73
|
-
|
|
74
|
-
const R1 = circuitJson.find(
|
|
75
|
-
(el) => el.type === "source_component" && el.name === "R1",
|
|
76
|
-
) as SourceComponentBase
|
|
77
|
-
|
|
78
|
-
const pcb_component = circuitJson.find(
|
|
79
|
-
(el: any) =>
|
|
80
|
-
el.type === "pcb_component" &&
|
|
81
|
-
el.source_component_id === R1?.source_component_id,
|
|
82
|
-
) as PcbComponent
|
|
83
|
-
|
|
84
|
-
expect(pcb_component.center.x).toBe(5)
|
|
85
|
-
expect(pcb_component.center.y).toBe(5)
|
|
86
|
-
|
|
87
|
-
await circuitWebWorker.kill()
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test("example2: Manual edits in manual-edits.json file", async () => {
|
|
91
|
-
const circuitWebWorker = await createCircuitWebWorker({
|
|
92
|
-
webWorkerUrl: new URL("../../webworker/index.ts", import.meta.url),
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
await circuitWebWorker.executeWithFsMap({
|
|
96
|
-
fsMap: example2.fsMap,
|
|
97
|
-
entrypoint: example2.entrypoint,
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
await circuitWebWorker.renderUntilSettled()
|
|
101
|
-
|
|
102
|
-
const circuitJson = await circuitWebWorker.getCircuitJson()
|
|
103
|
-
|
|
104
|
-
const R1 = circuitJson.find(
|
|
105
|
-
(el) => el.type === "source_component" && el.name === "R1",
|
|
106
|
-
) as SourceComponentBase
|
|
107
|
-
|
|
108
|
-
const pcb_component = circuitJson.find(
|
|
109
|
-
(el: any) =>
|
|
110
|
-
el.type === "pcb_component" &&
|
|
111
|
-
el.source_component_id === R1?.source_component_id,
|
|
112
|
-
) as PcbComponent
|
|
113
|
-
|
|
114
|
-
expect(pcb_component.center.x).toBe(5)
|
|
115
|
-
expect(pcb_component.center.y).toBe(5)
|
|
116
|
-
|
|
117
|
-
await circuitWebWorker.kill()
|
|
118
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "bun:test"
|
|
2
|
-
import { runTscircuitCode } from "lib/runner"
|
|
3
|
-
|
|
4
|
-
test(
|
|
5
|
-
"should support importing various npm packages",
|
|
6
|
-
async () => {
|
|
7
|
-
const circuitJson = await runTscircuitCode(
|
|
8
|
-
`
|
|
9
|
-
import isOdd from "is-odd"
|
|
10
|
-
import _ from "lodash"
|
|
11
|
-
import { v4 as uuidv4 } from "uuid"
|
|
12
|
-
import dayjs from "dayjs"
|
|
13
|
-
|
|
14
|
-
export default () => {
|
|
15
|
-
// Test is-odd
|
|
16
|
-
if (!isOdd(3)) {
|
|
17
|
-
throw new Error("isOdd(3) should be true")
|
|
18
|
-
}
|
|
19
|
-
// Test lodash
|
|
20
|
-
if (!_.isEqual({ a: 1 }, { a: 1 })) {
|
|
21
|
-
throw new Error("_.isEqual failed")
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Test uuid
|
|
25
|
-
const uuid = uuidv4()
|
|
26
|
-
if (typeof uuid !== "string" || uuid.length < 36) {
|
|
27
|
-
throw new Error("uuid.v4 failed to generate a valid uuid")
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Test dayjs
|
|
31
|
-
if (!dayjs().isValid()) {
|
|
32
|
-
throw new Error("dayjs().isValid() failed")
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return <resistor name="R1" resistance="1k" />
|
|
36
|
-
}
|
|
37
|
-
`,
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
const resistor = circuitJson.find(
|
|
41
|
-
(element) => element.type === "source_component" && element.name === "R1",
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
expect(resistor).toBeDefined()
|
|
45
|
-
},
|
|
46
|
-
{ timeout: 15000 },
|
|
47
|
-
)
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { runTscircuitCode } from "lib/runner"
|
|
3
|
-
|
|
4
|
-
test("example13 parent directory relative imports", async () => {
|
|
5
|
-
const circuitJson = await runTscircuitCode(
|
|
6
|
-
{
|
|
7
|
-
"lib/resistor-name.ts": `export const resistorName = "R1"`,
|
|
8
|
-
"lib/subdir/resistance-value.ts": `export const resistanceValue = "1k"`,
|
|
9
|
-
"lib/subdir/resistor.tsx": `
|
|
10
|
-
import { resistanceValue } from "./resistance-value"
|
|
11
|
-
import { resistorName } from "../resistor-name"
|
|
12
|
-
export default () => (<resistor name={resistorName} resistance={resistanceValue} />)
|
|
13
|
-
`,
|
|
14
|
-
"user-code.tsx": `import Resistor from "./lib/subdir/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,23 +0,0 @@
|
|
|
1
|
-
import { CircuitRunner } from "lib/runner/CircuitRunner"
|
|
2
|
-
import { expect, test } from "bun:test"
|
|
3
|
-
|
|
4
|
-
test("platform configuration is forwarded to RootCircuit", async () => {
|
|
5
|
-
const runner = new CircuitRunner({ platform: { pcbDisabled: true } })
|
|
6
|
-
|
|
7
|
-
await runner.execute(`
|
|
8
|
-
circuit.add(
|
|
9
|
-
<board width="10mm" height="10mm">
|
|
10
|
-
<resistor name="R1" resistance="1k" footprint="0402" />
|
|
11
|
-
</board>
|
|
12
|
-
)
|
|
13
|
-
`)
|
|
14
|
-
|
|
15
|
-
await runner.renderUntilSettled()
|
|
16
|
-
const circuit = (globalThis as any).__tscircuit_circuit
|
|
17
|
-
expect(circuit.platform?.pcbDisabled).toBe(true)
|
|
18
|
-
|
|
19
|
-
const circuitJson = await runner.getCircuitJson()
|
|
20
|
-
expect(circuitJson.length).toBeGreaterThan(0)
|
|
21
|
-
|
|
22
|
-
await runner.kill()
|
|
23
|
-
})
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { runTscircuitCode } from "lib/runner"
|
|
2
|
-
import { expect, test } from "bun:test"
|
|
3
|
-
|
|
4
|
-
test("example12 subdirectory relative imports", async () => {
|
|
5
|
-
const circuitJson = await runTscircuitCode(
|
|
6
|
-
{
|
|
7
|
-
"lib/resistor.tsx": `
|
|
8
|
-
export default () => (<resistor name="R1" resistance="1k" />)
|
|
9
|
-
`,
|
|
10
|
-
"user-code.tsx": `
|
|
11
|
-
import Resistor from "./lib/resistor";
|
|
12
|
-
export default () => (<resistor name="R2" resistance="2k" />)
|
|
13
|
-
export {Resistor}
|
|
14
|
-
`,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
mainComponentPath: "user-code",
|
|
18
|
-
},
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
const resistor = circuitJson.find(
|
|
22
|
-
(element) => element.type === "source_component",
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
expect(resistor).toBeDefined()
|
|
26
|
-
expect(resistor?.name).toBe("R2")
|
|
27
|
-
})
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { CircuitRunner } from "lib/runner/CircuitRunner"
|
|
2
|
-
import { expect, test } from "bun:test"
|
|
3
|
-
|
|
4
|
-
test("projectConfig overrides default platform config", async () => {
|
|
5
|
-
const runner = new CircuitRunner({
|
|
6
|
-
projectConfig: {
|
|
7
|
-
projectBaseUrl: "https://example.com/assets",
|
|
8
|
-
},
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
await runner.execute(`
|
|
12
|
-
circuit.add(
|
|
13
|
-
<board width="10mm" height="10mm">
|
|
14
|
-
<resistor name="R1" resistance="1k" footprint="0402" />
|
|
15
|
-
</board>
|
|
16
|
-
)
|
|
17
|
-
`)
|
|
18
|
-
|
|
19
|
-
await runner.renderUntilSettled()
|
|
20
|
-
const circuit = (globalThis as any).__tscircuit_circuit
|
|
21
|
-
expect(circuit.platform?.projectBaseUrl).toBe("https://example.com/assets")
|
|
22
|
-
expect(typeof circuit.platform?.footprintLibraryMap?.kicad).toBe("function")
|
|
23
|
-
|
|
24
|
-
await runner.kill()
|
|
25
|
-
})
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test"
|
|
2
|
-
import { createCircuitWebWorker } from "lib"
|
|
3
|
-
import { repoFileUrl } from "tests/fixtures/resourcePaths"
|
|
4
|
-
|
|
5
|
-
test("should import .glb file as string URL when projectBaseUrl is configured", async () => {
|
|
6
|
-
const circuitWebWorker = createCircuitWebWorker({
|
|
7
|
-
webWorkerUrl: repoFileUrl("dist/webworker/entrypoint.js").href,
|
|
8
|
-
platform: {
|
|
9
|
-
projectBaseUrl: "https://example.com/assets",
|
|
10
|
-
},
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
const worker = await circuitWebWorker
|
|
14
|
-
|
|
15
|
-
await worker.executeWithFsMap({
|
|
16
|
-
fsMap: {
|
|
17
|
-
"index.tsx": `
|
|
18
|
-
import glbUrl from "./model.glb";
|
|
19
|
-
import kicadMod from "./footprint.kicad_mod";
|
|
20
|
-
|
|
21
|
-
export default () => {
|
|
22
|
-
return (
|
|
23
|
-
<board width="10mm" height="10mm">
|
|
24
|
-
<resistor resistance="1k" footprint="0402" name="R1" cadModel={{
|
|
25
|
-
glbUrl
|
|
26
|
-
}} />
|
|
27
|
-
</board>
|
|
28
|
-
);
|
|
29
|
-
};
|
|
30
|
-
`,
|
|
31
|
-
"model.glb": "__STATIC_ASSET__",
|
|
32
|
-
"footprint.kicad_mod": "__STATIC_ASSET__",
|
|
33
|
-
},
|
|
34
|
-
mainComponentPath: "index.tsx",
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
await worker.renderUntilSettled()
|
|
38
|
-
|
|
39
|
-
// Verify the circuit rendered successfully (imports worked)
|
|
40
|
-
const circuitJson = await worker.getCircuitJson()
|
|
41
|
-
expect(circuitJson).toBeDefined()
|
|
42
|
-
|
|
43
|
-
const cadComponent = circuitJson.find((e) => e.type === "cad_component")!
|
|
44
|
-
|
|
45
|
-
expect(cadComponent.model_glb_url).toBe(
|
|
46
|
-
"https://example.com/assets/model.glb",
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
await worker.kill()
|
|
50
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { afterEach } from "bun:test"
|
|
2
|
-
import "bun-match-svg"
|
|
3
|
-
|
|
4
|
-
// Clean up all workers after each test
|
|
5
|
-
afterEach(async () => {
|
|
6
|
-
if (globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER) {
|
|
7
|
-
await globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER.kill()
|
|
8
|
-
globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER = undefined
|
|
9
|
-
}
|
|
10
|
-
})
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { runTscircuitCode } from "lib/runner"
|
|
3
|
-
|
|
4
|
-
describe("node module resolution", () => {
|
|
5
|
-
test("resolves package.json", async () => {
|
|
6
|
-
const circuitJson = await runTscircuitCode(
|
|
7
|
-
{
|
|
8
|
-
"node_modules/test-package/package.json": JSON.stringify({
|
|
9
|
-
name: "test-package",
|
|
10
|
-
}),
|
|
11
|
-
"node_modules/test-package/index.js": `
|
|
12
|
-
export const resistorName = "R1"
|
|
13
|
-
export const resistanceValue = "1k"
|
|
14
|
-
`,
|
|
15
|
-
"user-code.tsx": `
|
|
16
|
-
import { resistorName, resistanceValue } from "test-package"
|
|
17
|
-
export default () => (<resistor name={resistorName} resistance={resistanceValue} />)
|
|
18
|
-
`,
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
mainComponentPath: "user-code",
|
|
22
|
-
},
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
const resistor = circuitJson.find(
|
|
26
|
-
(element) => element.type === "source_component" && element.name === "R1",
|
|
27
|
-
) as any
|
|
28
|
-
expect(resistor).toBeDefined()
|
|
29
|
-
expect(resistor.resistance).toBe(1000)
|
|
30
|
-
expect(resistor.name).toBe("R1")
|
|
31
|
-
})
|
|
32
|
-
})
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { runTscircuitCode } from "lib/runner"
|
|
3
|
-
|
|
4
|
-
describe("node module resolution", () => {
|
|
5
|
-
test("resolves TypeScript files with .ts extension", async () => {
|
|
6
|
-
const circuitJson = await runTscircuitCode(
|
|
7
|
-
{
|
|
8
|
-
"node_modules/test-package/index.ts": `
|
|
9
|
-
export const resistorName: string = "R10"
|
|
10
|
-
export const resistanceValue: string = "10k"
|
|
11
|
-
`,
|
|
12
|
-
"user-code.tsx": `
|
|
13
|
-
import { resistorName, resistanceValue } from "test-package"
|
|
14
|
-
export default () => (<resistor name={resistorName} resistance={resistanceValue} />)
|
|
15
|
-
`,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
mainComponentPath: "user-code",
|
|
19
|
-
},
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
const resistor = circuitJson.find(
|
|
23
|
-
(element) =>
|
|
24
|
-
element.type === "source_component" && element.name === "R10",
|
|
25
|
-
) as any
|
|
26
|
-
expect(resistor).toBeDefined()
|
|
27
|
-
expect(resistor.resistance).toBe(10000)
|
|
28
|
-
expect(resistor.name).toBe("R10")
|
|
29
|
-
})
|
|
30
|
-
})
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { runTscircuitCode } from "lib/runner"
|
|
3
|
-
|
|
4
|
-
describe("node module resolution", () => {
|
|
5
|
-
test("resolves subpath exports in package.json", async () => {
|
|
6
|
-
const circuitJson = await runTscircuitCode(
|
|
7
|
-
{
|
|
8
|
-
"node_modules/test-package/package.json": JSON.stringify({
|
|
9
|
-
name: "test-package",
|
|
10
|
-
exports: {
|
|
11
|
-
"./components": "./dist/components/index.js",
|
|
12
|
-
"./utils": "./dist/utils/index.js",
|
|
13
|
-
},
|
|
14
|
-
}),
|
|
15
|
-
"node_modules/test-package/dist/components/index.js": `
|
|
16
|
-
export const resistorName = "R11"
|
|
17
|
-
export const resistanceValue = "11k"
|
|
18
|
-
`,
|
|
19
|
-
"node_modules/test-package/components.js": `
|
|
20
|
-
export const resistorName = "wrong-name"
|
|
21
|
-
export const resistanceValue = "wrong-value"
|
|
22
|
-
`,
|
|
23
|
-
"user-code.tsx": `
|
|
24
|
-
import { resistorName, resistanceValue } from "test-package/components"
|
|
25
|
-
export default () => (<resistor name={resistorName} resistance={resistanceValue} />)
|
|
26
|
-
`,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
mainComponentPath: "user-code",
|
|
30
|
-
},
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
const resistor = circuitJson.find(
|
|
34
|
-
(element) =>
|
|
35
|
-
element.type === "source_component" && element.name === "R11",
|
|
36
|
-
) as any
|
|
37
|
-
expect(resistor).toBeDefined()
|
|
38
|
-
expect(resistor.resistance).toBe(11000)
|
|
39
|
-
expect(resistor.name).toBe("R11")
|
|
40
|
-
})
|
|
41
|
-
})
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { runTscircuitCode } from "lib/runner"
|
|
3
|
-
|
|
4
|
-
describe("node module resolution", () => {
|
|
5
|
-
test("resolves package.json main field", async () => {
|
|
6
|
-
const circuitJson = await runTscircuitCode(
|
|
7
|
-
{
|
|
8
|
-
"node_modules/test-package/package.json": JSON.stringify({
|
|
9
|
-
name: "test-package",
|
|
10
|
-
main: "dist/index.js",
|
|
11
|
-
}),
|
|
12
|
-
"node_modules/test-package/dist/index.js": `
|
|
13
|
-
export const resistorName = "Q1"
|
|
14
|
-
export const resistanceValue = "2k"
|
|
15
|
-
`,
|
|
16
|
-
"user-code.tsx": `
|
|
17
|
-
import { resistorName, resistanceValue } from "test-package"
|
|
18
|
-
export default () => (<resistor name={resistorName} resistance={resistanceValue} />)
|
|
19
|
-
`,
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
mainComponentPath: "user-code",
|
|
23
|
-
},
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
const resistor = circuitJson.find(
|
|
27
|
-
(element) => element.type === "source_component" && element.name === "Q1",
|
|
28
|
-
) as any
|
|
29
|
-
expect(resistor).toBeDefined()
|
|
30
|
-
expect(resistor.resistance).toBe(2000)
|
|
31
|
-
expect(resistor.name).toBe("Q1")
|
|
32
|
-
})
|
|
33
|
-
})
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { runTscircuitCode } from "lib/runner"
|
|
3
|
-
|
|
4
|
-
describe("node module resolution", () => {
|
|
5
|
-
test("resolves package.json module field over main", async () => {
|
|
6
|
-
const circuitJson = await runTscircuitCode(
|
|
7
|
-
{
|
|
8
|
-
"node_modules/test-package/package.json": JSON.stringify({
|
|
9
|
-
name: "test-package",
|
|
10
|
-
main: "dist/index.js",
|
|
11
|
-
module: "dist/index.esm.js",
|
|
12
|
-
}),
|
|
13
|
-
"node_modules/test-package/dist/index.js": `
|
|
14
|
-
exports.resistorName = "wrong-name"
|
|
15
|
-
exports.resistanceValue = "wrong-value"
|
|
16
|
-
`,
|
|
17
|
-
"node_modules/test-package/dist/index.esm.js": `
|
|
18
|
-
export const resistorName = "F2"
|
|
19
|
-
export const resistanceValue = "2k"
|
|
20
|
-
`,
|
|
21
|
-
"user-code.tsx": `
|
|
22
|
-
import { resistorName, resistanceValue } from "test-package"
|
|
23
|
-
export default () => (<resistor name={resistorName} resistance={resistanceValue} />)
|
|
24
|
-
`,
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
mainComponentPath: "user-code",
|
|
28
|
-
},
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
const resistor = circuitJson.find(
|
|
32
|
-
(element) => element.type === "source_component" && element.name === "F2",
|
|
33
|
-
) as any
|
|
34
|
-
expect(resistor).toBeDefined()
|
|
35
|
-
expect(resistor.resistance).toBe(2000)
|
|
36
|
-
expect(resistor.name).toBe("F2")
|
|
37
|
-
})
|
|
38
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { runTscircuitCode } from "lib/runner"
|
|
3
|
-
|
|
4
|
-
describe("node module resolution", () => {
|
|
5
|
-
test("resolves scoped package with index file", async () => {
|
|
6
|
-
const circuitJson = await runTscircuitCode(
|
|
7
|
-
{
|
|
8
|
-
"node_modules/@scope/package/index.js": `
|
|
9
|
-
export const resistorName = "R3"
|
|
10
|
-
export const resistanceValue = "3k"
|
|
11
|
-
`,
|
|
12
|
-
"user-code.tsx": `
|
|
13
|
-
import { resistorName, resistanceValue } from "@scope/package"
|
|
14
|
-
export default () => (<resistor name={resistorName} resistance={resistanceValue} />)
|
|
15
|
-
`,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
mainComponentPath: "user-code",
|
|
19
|
-
},
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
const resistor = circuitJson.find(
|
|
23
|
-
(element) => element.type === "source_component" && element.name === "R3",
|
|
24
|
-
) as any
|
|
25
|
-
expect(resistor).toBeDefined()
|
|
26
|
-
expect(resistor.resistance).toBe(3000)
|
|
27
|
-
expect(resistor.name).toBe("R3")
|
|
28
|
-
})
|
|
29
|
-
})
|