Skip to content

Commit b5af692

Browse files
committed
Split SamacSys WRL regression tests
1 parent fe2952e commit b5af692

2 files changed

Lines changed: 175 additions & 112 deletions

File tree

tests/test_service_worker_samacsys.test.js

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ import {
2020
sendRuntimeMessage
2121
} from "./helpers/service_worker_harness.js";
2222

23-
function decodeDataUrl(dataUrl) {
24-
return Buffer.from(String(dataUrl).split(",")[1] || "", "base64").toString(
25-
"utf8"
26-
);
27-
}
28-
2923
describe("service worker SamacSys direct flow", () => {
3024
it("returns Mouser PNG preview URLs by resolving the SamacSys part page", async () => {
3125
const { chrome, listeners } = createServiceWorkerChrome();
@@ -218,112 +212,6 @@ describe("service worker SamacSys direct flow", () => {
218212
);
219213
});
220214

221-
it("keeps Mouser library footprint model references when only a WRL model is present", async () => {
222-
const { chrome, listeners } = createServiceWorkerChrome({
223-
storageState: {
224-
downloadIndividually: false,
225-
libraryDownloadRoot: "KiCad/Workspace"
226-
}
227-
});
228-
const readZipEntries = vi.fn(async () => [
229-
{
230-
name: "STM32C552KEU6/KiCad/QFN50P500X500X60-33N-D.kicad_mod",
231-
data: new TextEncoder().encode(MOUSER_FOOTPRINT)
232-
},
233-
{
234-
name: "STM32C552KEU6/3D/STM32C552KEU6.wrl",
235-
data: new TextEncoder().encode("#VRML V2.0")
236-
}
237-
]);
238-
const fetchImpl = createSamacsysFetchImpl({
239-
zipStatus: 200
240-
});
241-
242-
loadServiceWorker({
243-
chrome,
244-
fetchImpl,
245-
readZipEntries,
246-
urlApi: {}
247-
});
248-
249-
const result = await sendRuntimeMessage(listeners.runtimeMessage[0], {
250-
type: "EXPORT_PART",
251-
partContext: createSamacsysPartContext("mouser"),
252-
options: {
253-
symbol: false,
254-
footprint: true,
255-
model3d: true,
256-
datasheet: false
257-
}
258-
});
259-
260-
expect(result.response).toEqual({
261-
ok: true,
262-
warnings: [],
263-
downloadCount: 2
264-
});
265-
266-
const downloadCalls = chrome.downloads.download.mock.calls.map(([options]) => options);
267-
const footprintCall = downloadCalls.find((options) =>
268-
options.filename.endsWith("Workspace.pretty/QFN50P500X500X60-33N-D.kicad_mod")
269-
);
270-
const footprintContent = decodeDataUrl(footprintCall.url);
271-
expect(footprintContent).toContain(
272-
"../Workspace.3dshapes/STM32C552KEU6.wrl"
273-
);
274-
expect(footprintContent).not.toContain("STM32C552KEU6.stp");
275-
276-
const filenames = downloadCalls.map((options) => options.filename);
277-
expect(filenames).toContain(
278-
"KiCad/Workspace/Workspace.3dshapes/STM32C552KEU6.wrl"
279-
);
280-
});
281-
282-
it("exports Mouser WRL-only model archives when only 3D output is selected", async () => {
283-
const { chrome, listeners } = createServiceWorkerChrome({
284-
storageState: {
285-
downloadIndividually: true
286-
}
287-
});
288-
const readZipEntries = vi.fn(async () => [
289-
{
290-
name: "STM32C552KEU6/3D/STM32C552KEU6.wrl",
291-
data: new TextEncoder().encode("#VRML V2.0")
292-
}
293-
]);
294-
const fetchImpl = createSamacsysFetchImpl({
295-
zipStatus: 200
296-
});
297-
298-
loadServiceWorker({
299-
chrome,
300-
fetchImpl,
301-
readZipEntries
302-
});
303-
304-
const result = await sendRuntimeMessage(listeners.runtimeMessage[0], {
305-
type: "EXPORT_PART",
306-
partContext: createSamacsysPartContext("mouser"),
307-
options: {
308-
symbol: false,
309-
footprint: false,
310-
model3d: true,
311-
datasheet: false
312-
}
313-
});
314-
315-
expect(result.response).toEqual({
316-
ok: true,
317-
warnings: [],
318-
downloadCount: 1
319-
});
320-
321-
const filenames = chrome.downloads.download.mock.calls.map(
322-
([options]) => options.filename
323-
);
324-
expect(filenames).toEqual(["STM32C552KEU6.wrl"]);
325-
});
326-
327215
it("does not leave Mouser footprint model references behind when 3D export is disabled", async () => {
328216
const { chrome, listeners } = createServiceWorkerChrome({
329217
storageState: {
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
* These tests cover SamacSys WRL-only export edge cases. They live separately
3+
* from the main direct-flow suite so targeted regressions do not push the
4+
* broader SamacSys test file past the repository line-count limit.
5+
*/
6+
7+
import { describe, expect, it, vi } from "vitest";
8+
9+
import {
10+
createSamacsysFetchImpl,
11+
createSamacsysPartContext,
12+
createServiceWorkerChrome,
13+
loadServiceWorker,
14+
MOUSER_FOOTPRINT,
15+
sendRuntimeMessage
16+
} from "./helpers/service_worker_harness.js";
17+
18+
function decodeDataUrl(dataUrl) {
19+
return Buffer.from(String(dataUrl).split(",")[1] || "", "base64").toString(
20+
"utf8"
21+
);
22+
}
23+
24+
describe("service worker SamacSys WRL exports", () => {
25+
it("keeps Mouser library footprint model references when only a WRL model is present", async () => {
26+
const { chrome, listeners } = createServiceWorkerChrome({
27+
storageState: {
28+
downloadIndividually: false,
29+
libraryDownloadRoot: "KiCad/Workspace"
30+
}
31+
});
32+
const readZipEntries = vi.fn(async () => [
33+
{
34+
name: "STM32C552KEU6/KiCad/QFN50P500X500X60-33N-D.kicad_mod",
35+
data: new TextEncoder().encode(MOUSER_FOOTPRINT)
36+
},
37+
{
38+
name: "STM32C552KEU6/3D/STM32C552KEU6.wrl",
39+
data: new TextEncoder().encode("#VRML V2.0")
40+
}
41+
]);
42+
const fetchImpl = createSamacsysFetchImpl({
43+
zipStatus: 200
44+
});
45+
46+
loadServiceWorker({
47+
chrome,
48+
fetchImpl,
49+
readZipEntries,
50+
urlApi: {}
51+
});
52+
53+
const result = await sendRuntimeMessage(listeners.runtimeMessage[0], {
54+
type: "EXPORT_PART",
55+
partContext: createSamacsysPartContext("mouser"),
56+
options: {
57+
symbol: false,
58+
footprint: true,
59+
model3d: true,
60+
datasheet: false
61+
}
62+
});
63+
64+
expect(result.response).toEqual({
65+
ok: true,
66+
warnings: [],
67+
downloadCount: 2
68+
});
69+
70+
const downloadCalls = chrome.downloads.download.mock.calls.map(
71+
([options]) => options
72+
);
73+
const footprintCall = downloadCalls.find((options) =>
74+
options.filename.endsWith("Workspace.pretty/QFN50P500X500X60-33N-D.kicad_mod")
75+
);
76+
const footprintContent = decodeDataUrl(footprintCall.url);
77+
expect(footprintContent).toContain(
78+
"../Workspace.3dshapes/STM32C552KEU6.wrl"
79+
);
80+
expect(footprintContent).not.toContain("STM32C552KEU6.stp");
81+
82+
const filenames = downloadCalls.map((options) => options.filename);
83+
expect(filenames).toContain(
84+
"KiCad/Workspace/Workspace.3dshapes/STM32C552KEU6.wrl"
85+
);
86+
});
87+
88+
it("exports Mouser WRL-only model archives when only 3D output is selected", async () => {
89+
const { chrome, listeners } = createServiceWorkerChrome({
90+
storageState: {
91+
downloadIndividually: true
92+
}
93+
});
94+
const readZipEntries = vi.fn(async () => [
95+
{
96+
name: "STM32C552KEU6/3D/STM32C552KEU6.wrl",
97+
data: new TextEncoder().encode("#VRML V2.0")
98+
}
99+
]);
100+
const fetchImpl = createSamacsysFetchImpl({
101+
zipStatus: 200
102+
});
103+
104+
loadServiceWorker({
105+
chrome,
106+
fetchImpl,
107+
readZipEntries
108+
});
109+
110+
const result = await sendRuntimeMessage(listeners.runtimeMessage[0], {
111+
type: "EXPORT_PART",
112+
partContext: createSamacsysPartContext("mouser"),
113+
options: {
114+
symbol: false,
115+
footprint: false,
116+
model3d: true,
117+
datasheet: false
118+
}
119+
});
120+
121+
expect(result.response).toEqual({
122+
ok: true,
123+
warnings: [],
124+
downloadCount: 1
125+
});
126+
127+
const filenames = chrome.downloads.download.mock.calls.map(
128+
([options]) => options.filename
129+
);
130+
expect(filenames).toEqual(["STM32C552KEU6.wrl"]);
131+
});
132+
});
133+
134+
/*
135+
######################################################################################################################
136+
137+
138+
AAAAAAAA
139+
AAAA AAAAA AAAAAAAA
140+
AAA AAA AAAA AAA
141+
AA AA AAA AAA
142+
AA AAAAAAAAAA AAA AAAAAAAAAA
143+
AAA AAA AAA AA
144+
AAA AAA AAAAA AA
145+
AAAAA AAA AAA AA
146+
AAA AAA AA
147+
AAA AAA AA
148+
AA AAA AA
149+
AA AAA AA
150+
AAA AAAAAAAAA AA
151+
AAA AAAAAAAAA AA
152+
AA AAAAAAAAAAAAAA AA
153+
AA AAAAAAAAAAAAAAAAAAAAAAAA AAAAAAA AA
154+
AAAAAAAAAAA AA AA
155+
AAA AA
156+
AAAA AA
157+
AAAA AA
158+
AAAAA AA
159+
AAAAA AA
160+
AAAAA AA
161+
AAAAAA AA
162+
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
163+
164+
165+
######################################################################################################################
166+
167+
Copyright (c) JoeShade
168+
Licensed under the GNU Affero General Public License v3.0
169+
170+
######################################################################################################################
171+
172+
+44 (0) 7356 042702 | joe@jshade.co.uk
173+
174+
######################################################################################################################
175+
*/

0 commit comments

Comments
 (0)