Skip to content

Commit fadc91d

Browse files
zaloclaude
andcommitted
Fix flaky tests: wait for worker console logs before asserting
Console logs from the CAD worker can arrive slightly after isWorking() returns false. Add waitForFunction polls for expected log tags before reading getConsoleLog() in the Measurement, Selector API, and Console tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fc4046e commit fadc91d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

test/cascade-studio.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ test.describe('Console', () => {
306306
console.log("a", "b", 42);
307307
Box(10, 10, 10);
308308
`);
309+
await page.waitForFunction(() => {
310+
const logs = window.CascadeAPI.getConsoleLog();
311+
return logs.some(l => l.includes('test message'));
312+
}, { timeout: 10000 });
309313
const logs = await page.evaluate(() => window.CascadeAPI.getConsoleLog());
310314
expect(logs.some(l => l.includes('test message'))).toBe(true);
311315
expect(logs.some(l => l.includes('a') && l.includes('b') && l.includes('42'))).toBe(true);
@@ -350,6 +354,12 @@ test.describe('Selector API', () => {
350354
`);
351355
const errors = await page.evaluate(() => window.CascadeAPI.getErrors());
352356
expect(errors).toEqual([]);
357+
358+
// Wait for all expected log tags to arrive (worker messages may lag slightly)
359+
await page.waitForFunction(() => {
360+
const logs = window.CascadeAPI.getConsoleLog();
361+
return ['EDGE_COUNT:', 'TOP_FACES:'].every(tag => logs.some(l => l.includes(tag)));
362+
}, { timeout: 10000 });
353363
const logs = await page.evaluate(() => window.CascadeAPI.getConsoleLog());
354364

355365
const edgeCount = parseInt(extractLog(logs, 'EDGE_COUNT'));
@@ -386,6 +396,12 @@ test.describe('Measurement Functions', () => {
386396
`);
387397
const errors = await page.evaluate(() => window.CascadeAPI.getErrors());
388398
expect(errors).toEqual([]);
399+
400+
// Wait for all expected log tags to arrive (worker messages may lag slightly)
401+
await page.waitForFunction(() => {
402+
const logs = window.CascadeAPI.getConsoleLog();
403+
return ['VOL:', 'AREA:', 'COM:'].every(tag => logs.some(l => l.includes(tag)));
404+
}, { timeout: 10000 });
389405
const logs = await page.evaluate(() => window.CascadeAPI.getConsoleLog());
390406

391407
expect(parseFloat(extractLog(logs, 'VOL'))).toBeCloseTo(1000, 0);

0 commit comments

Comments
 (0)