From: Jérôme Benoit Date: Sat, 28 Feb 2026 15:36:56 +0000 (+0100) Subject: fix(test-isolation): move mock creation to beforeEach in CableFirst test X-Git-Tag: ocpp-server@v3.0.0~87 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5df3524f59efb16d19d0d69c117dc188cb036f57;p=e-mobility-charging-stations-simulator.git fix(test-isolation): move mock creation to beforeEach in CableFirst test - Move mockChargingStation initialization from module level to beforeEach() - Declare mockChargingStation as let at describe scope per TEST_STYLE_GUIDE.md - Ensures each test receives fresh mock instances - Fixes CRITICAL test isolation violation per test audit - All 12 tests in E02 - Cable-First Transaction Flow pass --- diff --git a/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent-CableFirst.test.ts b/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent-CableFirst.test.ts index 7c8300f5..cbd47542 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent-CableFirst.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent-CableFirst.test.ts @@ -3,7 +3,7 @@ * @description Unit tests for OCPP 2.0 cable-first transaction flow (E02) */ import { expect } from '@std/expect' -import { afterEach, describe, it } from 'node:test' +import { afterEach, beforeEach, describe, it } from 'node:test' import { OCPP20ServiceUtils } from '../../../../src/charging-station/ocpp/2.0/OCPP20ServiceUtils.js' import { @@ -39,10 +39,12 @@ import { * - E02.FR.03: Connector status transitions reflect cable state changes */ await describe('E02 - Cable-First Transaction Flow', async () => { - const mockChargingStation = createMockOCPP20TransactionTestStation() + let mockChargingStation: ReturnType - // Reset limits and state before tests - resetLimits(mockChargingStation) + beforeEach(() => { + mockChargingStation = createMockOCPP20TransactionTestStation() + resetLimits(mockChargingStation) + }) afterEach(() => { resetConnectorTransactionState(mockChargingStation)