From e6ba5ed9c74eb68e802103907af858178ae4f982 Mon Sep 17 00:00:00 2001 From: ciegovolador Date: Thu, 11 Jun 2026 03:14:32 -0300 Subject: [PATCH] test(sim): update PWM-callback assertions for the new timeMs arg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sample-accurate scheduling (06526c7) added an optional 3rd `timeMs` argument to PwmCallback / updatePwm, which broke 9 existing strict toHaveBeenCalledWith(pin, duty) assertions (PinManager, AVRSimulator, mega-emulation, attiny85). Match the real signature: PinManager drives updatePwm directly with no timeMs (assert `undefined`); the AVR OCR-poll path computes timeMs = cpu.cycles / 16000 (assert `expect.anything()`). Leaves one pre-existing red — component-to-spice "custom-chip missing fixture" — which fails on master too and is unrelated to this PR. Co-Authored-By: Claude Opus 4.8 --- frontend/src/__tests__/AVRSimulator.test.ts | 4 ++-- frontend/src/__tests__/PinManager.test.ts | 4 ++-- frontend/src/__tests__/attiny85-simulation.test.ts | 4 ++-- frontend/src/__tests__/mega-emulation.test.ts | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frontend/src/__tests__/AVRSimulator.test.ts b/frontend/src/__tests__/AVRSimulator.test.ts index f98cfd42..f88b9a44 100644 --- a/frontend/src/__tests__/AVRSimulator.test.ts +++ b/frontend/src/__tests__/AVRSimulator.test.ts @@ -168,7 +168,7 @@ describe('AVRSimulator — PWM OCR monitoring', () => { sim.start(); sim.stop(); - expect(pwmCb).toHaveBeenCalledWith(9, 128 / 255); + expect(pwmCb).toHaveBeenCalledWith(9, 128 / 255, expect.anything()); // 3rd arg = sim timeMs }); it('PWM covers all six Arduino PWM pins', () => { @@ -202,7 +202,7 @@ describe('AVRSimulator — PWM OCR monitoring', () => { PWM_MAP.forEach(({ pin }, i) => { const expected = ((i + 1) * 25) / 255; - expect(cbs[pin]).toHaveBeenCalledWith(pin, expected); + expect(cbs[pin]).toHaveBeenCalledWith(pin, expected, expect.anything()); // 3rd arg = sim timeMs }); }); }); diff --git a/frontend/src/__tests__/PinManager.test.ts b/frontend/src/__tests__/PinManager.test.ts index e0db42ac..b98cca16 100644 --- a/frontend/src/__tests__/PinManager.test.ts +++ b/frontend/src/__tests__/PinManager.test.ts @@ -124,7 +124,7 @@ describe('PinManager — PWM duty cycle', () => { const cb = vi.fn(); pm.onPwmChange(9, cb); pm.updatePwm(9, 0.5); - expect(cb).toHaveBeenCalledWith(9, 0.5); + expect(cb).toHaveBeenCalledWith(9, 0.5, undefined); // 3rd arg = optional timeMs (not passed here) }); it('stores the latest PWM value', () => { @@ -150,7 +150,7 @@ describe('PinManager — PWM duty cycle', () => { pwmPins.forEach((pin, i) => { const dc = (i + 1) / 6; pm.updatePwm(pin, dc); - expect(callbacks[i]).toHaveBeenCalledWith(pin, dc); + expect(callbacks[i]).toHaveBeenCalledWith(pin, dc, undefined); // optional timeMs not passed }); }); }); diff --git a/frontend/src/__tests__/attiny85-simulation.test.ts b/frontend/src/__tests__/attiny85-simulation.test.ts index 5843c765..2c66826b 100644 --- a/frontend/src/__tests__/attiny85-simulation.test.ts +++ b/frontend/src/__tests__/attiny85-simulation.test.ts @@ -283,7 +283,7 @@ describe('ATtiny85 — PWM monitoring', () => { sim.start(); sim.stop(); - expect(pwmCb).toHaveBeenCalledWith(1, 128 / 255); + expect(pwmCb).toHaveBeenCalledWith(1, 128 / 255, expect.anything()); // 3rd arg = sim timeMs }); it('PinManager receives PWM update on pin 0 when OCR0A (0x56) is written', () => { @@ -300,7 +300,7 @@ describe('ATtiny85 — PWM monitoring', () => { sim.start(); sim.stop(); - expect(pwmCb).toHaveBeenCalledWith(0, 64 / 255); + expect(pwmCb).toHaveBeenCalledWith(0, 64 / 255, expect.anything()); // 3rd arg = sim timeMs }); it('ATtiny85 PWM covers 4 pins (OCR0A/OCR0B/OCR1A/OCR1B)', () => { diff --git a/frontend/src/__tests__/mega-emulation.test.ts b/frontend/src/__tests__/mega-emulation.test.ts index 0752eeda..4f373576 100644 --- a/frontend/src/__tests__/mega-emulation.test.ts +++ b/frontend/src/__tests__/mega-emulation.test.ts @@ -301,7 +301,7 @@ describe('AVRSimulator Mega — PWM OCR mapping differs from Uno', () => { // Call pollPwmRegisters directly — avoids RAF dependency in unit tests (sim as any).pollPwmRegisters(); - expect(cb).toHaveBeenCalledWith(13, 128 / 255); + expect(cb).toHaveBeenCalledWith(13, 128 / 255, expect.anything()); // 3rd arg = sim timeMs sim.stop(); }); @@ -318,7 +318,7 @@ describe('AVRSimulator Mega — PWM OCR mapping differs from Uno', () => { (sim as any).pollPwmRegisters(); - expect(cb).toHaveBeenCalledWith(5, 200 / 255); + expect(cb).toHaveBeenCalledWith(5, 200 / 255, expect.anything()); // 3rd arg = sim timeMs sim.stop(); }); @@ -335,7 +335,7 @@ describe('AVRSimulator Mega — PWM OCR mapping differs from Uno', () => { (sim as any).pollPwmRegisters(); - expect(cb).toHaveBeenCalledWith(6, 100 / 255); + expect(cb).toHaveBeenCalledWith(6, 100 / 255, expect.anything()); // 3rd arg = sim timeMs sim.stop(); }); });