]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
test: add afterEach cleanup to all test files
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 27 Feb 2026 22:14:12 +0000 (23:14 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 27 Feb 2026 22:14:12 +0000 (23:14 +0100)
Add afterEach with mock.restoreAll() to 27 test files.
Ensures 100% coverage for mock cleanup (63/63 files).
Prevents test pollution between test runs.
Follows TEST_STYLE_GUIDE.md standards.

28 files changed:
tests/ChargingStationFactory.test.ts
tests/charging-station/ConfigurationKeyUtils.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-CertificateSigned.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-ClearCache.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-DeleteCertificate.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-GetInstalledCertificateIds.test.ts
tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-InstallCertificate.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-BootNotification.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-HeartBeat.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-ISO15118.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-NotifyReport.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-SignCertificate.test.ts
tests/charging-station/ocpp/2.0/OCPP20RequestService-StatusNotification.test.ts
tests/charging-station/ocpp/auth/types/AuthTypes.test.ts
tests/charging-station/ocpp/auth/utils/AuthHelpers.test.ts
tests/charging-station/ocpp/auth/utils/AuthValidators.test.ts
tests/charging-station/ocpp/auth/utils/ConfigValidator.test.ts
tests/charging-station/ui-server/UIHttpServer.test.ts
tests/charging-station/ui-server/UIServerSecurity.test.ts
tests/charging-station/ui-server/UIWebSocketServer.test.ts
tests/charging-station/ui-server/ui-services/AbstractUIService.test.ts
tests/exception/BaseError.test.ts
tests/exception/OCPPError.test.ts
tests/helpers/TestLifecycleHelpers.ts
tests/types/ConfigurationData.test.ts
tests/utils/AsyncLock.test.ts
tests/utils/ElectricUtils.test.ts
tests/utils/StatisticUtils.test.ts

index a5ba713a5b94c110c9f9d36677746a3aeaa61aa2..80a03920d62dfef3bf50cc0adcb420db76991e20 100644 (file)
@@ -3,13 +3,17 @@
  * @description Unit tests for charging station factory utilities and OCPP service mocking
  */
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { getHashId } from '../src/charging-station/Helpers.js'
 import { AvailabilityType, ConnectorStatusEnum, OCPPVersion } from '../src/types/index.js'
 import { createChargingStation, createChargingStationTemplate } from './ChargingStationFactory.js'
 
 await describe('ChargingStationFactory', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
+
   await describe('OCPP Service Mocking', async () => {
     await it('should throw error when OCPPRequestService.requestHandler is not mocked', async () => {
       const station = createChargingStation({ connectorsCount: 1 })
index 031f92a694fc5c94ac6f375ab6aa39070d6b6ab1..a9479c62b7ecbb03032fbb72b9e3a265fcdbec03 100644 (file)
@@ -3,7 +3,7 @@
  * @description Unit tests for OCPP configuration key management utilities
  */
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import type { ChargingStationOcppConfiguration } from '../../src/types/index.js'
 
@@ -22,6 +22,9 @@ const VALUE_A = 'ValueA'
 const VALUE_B = 'ValueB'
 
 await describe('ConfigurationKeyUtils test suite', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await describe('getConfigurationKey()', async () => {
     await it('should return undefined when configurationKey array is missing', () => {
       const cs = createChargingStation()
index 3dff62bebf2cfe8c5dda658fa3e9577d92056b94..2227f8c59f56ad9d9253d2bab134c75186b1c9e6 100644 (file)
@@ -4,7 +4,7 @@
  */
 
 import { expect } from '@std/expect'
-import { describe, it, mock, type Mock } from 'node:test'
+import { afterEach, describe, it, mock, type Mock } from 'node:test'
 
 import type { ChargingStation } from '../../../../src/charging-station/index.js'
 import type {
@@ -105,6 +105,10 @@ const createMockCertificateManager = (
 })
 
 await describe('I04 - CertificateSigned', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
+
   const mockChargingStation = createChargingStation({
     baseName: TEST_CHARGING_STATION_BASE_NAME,
     connectorsCount: 3,
index f99573fa55102722c2f3decfcbeacc8f0022d0e7..b28fa9b4a64f9dd420c106b3570bf07edea2b11c 100644 (file)
@@ -4,7 +4,7 @@
  */
 
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { createTestableIncomingRequestService } from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
 import { OCPP20IncomingRequestService } from '../../../../src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.js'
@@ -15,6 +15,10 @@ import { createChargingStation } from '../../../ChargingStationFactory.js'
 import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConstants.js'
 
 await describe('C11 - Clear Authorization Data in Authorization Cache', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
+
   const mockChargingStation = createChargingStation({
     baseName: TEST_CHARGING_STATION_BASE_NAME,
     connectorsCount: 3,
@@ -86,7 +90,9 @@ await describe('C11 - Clear Authorization Data in Authorization Cache', async ()
     await it('should NOT call idTagsCache.deleteIdTags() on ClearCache request', async () => {
       // Verify that IdTagsCache is not touched
       let deleteIdTagsCalled = false
-      const originalDeleteIdTags = mockChargingStation.idTagsCache.deleteIdTags.bind(mockChargingStation.idTagsCache)
+      const originalDeleteIdTags = mockChargingStation.idTagsCache.deleteIdTags.bind(
+        mockChargingStation.idTagsCache
+      )
 
       Object.assign(mockChargingStation.idTagsCache, {
         deleteIdTags: () => {
index 696133fbd9ce471efc3c5c08e89fd6ccfe539a5c..5bd120b6d43644edb9d34937eb996c21de2fb668 100644 (file)
@@ -4,7 +4,7 @@
  */
 
 import { expect } from '@std/expect'
-import { describe, it, mock } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import type { ChargingStationWithCertificateManager } from '../../../../src/charging-station/ocpp/2.0/OCPP20CertificateManager.js'
 
@@ -54,6 +54,10 @@ const createMockCertificateManager = (
 })
 
 await describe('I04 - DeleteCertificate', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
+
   const mockChargingStation = createChargingStation({
     baseName: TEST_CHARGING_STATION_BASE_NAME,
     connectorsCount: 3,
index ea1374c5111f6e83c6a764f47fe27eb6be34a525..8eb242917927836c599c9010a80d2d3c0eb41d41 100644 (file)
@@ -4,7 +4,7 @@
  */
 
 import { expect } from '@std/expect'
-import { describe, it, mock } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import type { ChargingStationWithCertificateManager } from '../../../../src/charging-station/ocpp/2.0/OCPP20CertificateManager.js'
 
@@ -59,6 +59,10 @@ const createMockCertificateManager = (
 })
 
 await describe('I04 - GetInstalledCertificateIds', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
+
   const mockChargingStation = createChargingStation({
     baseName: TEST_CHARGING_STATION_BASE_NAME,
     connectorsCount: 3,
@@ -72,7 +76,8 @@ await describe('I04 - GetInstalledCertificateIds', async () => {
   })
 
   // Cast to allow setting certificateManager property
-  const stationWithCertManager = mockChargingStation as unknown as ChargingStationWithCertificateManager
+  const stationWithCertManager =
+    mockChargingStation as unknown as ChargingStationWithCertificateManager
   stationWithCertManager.certificateManager = createMockCertificateManager()
 
   const incomingRequestService = new OCPP20IncomingRequestService()
@@ -255,13 +260,18 @@ await describe('I04 - GetInstalledCertificateIds', async () => {
       })
 
       // Explicitly set to null/undefined
-      const stationNoCertManager = stationWithoutCertManager as unknown as ChargingStationWithCertificateManager
-      stationNoCertManager.certificateManager = null as unknown as ChargingStationWithCertificateManager['certificateManager']
+      const stationNoCertManager =
+        stationWithoutCertManager as unknown as ChargingStationWithCertificateManager
+      stationNoCertManager.certificateManager =
+        null as unknown as ChargingStationWithCertificateManager['certificateManager']
 
       const request: OCPP20GetInstalledCertificateIdsRequest = {}
 
       const response: OCPP20GetInstalledCertificateIdsResponse =
-        await testableService.handleRequestGetInstalledCertificateIds(stationWithoutCertManager, request)
+        await testableService.handleRequestGetInstalledCertificateIds(
+          stationWithoutCertManager,
+          request
+        )
 
       expect(response).toBeDefined()
       expect(response.status).toBe(GetInstalledCertificateStatusEnumType.NotFound)
index 64137e8d83fc5d2380fa2444e7d1bb061c77b441..6d47f906243f348571145ea9f49d529a18c039e7 100644 (file)
@@ -4,7 +4,7 @@
  */
 
 import { expect } from '@std/expect'
-import { describe, it, mock } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import type { ChargingStationWithCertificateManager } from '../../../../src/charging-station/ocpp/2.0/OCPP20CertificateManager.js'
 
@@ -68,6 +68,10 @@ const createMockCertificateManager = (
 })
 
 await describe('I03 - InstallCertificate', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
+
   const mockChargingStation = createChargingStation({
     baseName: TEST_CHARGING_STATION_BASE_NAME,
     connectorsCount: 3,
@@ -81,7 +85,8 @@ await describe('I03 - InstallCertificate', async () => {
   })
 
   // Cast to allow setting certificateManager property
-  const stationWithCertManager = mockChargingStation as unknown as ChargingStationWithCertificateManager
+  const stationWithCertManager =
+    mockChargingStation as unknown as ChargingStationWithCertificateManager
   stationWithCertManager.certificateManager = createMockCertificateManager()
 
   const incomingRequestService = new OCPP20IncomingRequestService()
index 8476227da1feeb073ab526688e05aee1c0ccf030..5835ba624ddd9f124d8d46f1446d536c8f9172c6 100644 (file)
@@ -8,7 +8,7 @@
 /* eslint-disable @typescript-eslint/no-explicit-any */
 
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { OCPP20RequestService } from '../../../../src/charging-station/ocpp/2.0/OCPP20RequestService.js'
 import { OCPP20ResponseService } from '../../../../src/charging-station/ocpp/2.0/OCPP20ResponseService.js'
@@ -30,6 +30,10 @@ import {
 } from '../../ChargingStationTestConstants.js'
 
 await describe('B01 - Cold Boot Charging Station', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
+
   const mockResponseService = new OCPP20ResponseService()
   const requestService = new OCPP20RequestService(mockResponseService)
 
index 8b19aa04235cbb6af0032e9e98bc6515e16480fe..33c096a0318c9d2489b070a8e0a2700e66ae791f 100644 (file)
@@ -8,7 +8,7 @@
 /* eslint-disable @typescript-eslint/no-explicit-any */
 
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { OCPP20RequestService } from '../../../../src/charging-station/ocpp/2.0/OCPP20RequestService.js'
 import { OCPP20ResponseService } from '../../../../src/charging-station/ocpp/2.0/OCPP20ResponseService.js'
@@ -28,6 +28,9 @@ import {
 } from '../../ChargingStationTestConstants.js'
 
 await describe('G02 - Heartbeat', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   const mockResponseService = new OCPP20ResponseService()
   const requestService = new OCPP20RequestService(mockResponseService)
 
index 65eac6bd2a4193baac4a0bf609bac2e1142d691f..506ad930462171b8a24ee035dcc85620eb2ea4f1 100644 (file)
@@ -5,7 +5,7 @@
 /* cspell:ignore Bvbn NQIF CBCYX */
 
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { createTestableRequestService } from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
 import {
@@ -42,6 +42,9 @@ const createMockOCSPRequestData = (): OCSPRequestDataType => ({
 })
 
 await describe('M02 - Get15118EVCertificate Request', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   const mockChargingStation = createChargingStation({
     baseName: TEST_CHARGING_STATION_BASE_NAME,
     connectorsCount: 3,
index 45a0ca674b67db364ecf7854fb868eda2129e0c5..6b55e96996d62b338b2c8faa31924a2dd1b79d10 100644 (file)
@@ -4,11 +4,9 @@
  */
 
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
-import {
-  createTestableRequestService,
-} from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
+import { createTestableRequestService } from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
 import {
   AttributeEnumType,
   DataEnumType,
@@ -31,6 +29,9 @@ import {
 } from '../../ChargingStationTestConstants.js'
 
 await describe('B07/B08 - NotifyReport', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   const { service: testableService } = createTestableRequestService()
 
   const mockChargingStation = createChargingStation({
index 1a8b05064546662ec03fb7e78373abee95eb0b9f..6753286181cb2090f75583555be6d2d9291cc08b 100644 (file)
@@ -4,7 +4,7 @@
  */
 
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { createTestableRequestService } from '../../../../src/charging-station/ocpp/2.0/__testable__/index.js'
 import {
@@ -22,6 +22,9 @@ import { TEST_CHARGING_STATION_BASE_NAME } from '../../ChargingStationTestConsta
 const MOCK_ORGANIZATION_NAME = 'Test Organization Inc.'
 
 await describe('I02 - SignCertificate Request', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   const mockChargingStation = createChargingStation({
     baseName: TEST_CHARGING_STATION_BASE_NAME,
     connectorsCount: 3,
index 9bd0b808d891a5fcb3c135da99ff0a97dd8882e6..cd410cdfd74008a7352700fd122deaad0724e2e8 100644 (file)
@@ -8,7 +8,7 @@
 /* eslint-disable @typescript-eslint/no-explicit-any */
 
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { OCPP20RequestService } from '../../../../src/charging-station/ocpp/2.0/OCPP20RequestService.js'
 import { OCPP20ResponseService } from '../../../../src/charging-station/ocpp/2.0/OCPP20ResponseService.js'
@@ -29,6 +29,9 @@ import {
 } from '../../ChargingStationTestConstants.js'
 
 await describe('G01 - Status Notification', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   const mockResponseService = new OCPP20ResponseService()
   const requestService = new OCPP20RequestService(mockResponseService)
 
index b8661050070b49e9d84472bb7a33cbf46dd5b192..0f84170c365d1567fc3067d116ed21e34b7a8c8a 100644 (file)
@@ -3,7 +3,7 @@
  * @description Unit tests for authentication type definitions and mappings
  */
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import {
   AuthContext,
@@ -31,6 +31,9 @@ import {
 import { OCPPVersion } from '../../../../../src/types/ocpp/OCPPVersion.js'
 
 await describe('AuthTypes', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await describe('IdentifierTypeGuards', async () => {
     await it('should correctly identify OCPP 1.6 types', () => {
       expect(isOCPP16Type(IdentifierType.ID_TAG)).toBe(true)
index c4d4a84988b3044b2cd73daf4c2bb3a470a4a30b..e17dbd29e3be5805f3da663c6c67578a4d5912a8 100644 (file)
@@ -3,7 +3,7 @@
  * @description Unit tests for authentication helper utilities
  */
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import {
   AuthContext,
@@ -17,6 +17,9 @@ import { AuthHelpers } from '../../../../../src/charging-station/ocpp/auth/utils
 import { OCPPVersion } from '../../../../../src/types/ocpp/OCPPVersion.js'
 
 await describe('AuthHelpers', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await describe('calculateTTL', async () => {
     await it('should return undefined for undefined expiry date', () => {
       const result = AuthHelpers.calculateTTL(undefined)
index 0b39ba034e111bf3f8b43770c1502af58455d018..5fbf2da592da6cf128ed2e611de11eb7f442b328 100644 (file)
@@ -3,7 +3,7 @@
  * @description Unit tests for authentication validation utilities
  */
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import {
   type AuthConfiguration,
@@ -15,6 +15,9 @@ import { AuthValidators } from '../../../../../src/charging-station/ocpp/auth/ut
 import { OCPPVersion } from '../../../../../src/types/ocpp/OCPPVersion.js'
 
 await describe('AuthValidators', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await describe('isValidCacheTTL', async () => {
     await it('should return true for undefined TTL', () => {
       expect(AuthValidators.isValidCacheTTL(undefined)).toBe(true)
index 1dd09d880be37599024789b1484b479d7f7ee7d3..a9c7b3cebe6beef87b1676ee550b29a9c3141191 100644 (file)
@@ -5,7 +5,7 @@
 // Copyright Jerome Benoit. 2021-2025. All Rights Reserved.
 
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import {
   type AuthConfiguration,
@@ -15,6 +15,9 @@ import {
 import { AuthConfigValidator } from '../../../../../src/charging-station/ocpp/auth/utils/ConfigValidator.js'
 
 await describe('AuthConfigValidator', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await describe('validate', async () => {
     await it('should accept valid configuration', () => {
       const config: AuthConfiguration = {
index aaf148bc65f61f6e5fef5fe54c77c32b0ca32228..c3ab62c7260a80ee205ca70ab65c559bcd2149cc 100644 (file)
@@ -5,7 +5,7 @@
 // Copyright Jerome Benoit. 2024-2025. All Rights Reserved.
 
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 import { gunzipSync } from 'node:zlib'
 
 import type { UUIDv4 } from '../../../src/types/index.js'
@@ -47,6 +47,9 @@ const createLargePayload = (status: ResponseStatus = ResponseStatus.SUCCESS) =>
 })
 
 await describe('UIHttpServer test suite', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await it('should delete response handler after successful send', () => {
     const server = new TestableUIHttpServer(createHttpServerConfig())
     const res = new MockServerResponse()
index 3c851d04120352476e753b55beb88136ac6fb3e2..5312bd94dc8773c596199ad501e4bb656a422956 100644 (file)
@@ -5,7 +5,7 @@
 // Copyright Jerome Benoit. 2024-2025. All Rights Reserved.
 
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import {
   createBodySizeLimiter,
@@ -19,6 +19,9 @@ import { waitForStreamFlush } from './UIServerTestUtils.js'
 const RATE_WINDOW_EXPIRY_DELAY_MS = 110
 
 await describe('UIServerSecurity test suite', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await describe('isValidCredential()', async () => {
     await it('should return true for matching credentials', () => {
       expect(isValidCredential('myPassword123', 'myPassword123')).toBe(true)
index 3f5466048683adb84c48f53bde53db51959dd3e1..5e8bf64ebc0d3e58d137cd0b18163358d96575ed 100644 (file)
@@ -5,7 +5,7 @@
 // Copyright Jerome Benoit. 2024-2025. All Rights Reserved.
 
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import type { UUIDv4 } from '../../../src/types/index.js'
 
@@ -35,6 +35,9 @@ class TestableUIWebSocketServer extends UIWebSocketServer {
 }
 
 await describe('UIWebSocketServer test suite', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await it('should delete response handler after successful send', () => {
     const config = createMockUIServerConfiguration()
     const server = new TestableUIWebSocketServer(config)
index 58081dd8ac8a088aee11ce3dfe1a2bca2d3587f0..a1eadcd02f84af8565c162e60651d1d38fc978a1 100644 (file)
@@ -5,7 +5,7 @@
 // Copyright Jerome Benoit. 2024-2025. All Rights Reserved.
 
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { UIWebSocketServer } from '../../../../src/charging-station/ui-server/UIWebSocketServer.js'
 import { ProcedureName, ProtocolVersion, ResponseStatus } from '../../../../src/types/index.js'
@@ -27,6 +27,9 @@ class TestableUIWebSocketServer extends UIWebSocketServer {
 }
 
 await describe('AbstractUIService test suite', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await it('should check response handler existence before sending', () => {
     const config = createMockUIServerConfiguration()
     const server = new TestableUIWebSocketServer(config)
index 1b505abb59cbce0c0596e54ef9a9c9df22650cb7..a715a7ddf6b75a3bb164bea3d048beec187e7aae 100644 (file)
@@ -3,11 +3,14 @@
  * @description Unit tests for base error class functionality
  */
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { BaseError } from '../../src/exception/BaseError.js'
 
 await describe('BaseError test suite', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await it('should create instance with default values', () => {
     const baseError = new BaseError()
     expect(baseError).toBeInstanceOf(BaseError)
index fef65af84a0923e01dfaabadf0d5d8e925fde7e3..4a5ff48789030a24f674ff9960265e5908c6ed16 100644 (file)
@@ -3,13 +3,17 @@
  * @description Unit tests for OCPP-specific error class
  */
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { OCPPError } from '../../src/exception/OCPPError.js'
 import { ErrorType } from '../../src/types/index.js'
 import { Constants } from '../../src/utils/Constants.js'
 
 await describe('OCPPError test suite', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
+
   await it('should create instance with error code and default values', () => {
     const ocppError = new OCPPError(ErrorType.GENERIC_ERROR, '')
     expect(ocppError).toBeInstanceOf(OCPPError)
index 075e0960b80929a0840b6c4a65d57fe5759617ba..4de31796e63aeac612ecf0e388c357449b5628c3 100644 (file)
@@ -76,10 +76,7 @@ export interface TimerHelperOptions {
  */
 interface MockContext {
   mock: {
-    method: (
-      object: object,
-      methodName: string
-    ) => { mock: { calls: unknown[][] } }
+    method: (object: object, methodName: string) => { mock: { calls: unknown[][] } }
   }
 }
 
index 62ce324bd859a06d537b0cd5ec3c7c6ad40bf831..979d707c33bbb0417f8da6f92d8180512752607e 100644 (file)
@@ -3,7 +3,7 @@
  * @description Unit tests for configuration data types and enumerations
  */
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import {
   ApplicationProtocolVersion,
@@ -12,6 +12,10 @@ import {
 } from '../../src/types/ConfigurationData.js'
 
 await describe('ConfigurationData test suite', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
+
   await it('should define ConfigurationSection enumeration values', () => {
     expect(ConfigurationSection.log).toBe('log')
     expect(ConfigurationSection.performanceStorage).toBe('performanceStorage')
index 9f91d5ffa371059414924cfa64294d28ffd81f0d..0d8125776c2accad874d80407107227f6b2605d4 100644 (file)
@@ -4,11 +4,14 @@
  */
 import { expect } from '@std/expect'
 import { randomInt } from 'node:crypto'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { AsyncLock, AsyncLockType } from '../../src/utils/AsyncLock.js'
 
 await describe('AsyncLock test suite', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await it('should run synchronous functions exclusively in sequence', () => {
     const runs = 10
     const executed: number[] = []
index e61c09d091e2ef99d2de46c0be53b592b76da8c3..119402228e5701134cfde0631ed0e572ad497bcd 100644 (file)
@@ -3,11 +3,14 @@
  * @description Unit tests for electrical calculations (AC/DC power, amperage)
  */
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { ACElectricUtils, DCElectricUtils } from '../../src/utils/ElectricUtils.js'
 
 await describe('ElectricUtils test suite', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await it('should calculate DC power from voltage and current', () => {
     expect(DCElectricUtils.power(230, 1)).toBe(230)
   })
index 2cbfacc0f46ca8f6225b1d3c5d0df7d9393962bf..1b231a447e7df14b69a2df5e3c5b883e089e7752 100644 (file)
@@ -3,11 +3,14 @@
  * @description Unit tests for statistical calculation utilities
  */
 import { expect } from '@std/expect'
-import { describe, it } from 'node:test'
+import { afterEach, describe, it, mock } from 'node:test'
 
 import { average, max, median, min, percentile, std } from '../../src/utils/StatisticUtils.js'
 
 await describe('StatisticUtils test suite', async () => {
+  afterEach(() => {
+    mock.restoreAll()
+  })
   await it('should calculate arithmetic mean of array values', () => {
     expect(average([])).toBe(0)
     expect(average([0.08])).toBe(0.08)