From: Jérôme Benoit Date: Sat, 28 Feb 2026 17:43:48 +0000 (+0100) Subject: refactor(tests): standardize cleanup and strict equality X-Git-Tag: v3~79 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4ddc77fe2d3d0d1211bd861c65e85a45a2eae4e6;p=e-mobility-charging-stations-simulator.git refactor(tests): standardize cleanup and strict equality - Migrate 15 test files to use standardCleanup() from TestLifecycleHelpers - Replace all 27 .toEqual() with .toStrictEqual() across 10 files - Fix import path in OCPP20CertificateManager.test.ts This completes P0 (cleanup standardization) and P1 (strict equality) from the test audit. All 291 tests pass. --- diff --git a/tests/charging-station/ChargingStation-Configuration.test.ts b/tests/charging-station/ChargingStation-Configuration.test.ts index 4f9db712..83de2259 100644 --- a/tests/charging-station/ChargingStation-Configuration.test.ts +++ b/tests/charging-station/ChargingStation-Configuration.test.ts @@ -8,7 +8,7 @@ import { afterEach, beforeEach, describe, it } from 'node:test' import type { ChargingStation } from '../../src/charging-station/ChargingStation.js' import { AvailabilityType, RegistrationStatusEnumType } from '../../src/types/index.js' -import { withMockTimers } from '../helpers/TestLifecycleHelpers.js' +import { standardCleanup, withMockTimers } from '../helpers/TestLifecycleHelpers.js' import { cleanupChargingStation, createMockChargingStation } from './ChargingStationTestUtils.js' // Alias for tests that reference createRealChargingStation @@ -24,6 +24,7 @@ await describe('ChargingStation Configuration Management', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -121,6 +122,7 @@ await describe('ChargingStation Configuration Management', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -247,6 +249,7 @@ await describe('ChargingStation Configuration Management', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -428,6 +431,7 @@ await describe('ChargingStation Configuration Management', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -561,7 +565,7 @@ await describe('ChargingStation Configuration Management', async () => { // Assert const parsed = mocks.webSocket.getSentMessagesAsJson() expect(parsed.length).toBe(1) - expect(parsed[0]).toEqual([2, 'uuid-1', 'Heartbeat', {}]) + expect(parsed[0]).toStrictEqual([2, 'uuid-1', 'Heartbeat', {}]) }) await it('should clear captured messages via clearMessages()', () => { @@ -750,6 +754,7 @@ await describe('ChargingStation Configuration Management', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } diff --git a/tests/charging-station/ChargingStation-Connectors.test.ts b/tests/charging-station/ChargingStation-Connectors.test.ts index 227b9399..4b8591cb 100644 --- a/tests/charging-station/ChargingStation-Connectors.test.ts +++ b/tests/charging-station/ChargingStation-Connectors.test.ts @@ -8,6 +8,7 @@ import { afterEach, beforeEach, describe, it } from 'node:test' import type { ChargingStation } from '../../src/charging-station/ChargingStation.js' import { RegistrationStatusEnumType } from '../../src/types/index.js' +import { standardCleanup } from '../helpers/TestLifecycleHelpers.js' import { cleanupChargingStation, createMockChargingStation } from './ChargingStationTestUtils.js' // Alias for tests that reference createRealChargingStation @@ -22,6 +23,7 @@ await describe('ChargingStation Connector and EVSE State', async () => { }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -103,6 +105,7 @@ await describe('ChargingStation Connector and EVSE State', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -133,6 +136,7 @@ await describe('ChargingStation Connector and EVSE State', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -162,6 +166,7 @@ await describe('ChargingStation Connector and EVSE State', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -258,6 +263,7 @@ await describe('ChargingStation Connector and EVSE State', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -362,6 +368,7 @@ await describe('ChargingStation Connector and EVSE State', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } diff --git a/tests/charging-station/ChargingStation-Lifecycle.test.ts b/tests/charging-station/ChargingStation-Lifecycle.test.ts index e42648d6..5672cafe 100644 --- a/tests/charging-station/ChargingStation-Lifecycle.test.ts +++ b/tests/charging-station/ChargingStation-Lifecycle.test.ts @@ -7,6 +7,7 @@ import { afterEach, beforeEach, describe, it } from 'node:test' import type { ChargingStation } from '../../src/charging-station/ChargingStation.js' +import { standardCleanup } from '../helpers/TestLifecycleHelpers.js' import { cleanupChargingStation, createMockChargingStation } from './ChargingStationTestUtils.js' await describe('ChargingStation Lifecycle', async () => { @@ -17,6 +18,7 @@ await describe('ChargingStation Lifecycle', async () => { }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -168,6 +170,7 @@ await describe('ChargingStation Lifecycle', async () => { }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } diff --git a/tests/charging-station/ChargingStation-Resilience.test.ts b/tests/charging-station/ChargingStation-Resilience.test.ts index ee431b95..e4756de0 100644 --- a/tests/charging-station/ChargingStation-Resilience.test.ts +++ b/tests/charging-station/ChargingStation-Resilience.test.ts @@ -8,6 +8,7 @@ import { afterEach, beforeEach, describe, it } from 'node:test' import type { ChargingStation } from '../../src/charging-station/ChargingStation.js' import { RegistrationStatusEnumType } from '../../src/types/index.js' +import { standardCleanup } from '../helpers/TestLifecycleHelpers.js' import { cleanupChargingStation, createMockChargingStation } from './ChargingStationTestUtils.js' await describe('ChargingStation Error Recovery and Resilience', async () => { @@ -18,6 +19,7 @@ await describe('ChargingStation Error Recovery and Resilience', async () => { }) afterEach(() => { + standardCleanup() // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (station != null) { cleanupChargingStation(station) @@ -283,6 +285,7 @@ await describe('ChargingStation Message Buffering', async () => { }) afterEach(() => { + standardCleanup() // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (station != null) { cleanupChargingStation(station) diff --git a/tests/charging-station/ChargingStation-Transactions.test.ts b/tests/charging-station/ChargingStation-Transactions.test.ts index 32d15a19..af1f3035 100644 --- a/tests/charging-station/ChargingStation-Transactions.test.ts +++ b/tests/charging-station/ChargingStation-Transactions.test.ts @@ -7,7 +7,7 @@ import { afterEach, beforeEach, describe, it } from 'node:test' import type { ChargingStation } from '../../src/charging-station/ChargingStation.js' -import { withMockTimers } from '../helpers/TestLifecycleHelpers.js' +import { standardCleanup, withMockTimers } from '../helpers/TestLifecycleHelpers.js' import { cleanupChargingStation, createMockChargingStation } from './ChargingStationTestUtils.js' await describe('ChargingStation Transaction Management', async () => { @@ -18,6 +18,7 @@ await describe('ChargingStation Transaction Management', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -174,6 +175,7 @@ await describe('ChargingStation Transaction Management', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -277,6 +279,7 @@ await describe('ChargingStation Transaction Management', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } @@ -441,6 +444,7 @@ await describe('ChargingStation Transaction Management', async () => { station = undefined }) afterEach(() => { + standardCleanup() if (station != null) { cleanupChargingStation(station) } diff --git a/tests/charging-station/ChargingStation.test.ts b/tests/charging-station/ChargingStation.test.ts index 2f2a1901..ce58592c 100644 --- a/tests/charging-station/ChargingStation.test.ts +++ b/tests/charging-station/ChargingStation.test.ts @@ -241,7 +241,7 @@ await describe('ChargingStation Integration Tests', async () => { // Store some data in cache mocks1.idTagsCache.setIdTags('test-file.json', ['tag1', 'tag2']) - expect(mocks1.idTagsCache.getIdTags('test-file.json')).toEqual(['tag1', 'tag2']) + expect(mocks1.idTagsCache.getIdTags('test-file.json')).toStrictEqual(['tag1', 'tag2']) // Cleanup first station cleanupChargingStation(result1.station) diff --git a/tests/charging-station/ocpp/2.0/OCPP20CertificateManager.test.ts b/tests/charging-station/ocpp/2.0/OCPP20CertificateManager.test.ts index 4ddeb1b6..9e01913c 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20CertificateManager.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20CertificateManager.test.ts @@ -13,6 +13,7 @@ import { HashAlgorithmEnumType, InstallCertificateUseEnumType, } from '../../../../src/types/index.js' +import { standardCleanup } from '../../../helpers/TestLifecycleHelpers.js' const TEST_STATION_HASH_ID = 'test-station-hash-12345' const TEST_CERT_TYPE = InstallCertificateUseEnumType.CSMSRootCertificate @@ -61,6 +62,7 @@ await describe('I02-I04 - ISO15118 Certificate Management', async () => { force: true, recursive: true, }) + standardCleanup() }) await describe('storeCertificate', async () => { diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetBaseReport.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetBaseReport.test.ts index af451bca..96c2a544 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetBaseReport.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetBaseReport.test.ts @@ -27,6 +27,7 @@ import { } from '../../../../src/types/index.js' import { StandardParametersKey } from '../../../../src/types/ocpp/Configuration.js' import { Constants } from '../../../../src/utils/index.js' +import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js' import { createChargingStation } from '../../../ChargingStationFactory.js' import { TEST_CHARGE_POINT_MODEL, @@ -65,6 +66,7 @@ await describe('B07 - Get Base Report', async () => { // Reset singleton state after each test to ensure test isolation afterEach(() => { + standardCleanup() OCPP20VariableManager.getInstance().resetRuntimeOverrides() }) @@ -109,7 +111,7 @@ await describe('B07 - Get Base Report', async () => { const types = heartbeatEntry.variableAttribute?.map((a: { type?: string; value?: string }) => a.type) ?? [] - expect(types).toEqual([AttributeEnumType.Actual]) + expect(types).toStrictEqual([AttributeEnumType.Actual]) } // Boolean variable (AuthorizeRemoteStart) should only include Actual const authorizeRemoteStartEntry = reportData.find( @@ -123,7 +125,7 @@ await describe('B07 - Get Base Report', async () => { authorizeRemoteStartEntry.variableAttribute?.map( (a: { type?: string; value?: string }) => a.type ) ?? [] - expect(types).toEqual([AttributeEnumType.Actual]) + expect(types).toStrictEqual([AttributeEnumType.Actual]) } }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetVariables.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetVariables.test.ts index 196006f8..12fd1116 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetVariables.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetVariables.test.ts @@ -21,6 +21,7 @@ import { ReasonCodeEnumType, } from '../../../../src/types/index.js' import { Constants } from '../../../../src/utils/index.js' +import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js' import { createChargingStation } from '../../../ChargingStationFactory.js' import { TEST_CHARGING_STATION_BASE_NAME, @@ -55,6 +56,7 @@ await describe('B06 - Get Variables', async () => { // Reset singleton state after each test to ensure test isolation afterEach(() => { + standardCleanup() OCPP20VariableManager.getInstance().resetRuntimeOverrides() }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RemoteStartAuth.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RemoteStartAuth.test.ts index c42f6d37..cc0420b3 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RemoteStartAuth.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RemoteStartAuth.test.ts @@ -23,6 +23,7 @@ import { type OCPP20IdTokenType, } from '../../../../src/types/ocpp/2.0/Transaction.js' import { OCPPVersion } from '../../../../src/types/ocpp/OCPPVersion.js' +import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js' await describe('G03 - Remote Start Pre-Authorization', async () => { let service: OCPP20IncomingRequestService | undefined @@ -60,7 +61,7 @@ await describe('G03 - Remote Start Pre-Authorization', async () => { }) afterEach(() => { - // Reset service and mock charging station state + standardCleanup() mockChargingStation = undefined service = undefined }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts index 49f0929c..6fa4185a 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts @@ -21,6 +21,7 @@ import { OCPP20IdTokenEnumType, } from '../../../../src/types/ocpp/2.0/Transaction.js' import { Constants } from '../../../../src/utils/index.js' +import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js' import { createChargingStation } from '../../../ChargingStationFactory.js' import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js' import { createMockAuthService } from '../auth/helpers/MockFactories.js' @@ -59,6 +60,7 @@ await describe('F01 & F02 - Remote Start Transaction', async () => { }) afterEach(() => { + standardCleanup() OCPPAuthServiceFactory.clearAllInstances() }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts index 2762fb1a..0a470463 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts @@ -28,6 +28,7 @@ import { OCPP20ReasonEnumType, } from '../../../../src/types/ocpp/2.0/Transaction.js' import { Constants } from '../../../../src/utils/index.js' +import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js' import { createChargingStation } from '../../../ChargingStationFactory.js' import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js' import { createMockAuthService } from '../auth/helpers/MockFactories.js' @@ -78,6 +79,7 @@ await describe('F03 - Remote Stop Transaction', async () => { }) afterEach(() => { + standardCleanup() OCPPAuthServiceFactory.clearAllInstances() }) @@ -388,7 +390,7 @@ await describe('F03 - Remote Stop Transaction', async () => { expect(Object.values(RequestStartStopStatusEnumType)).toContain(response.status) // OCPP 2.0 RequestStopTransaction response should only contain status - expect(Object.keys(response as object)).toEqual(['status']) + expect(Object.keys(response as object)).toStrictEqual(['status']) }) await it('should handle custom data in request payload', async () => { diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-SetVariables.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-SetVariables.test.ts index 9444c174..d47ce5c4 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-SetVariables.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-SetVariables.test.ts @@ -25,6 +25,7 @@ import { SetVariableStatusEnumType, } from '../../../../src/types/index.js' import { Constants } from '../../../../src/utils/index.js' +import { standardCleanup } from '../../../../tests/helpers/TestLifecycleHelpers.js' import { createChargingStation } from '../../../ChargingStationFactory.js' import { TEST_CHARGING_STATION_BASE_NAME, @@ -62,6 +63,7 @@ await describe('B05 - Set Variables', async () => { // Reset singleton state after each test to ensure test isolation afterEach(() => { + standardCleanup() OCPP20VariableManager.getInstance().resetRuntimeOverrides() }) diff --git a/tests/charging-station/ocpp/2.0/OCPP20RequestService-HeartBeat.test.ts b/tests/charging-station/ocpp/2.0/OCPP20RequestService-HeartBeat.test.ts index cc4a119a..8d9c3b76 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20RequestService-HeartBeat.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20RequestService-HeartBeat.test.ts @@ -126,8 +126,8 @@ await describe('G02 - Heartbeat', async () => { ) // All payloads should be identical empty objects - expect(payload1).toEqual(payload2) - expect(payload2).toEqual(payload3) + expect(payload1).toStrictEqual(payload2) + expect(payload2).toStrictEqual(payload3) expect(JSON.stringify(payload1)).toBe('{}') expect(JSON.stringify(payload2)).toBe('{}') expect(JSON.stringify(payload3)).toBe('{}') @@ -179,7 +179,7 @@ await describe('G02 - Heartbeat', async () => { // According to OCPP 2.0 specification, HeartBeat request should be an empty object // This validates compliance with the official OCPP 2.0 standard expect(payload).toBeDefined() - expect(payload).toEqual({}) + expect(payload).toStrictEqual({}) expect(has('constructor', payload)).toBe(false) // Ensure it's a plain object and not an instance of another type diff --git a/tests/charging-station/ocpp/2.0/OCPP20RequestService-NotifyReport.test.ts b/tests/charging-station/ocpp/2.0/OCPP20RequestService-NotifyReport.test.ts index 82cbe448..9bcd6903 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20RequestService-NotifyReport.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20RequestService-NotifyReport.test.ts @@ -123,7 +123,7 @@ await describe('B07/B08 - NotifyReport', async () => { expect(payload.requestId).toBe(456) expect(payload.seqNo).toBe(1) expect(payload.tbc).toBe(false) - expect(payload.reportData).toEqual(reportData) + expect(payload.reportData).toStrictEqual(reportData) expect(Array.isArray(payload.reportData)).toBe(true) expect(payload.reportData).toHaveLength(1) }) @@ -205,7 +205,7 @@ await describe('B07/B08 - NotifyReport', async () => { expect(payload.requestId).toBe(789) expect(payload.seqNo).toBe(2) expect(payload.tbc).toBe(true) - expect(payload.reportData).toEqual(reportData) + expect(payload.reportData).toStrictEqual(reportData) expect(Array.isArray(payload.reportData)).toBe(true) expect(payload.reportData).toHaveLength(3) }) @@ -251,7 +251,7 @@ await describe('B07/B08 - NotifyReport', async () => { expect(payload.requestId).toBe(999) expect(payload.seqNo).toBe(0) expect(payload.tbc).toBe(true) - expect(payload.reportData).toEqual(reportData) + expect(payload.reportData).toStrictEqual(reportData) expect(Array.isArray(payload.reportData)).toBe(true) expect(payload.reportData).toHaveLength(1) }) @@ -276,7 +276,7 @@ await describe('B07/B08 - NotifyReport', async () => { expect(payload.requestId).toBe(100) expect(payload.seqNo).toBe(0) expect(payload.tbc).toBe(false) - expect(payload.reportData).toEqual([]) + expect(payload.reportData).toStrictEqual([]) expect(Array.isArray(payload.reportData)).toBe(true) expect(payload.reportData).toHaveLength(0) }) @@ -529,6 +529,6 @@ await describe('B07/B08 - NotifyReport', async () => { const expectedKeys = ['generatedAt', 'reportData', 'requestId', 'seqNo', 'tbc'] const actualKeys = Object.keys(payload as object).sort() expectedKeys.sort() - expect(actualKeys).toEqual(expectedKeys) + expect(actualKeys).toStrictEqual(expectedKeys) }) }) diff --git a/tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts b/tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts index 3b03ac3f..f6a2cf7e 100644 --- a/tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts +++ b/tests/charging-station/ocpp/auth/cache/InMemoryAuthCache.test.ts @@ -64,7 +64,7 @@ await describe('InMemoryAuthCache - G03.FR.01 Conformance', async () => { expect(cachedResult).toBeDefined() expect(cachedResult?.status).toBe(AuthorizationStatus.ACCEPTED) - expect(cachedResult?.timestamp).toEqual(mockResult.timestamp) + expect(cachedResult?.timestamp).toStrictEqual(mockResult.timestamp) }) await it('should track cache hits in statistics', async () => { diff --git a/tests/charging-station/ocpp/auth/factories/AuthComponentFactory.test.ts b/tests/charging-station/ocpp/auth/factories/AuthComponentFactory.test.ts index f49e2869..03c56b94 100644 --- a/tests/charging-station/ocpp/auth/factories/AuthComponentFactory.test.ts +++ b/tests/charging-station/ocpp/auth/factories/AuthComponentFactory.test.ts @@ -11,10 +11,11 @@ import type { AuthConfiguration } from '../../../../../src/charging-station/ocpp import { AuthComponentFactory } from '../../../../../src/charging-station/ocpp/auth/factories/AuthComponentFactory.js' import { OCPPVersion } from '../../../../../src/types/ocpp/OCPPVersion.js' import { createChargingStation } from '../../../../ChargingStationFactory.js' +import { standardCleanup } from '../../../../helpers/TestLifecycleHelpers.js' await describe('AuthComponentFactory', async () => { afterEach(() => { - // Cleanup handled by test isolation - each test creates its own instances + standardCleanup() }) await describe('createAdapters', async () => { diff --git a/tests/charging-station/ocpp/auth/services/OCPPAuthServiceFactory.test.ts b/tests/charging-station/ocpp/auth/services/OCPPAuthServiceFactory.test.ts index 1ffbd928..938a5a70 100644 --- a/tests/charging-station/ocpp/auth/services/OCPPAuthServiceFactory.test.ts +++ b/tests/charging-station/ocpp/auth/services/OCPPAuthServiceFactory.test.ts @@ -9,12 +9,14 @@ import type { ChargingStation } from '../../../../../src/charging-station/Chargi import { OCPPAuthServiceFactory } from '../../../../../src/charging-station/ocpp/auth/services/OCPPAuthServiceFactory.js' import { OCPPVersion } from '../../../../../src/types/ocpp/OCPPVersion.js' +import { standardCleanup } from '../../../../helpers/TestLifecycleHelpers.js' import { createMockAuthServiceTestStation } from '../helpers/MockFactories.js' await describe('OCPPAuthServiceFactory', async () => { // Clear all cached instances after each test to ensure test isolation afterEach(() => { OCPPAuthServiceFactory.clearAllInstances() + standardCleanup() }) await describe('getInstance', async () => { diff --git a/tests/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.test.ts b/tests/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.test.ts index 25808b54..9553481d 100644 --- a/tests/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.test.ts +++ b/tests/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.test.ts @@ -17,11 +17,12 @@ import { type UnifiedIdentifier, } from '../../../../../src/charging-station/ocpp/auth/types/AuthTypes.js' import { OCPPVersion } from '../../../../../src/types/ocpp/OCPPVersion.js' +import { standardCleanup } from '../../../../helpers/TestLifecycleHelpers.js' import { createMockAuthServiceTestStation } from '../helpers/MockFactories.js' await describe('OCPPAuthServiceImpl', async () => { afterEach(() => { - // Cleanup handled by test isolation - each test creates its own mock station + standardCleanup() }) await describe('constructor', async () => { diff --git a/tests/charging-station/ocpp/auth/utils/AuthHelpers.test.ts b/tests/charging-station/ocpp/auth/utils/AuthHelpers.test.ts index 49706f98..db13cf29 100644 --- a/tests/charging-station/ocpp/auth/utils/AuthHelpers.test.ts +++ b/tests/charging-station/ocpp/auth/utils/AuthHelpers.test.ts @@ -93,7 +93,7 @@ await describe('AuthHelpers', async () => { const request = AuthHelpers.createAuthRequest(identifier, context, undefined, metadata) - expect(request.metadata).toEqual({ source: 'test' }) + expect(request.metadata).toStrictEqual({ source: 'test' }) }) }) @@ -120,7 +120,7 @@ await describe('AuthHelpers', async () => { expect(result.status).toBe(AuthorizationStatus.EXPIRED) expect(result.method).toBe(AuthenticationMethod.REMOTE_AUTHORIZATION) - expect(result.additionalInfo).toEqual({ reason: 'Token expired on 2024-01-01' }) + expect(result.additionalInfo).toStrictEqual({ reason: 'Token expired on 2024-01-01' }) }) }) @@ -480,7 +480,7 @@ await describe('AuthHelpers', async () => { expect(merged?.status).toBe(AuthorizationStatus.BLOCKED) expect(merged?.method).toBe(AuthenticationMethod.LOCAL_LIST) expect(merged?.isOffline).toBe(true) - expect(merged?.additionalInfo).toEqual({ + expect(merged?.additionalInfo).toStrictEqual({ attemptedMethods: 'LocalList, RemoteAuthorization', totalAttempts: 2, }) @@ -504,7 +504,7 @@ await describe('AuthHelpers', async () => { const sanitized = AuthHelpers.sanitizeForLogging(result) - expect(sanitized).toEqual({ + expect(sanitized).toStrictEqual({ hasExpiryDate: true, hasGroupId: true, hasPersonalMessage: true, @@ -525,7 +525,7 @@ await describe('AuthHelpers', async () => { const sanitized = AuthHelpers.sanitizeForLogging(result) - expect(sanitized).toEqual({ + expect(sanitized).toStrictEqual({ hasExpiryDate: false, hasGroupId: false, hasPersonalMessage: false, diff --git a/tests/charging-station/ui-server/UIHttpServer.test.ts b/tests/charging-station/ui-server/UIHttpServer.test.ts index c3ab62c7..09207689 100644 --- a/tests/charging-station/ui-server/UIHttpServer.test.ts +++ b/tests/charging-station/ui-server/UIHttpServer.test.ts @@ -149,7 +149,7 @@ await describe('UIHttpServer test suite', async () => { expect(res.body).toBeDefined() const parsedBody = JSON.parse(res.body ?? '{}') as Record expect(parsedBody.status).toBe('success') - expect(parsedBody.hashIdsSucceeded).toEqual(['station-1', 'station-2']) + expect(parsedBody.hashIdsSucceeded).toStrictEqual(['station-1', 'station-2']) }) await it('should include error details in failure response', () => { @@ -168,7 +168,7 @@ await describe('UIHttpServer test suite', async () => { const parsedBody = JSON.parse(res.body ?? '{}') as Record expect(parsedBody.status).toBe('failure') expect(parsedBody.errorMessage).toBe('Test error') - expect(parsedBody.hashIdsFailed).toEqual(['station-1']) + expect(parsedBody.hashIdsFailed).toStrictEqual(['station-1']) }) await it('should create server with valid HTTP configuration', () => { diff --git a/tests/utils/Utils.test.ts b/tests/utils/Utils.test.ts index d1901ff9..9f1c538c 100644 --- a/tests/utils/Utils.test.ts +++ b/tests/utils/Utils.test.ts @@ -52,7 +52,7 @@ await describe('Utils test suite', async () => { await it('should generate valid UUIDs and validate them correctly', () => { const uuid = generateUUID() expect(uuid).toBeDefined() - expect(uuid.length).toEqual(36) + expect(uuid.length).toStrictEqual(36) expect(validateUUID(uuid)).toBe(true) expect(validateUUID('abcdef00-0000-4000-9000-000000000000')).toBe(true) expect(validateUUID('abcdef00-0000-4000-a000-000000000000')).toBe(true) @@ -171,7 +171,7 @@ await describe('Utils test suite', async () => { expect(convertToInt(null)).toBe(0) expect(convertToInt(0)).toBe(0) const randomInteger = randomInt(Constants.MAX_RANDOM_INTEGER) - expect(convertToInt(randomInteger)).toEqual(randomInteger) + expect(convertToInt(randomInteger)).toStrictEqual(randomInteger) expect(convertToInt('-1')).toBe(-1) expect(convertToInt('1')).toBe(1) expect(convertToInt('1.1')).toBe(1) @@ -192,7 +192,7 @@ await describe('Utils test suite', async () => { expect(convertToFloat(null)).toBe(0) expect(convertToFloat(0)).toBe(0) const randomFloat = getRandomFloat() - expect(convertToFloat(randomFloat)).toEqual(randomFloat) + expect(convertToFloat(randomFloat)).toStrictEqual(randomFloat) expect(convertToFloat('-1')).toBe(-1) expect(convertToFloat('1')).toBe(1) expect(convertToFloat('1.1')).toBe(1.1) @@ -252,7 +252,7 @@ await describe('Utils test suite', async () => { expect(typeof randomFloat === 'number').toBe(true) expect(randomFloat).toBeGreaterThanOrEqual(0) expect(randomFloat).toBeLessThanOrEqual(Number.MAX_VALUE) - expect(randomFloat).not.toEqual(getRandomFloat()) + expect(randomFloat).not.toStrictEqual(getRandomFloat()) expect(() => getRandomFloat(0, 1)).toThrow(new RangeError('Invalid interval')) expect(() => getRandomFloat(Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY)).toThrow( new RangeError('Invalid interval') @@ -267,7 +267,7 @@ await describe('Utils test suite', async () => { extractTimeSeriesValues( new CircularBuffer(Array, Constants.DEFAULT_CIRCULAR_BUFFER_CAPACITY) ) - ).toEqual([]) + ).toStrictEqual([]) const circularBuffer = new CircularBuffer( Array, Constants.DEFAULT_CIRCULAR_BUFFER_CAPACITY @@ -275,7 +275,7 @@ await describe('Utils test suite', async () => { circularBuffer.push({ timestamp: Date.now(), value: 1.1 }) circularBuffer.push({ timestamp: Date.now(), value: 2.2 }) circularBuffer.push({ timestamp: Date.now(), value: 3.3 }) - expect(extractTimeSeriesValues(circularBuffer)).toEqual([1.1, 2.2, 3.3]) + expect(extractTimeSeriesValues(circularBuffer)).toStrictEqual([1.1, 2.2, 3.3]) }) await it('should correctly identify async functions from other types', () => {