From: Jérôme Benoit Date: Tue, 24 Mar 2026 13:46:17 +0000 (+0100) Subject: refactor: audit-driven quick wins — fix assert.ok misuse, naming conventions, and... X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=901296a93b8f4b195acd355bf4846e2ac08fdc14;p=e-mobility-charging-stations-simulator.git refactor: audit-driven quick wins — fix assert.ok misuse, naming conventions, and hardcoded defaults - Replace 71 improper assert.ok(comparison) with assert.strictEqual/notStrictEqual in 10 test files per TEST_STYLE_GUIDE (assert.ok for boolean/existence only) - Rename lastUpdated → lastUpdatedDate in auth interfaces and strategies to follow Date suffix naming convention - Extract hardcoded 'ws://localhost' to OCPP20Constants.DEFAULT_CONNECTION_URL - Replace setTimeout(resolve, 50) with proper httpServer.close() await in UIMCPServer integration test --- diff --git a/src/charging-station/ocpp/2.0/OCPP20Constants.ts b/src/charging-station/ocpp/2.0/OCPP20Constants.ts index 64d6c607..c91d047a 100644 --- a/src/charging-station/ocpp/2.0/OCPP20Constants.ts +++ b/src/charging-station/ocpp/2.0/OCPP20Constants.ts @@ -138,6 +138,8 @@ export class OCPP20Constants extends OCPPConstants { // { from: OCPP20ConnectorStatusEnumType.Faulted, to: OCPP20ConnectorStatusEnumType.Faulted } ]) + static readonly DEFAULT_CONNECTION_URL = 'ws://localhost' + static readonly FIRMWARE_INSTALL_DELAY_MS = 5000 static readonly FIRMWARE_STATUS_DELAY_MS = 2000 static readonly FIRMWARE_VERIFY_DELAY_MS = 500 diff --git a/src/charging-station/ocpp/2.0/OCPP20VariableRegistry.ts b/src/charging-station/ocpp/2.0/OCPP20VariableRegistry.ts index c37be16a..470ef54d 100644 --- a/src/charging-station/ocpp/2.0/OCPP20VariableRegistry.ts +++ b/src/charging-station/ocpp/2.0/OCPP20VariableRegistry.ts @@ -20,6 +20,7 @@ import { type VariableName, } from '../../../types/index.js' import { Constants, convertToIntOrNaN, has } from '../../../utils/index.js' +import { OCPP20Constants } from './OCPP20Constants.js' /** * Metadata describing a variable (component-level configuration or runtime state). @@ -599,7 +600,7 @@ export const VARIABLE_REGISTRY: Record = { )]: { component: OCPP20ComponentName.ChargingStation as string, dataType: DataEnumType.string, - defaultValue: 'ws://localhost', + defaultValue: OCPP20Constants.DEFAULT_CONNECTION_URL, description: 'Central system connection URL.', isUrl: true, maxLength: 512, diff --git a/src/charging-station/ocpp/auth/interfaces/OCPPAuthService.ts b/src/charging-station/ocpp/auth/interfaces/OCPPAuthService.ts index d7b54acc..7122f981 100644 --- a/src/charging-station/ocpp/auth/interfaces/OCPPAuthService.ts +++ b/src/charging-station/ocpp/auth/interfaces/OCPPAuthService.ts @@ -84,7 +84,7 @@ export interface AuthStats { failedAuth: number /** Last update timestamp */ - lastUpdated: Date + lastUpdatedDate: Date /** Local authorization usage rate */ localUsageRate: number diff --git a/src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts b/src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts index 37286c0f..8420bc36 100644 --- a/src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts +++ b/src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts @@ -391,7 +391,7 @@ export class OCPPAuthServiceImpl implements OCPPAuthService { avgResponseTime: Math.round(avgResponseTime * 100) / 100, cacheHitRate: Math.round(cacheHitRate * 10000) / 100, failedAuth: this.metrics.failedAuth, - lastUpdated: this.metrics.lastReset, + lastUpdatedDate: this.metrics.lastReset, localUsageRate: Math.round(localUsageRate * 10000) / 100, rateLimit: rateLimitStats, remoteSuccessRate: Math.round(remoteSuccessRate * 10000) / 100, diff --git a/src/charging-station/ocpp/auth/strategies/LocalAuthStrategy.ts b/src/charging-station/ocpp/auth/strategies/LocalAuthStrategy.ts index a78b1475..7a94730d 100644 --- a/src/charging-station/ocpp/auth/strategies/LocalAuthStrategy.ts +++ b/src/charging-station/ocpp/auth/strategies/LocalAuthStrategy.ts @@ -36,7 +36,7 @@ export class LocalAuthStrategy implements AuthStrategy { private localAuthListManager?: LocalAuthListManager private stats = { cacheHits: 0, - lastUpdated: new Date(), + lastUpdatedDate: new Date(), localListHits: 0, offlineDecisions: 0, totalRequests: 0, @@ -134,7 +134,7 @@ export class LocalAuthStrategy implements AuthStrategy { } ) } finally { - this.stats.lastUpdated = new Date() + this.stats.lastUpdatedDate = new Date() } } @@ -184,7 +184,7 @@ export class LocalAuthStrategy implements AuthStrategy { this.isInitialized = false this.stats = { cacheHits: 0, - lastUpdated: new Date(), + lastUpdatedDate: new Date(), localListHits: 0, offlineDecisions: 0, totalRequests: 0, diff --git a/src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts b/src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts index d7bcb7ca..71786a43 100644 --- a/src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts +++ b/src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts @@ -39,7 +39,7 @@ export class RemoteAuthStrategy implements AuthStrategy { private stats = { avgResponseTimeMs: 0, failedRemoteAuth: 0, - lastUpdated: new Date(), + lastUpdatedDate: new Date(), networkErrors: 0, successfulRemoteAuth: 0, timeoutErrors: 0, @@ -156,7 +156,7 @@ export class RemoteAuthStrategy implements AuthStrategy { return undefined } finally { this.updateResponseTimeStats(startTime) - this.stats.lastUpdated = new Date() + this.stats.lastUpdatedDate = new Date() } } @@ -187,7 +187,7 @@ export class RemoteAuthStrategy implements AuthStrategy { this.stats = { avgResponseTimeMs: 0, failedRemoteAuth: 0, - lastUpdated: new Date(), + lastUpdatedDate: new Date(), networkErrors: 0, successfulRemoteAuth: 0, timeoutErrors: 0, diff --git a/tests/charging-station/ChargingStation-Configuration.test.ts b/tests/charging-station/ChargingStation-Configuration.test.ts index 4fa0224a..e233c4ad 100644 --- a/tests/charging-station/ChargingStation-Configuration.test.ts +++ b/tests/charging-station/ChargingStation-Configuration.test.ts @@ -40,7 +40,7 @@ await describe('ChargingStation Configuration Management', async () => { if (station.bootNotificationResponse == null) { assert.fail('Expected bootNotificationResponse to be defined') } - assert.ok(station.bootNotificationResponse.interval > 0) + assert.strictEqual(station.bootNotificationResponse.interval > 0, true) assert.strictEqual(station.inPendingState(), true) }) @@ -140,7 +140,7 @@ await describe('ChargingStation Configuration Management', async () => { if (station.bootNotificationResponse == null) { assert.fail('Expected bootNotificationResponse to be defined') } - assert.ok(station.bootNotificationResponse.interval > 0) + assert.strictEqual(station.bootNotificationResponse.interval > 0, true) assert.strictEqual(station.inRejectedState(), true) }) @@ -756,7 +756,7 @@ await describe('ChargingStation Configuration Management', async () => { // Assert assert.notStrictEqual(mocks.webSocket.url, undefined) assert.strictEqual(typeof mocks.webSocket.url, 'string') - assert.ok(mocks.webSocket.url.length > 0) + assert.strictEqual(mocks.webSocket.url.length > 0, true) }) }) @@ -783,7 +783,7 @@ await describe('ChargingStation Configuration Management', async () => { const pingInterval = station.getWebSocketPingInterval() // Assert - should return a valid interval value - assert.ok(pingInterval >= 0) + assert.strictEqual(pingInterval >= 0, true) assert.strictEqual(typeof pingInterval, 'number') }) }) diff --git a/tests/charging-station/ChargingStation-Connectors.test.ts b/tests/charging-station/ChargingStation-Connectors.test.ts index d342f95e..402df3eb 100644 --- a/tests/charging-station/ChargingStation-Connectors.test.ts +++ b/tests/charging-station/ChargingStation-Connectors.test.ts @@ -246,7 +246,7 @@ await describe('ChargingStation Connector and EVSE State', async () => { assert.fail('Expected evseStatus to be defined') } assert.notStrictEqual(evseStatus.connectors, undefined) - assert.ok(evseStatus.connectors.size > 0) + assert.strictEqual(evseStatus.connectors.size > 0, true) }) await it('should return undefined for getEvseStatus() with invalid EVSE IDs', () => { diff --git a/tests/charging-station/ChargingStation-Resilience.test.ts b/tests/charging-station/ChargingStation-Resilience.test.ts index b77779fc..40a58ceb 100644 --- a/tests/charging-station/ChargingStation-Resilience.test.ts +++ b/tests/charging-station/ChargingStation-Resilience.test.ts @@ -118,7 +118,7 @@ await describe('ChargingStation Resilience', async () => { mocks.webSocket.simulateMessage('invalid json') // Assert - Station should still be operational (not crashed) - assert.ok(station.connectors.size > 0) + assert.strictEqual(station.connectors.size > 0, true) }) await it('should handle WebSocket error event gracefully', () => { @@ -196,7 +196,7 @@ await describe('ChargingStation Resilience', async () => { mocks.webSocket.simulateClose(1006, 'Server unreachable') // Assert - Station should remain in valid state - assert.ok(station.connectors.size > 0) + assert.strictEqual(station.connectors.size > 0, true) assert.strictEqual(mocks.webSocket.readyState, 3) // CLOSED }) @@ -362,7 +362,7 @@ await describe('ChargingStation Resilience', async () => { // Note: Due to async nature, the message may be sent or buffered depending on timing // This test verifies the message is queued at minimum const stationWithQueue = station as unknown as { messageQueue: string[] } - assert.ok(stationWithQueue.messageQueue.length >= 0) + assert.strictEqual(stationWithQueue.messageQueue.length >= 0, true) }) await it('should flush messages in FIFO order when connection restored', () => { diff --git a/tests/charging-station/ChargingStation-Transactions.test.ts b/tests/charging-station/ChargingStation-Transactions.test.ts index dd528e64..51baa8c9 100644 --- a/tests/charging-station/ChargingStation-Transactions.test.ts +++ b/tests/charging-station/ChargingStation-Transactions.test.ts @@ -502,7 +502,7 @@ await describe('ChargingStation Transaction Management', async () => { // Assert - interval should be different (old cleared, new created) assert.notStrictEqual(secondInterval, undefined) assert.strictEqual(typeof secondInterval, 'object') - assert.ok(firstInterval !== secondInterval) + assert.notStrictEqual(firstInterval, secondInterval) }) }) @@ -569,7 +569,7 @@ await describe('ChargingStation Transaction Management', async () => { // Assert - interval should be different assert.notStrictEqual(secondInterval, undefined) assert.strictEqual(typeof secondInterval, 'object') - assert.ok(firstInterval !== secondInterval) + assert.notStrictEqual(firstInterval, secondInterval) }) }) diff --git a/tests/charging-station/ChargingStation.test.ts b/tests/charging-station/ChargingStation.test.ts index 829eabab..c07cae1e 100644 --- a/tests/charging-station/ChargingStation.test.ts +++ b/tests/charging-station/ChargingStation.test.ts @@ -40,7 +40,7 @@ await describe('ChargingStation', async () => { const station = result.station assert.notStrictEqual(station, undefined) - assert.ok(station.connectors.size > 0) + assert.strictEqual(station.connectors.size > 0, true) assert.notStrictEqual(station.stationInfo, undefined) cleanupChargingStation(station) diff --git a/tests/charging-station/ocpp/auth/helpers/MockFactories.ts b/tests/charging-station/ocpp/auth/helpers/MockFactories.ts index 09917b9a..dd5929b2 100644 --- a/tests/charging-station/ocpp/auth/helpers/MockFactories.ts +++ b/tests/charging-station/ocpp/auth/helpers/MockFactories.ts @@ -126,7 +126,7 @@ export const createMockAuthService = (overrides?: Partial): OCP avgResponseTime: 0, cacheHitRate: 0, failedAuth: 0, - lastUpdated: new Date(), + lastUpdatedDate: new Date(), localUsageRate: 1, remoteSuccessRate: 0, successfulAuth: 0, diff --git a/tests/charging-station/ui-server/UIMCPServer.integration.test.ts b/tests/charging-station/ui-server/UIMCPServer.integration.test.ts index c3e669f5..212f6c25 100644 --- a/tests/charging-station/ui-server/UIMCPServer.integration.test.ts +++ b/tests/charging-station/ui-server/UIMCPServer.integration.test.ts @@ -131,10 +131,15 @@ await describe('UIMCPServer HTTP Integration', async () => { }) afterEach(async () => { + const httpServer = Reflect.get(server, 'httpServer') as Server + if (httpServer.listening) { + await new Promise(resolve => { + httpServer.close(() => { + resolve() + }) + }) + } server.stop() - await new Promise(resolve => { - setTimeout(resolve, 50) - }) standardCleanup() }) diff --git a/tests/exception/BaseError.test.ts b/tests/exception/BaseError.test.ts index d9a5335d..34f86910 100644 --- a/tests/exception/BaseError.test.ts +++ b/tests/exception/BaseError.test.ts @@ -43,8 +43,8 @@ await describe('BaseError', async () => { const beforeNow = Date.now() const baseError = new BaseError() const afterNow = Date.now() - assert.ok(baseError.date.getTime() >= beforeNow - 1000) - assert.ok(baseError.date.getTime() <= afterNow + 1000) + assert.strictEqual(baseError.date.getTime() >= beforeNow - 1000, true) + assert.strictEqual(baseError.date.getTime() <= afterNow + 1000, true) }) await it('should set name to subclass name when extended', () => { diff --git a/tests/utils/ChargingStationConfigurationUtils.test.ts b/tests/utils/ChargingStationConfigurationUtils.test.ts index a6eb5105..b69d2706 100644 --- a/tests/utils/ChargingStationConfigurationUtils.test.ts +++ b/tests/utils/ChargingStationConfigurationUtils.test.ts @@ -236,11 +236,11 @@ await describe('ChargingStationConfigurationUtils', async () => { const result = buildEvsesStatus(station) const evse0Status = result[0][1].connectorsStatus as [number, ConnectorStatus][] - assert.ok(evse0Status.length > 0) + assert.strictEqual(evse0Status.length > 0, true) assert.strictEqual(evse0Status[0][0], 0) const evse1Status = result[1][1].connectorsStatus as [number, ConnectorStatus][] - assert.ok(evse1Status.length > 1) + assert.strictEqual(evse1Status.length > 1, true) assert.strictEqual(evse1Status[0][0], 1) assert.strictEqual(evse1Status[1][0], 2) assert.strictEqual(evse1Status[1][1].availability, AvailabilityType.Inoperative) diff --git a/tests/utils/Utils.test.ts b/tests/utils/Utils.test.ts index 2e5dbae5..056af9f9 100644 --- a/tests/utils/Utils.test.ts +++ b/tests/utils/Utils.test.ts @@ -226,8 +226,8 @@ await describe('Utils', async () => { await it('should generate cryptographically secure random numbers between 0 and 1', () => { const random = secureRandom() assert.ok(typeof random === 'number') - assert.ok(random >= 0) - assert.ok(random < 1) + assert.strictEqual(random >= 0, true) + assert.strictEqual(random < 1, true) }) await it('should round numbers to specified decimal places correctly', () => { @@ -248,8 +248,8 @@ await describe('Utils', async () => { await it('should generate random floats within specified range', () => { let randomFloat = getRandomFloat() assert.ok(typeof randomFloat === 'number') - assert.ok(randomFloat >= 0) - assert.ok(randomFloat <= Number.MAX_VALUE) + assert.strictEqual(randomFloat >= 0, true) + assert.strictEqual(randomFloat <= Number.MAX_VALUE, true) assert.notDeepStrictEqual(randomFloat, getRandomFloat()) assert.throws( () => { @@ -264,8 +264,8 @@ await describe('Utils', async () => { { message: /Invalid interval/ } ) randomFloat = getRandomFloat(0, -Number.MAX_VALUE) - assert.ok(randomFloat >= -Number.MAX_VALUE) - assert.ok(randomFloat <= 0) + assert.strictEqual(randomFloat >= -Number.MAX_VALUE, true) + assert.strictEqual(randomFloat <= 0, true) }) await it('should extract numeric values from timestamped circular buffer', () => { @@ -558,39 +558,39 @@ await describe('Utils', async () => { // retryNumber = 0: 2^0 * 100 = 100ms base const delay0 = exponentialDelay(0) - assert.ok(delay0 >= 100) - assert.ok(delay0 <= 120) // 100 + 20% max jitter + assert.strictEqual(delay0 >= 100, true) + assert.strictEqual(delay0 <= 120, true) // 100 + 20% max jitter // retryNumber = 1: 2^1 * 100 = 200ms base const delay1 = exponentialDelay(1) - assert.ok(delay1 >= 200) - assert.ok(delay1 <= 240) // 200 + 20% max jitter + assert.strictEqual(delay1 >= 200, true) + assert.strictEqual(delay1 <= 240, true) // 200 + 20% max jitter // retryNumber = 2: 2^2 * 100 = 400ms base const delay2 = exponentialDelay(2) - assert.ok(delay2 >= 400) - assert.ok(delay2 <= 480) // 400 + 20% max jitter + assert.strictEqual(delay2 >= 400, true) + assert.strictEqual(delay2 <= 480, true) // 400 + 20% max jitter // retryNumber = 3: 2^3 * 100 = 800ms base const delay3 = exponentialDelay(3) - assert.ok(delay3 >= 800) - assert.ok(delay3 <= 960) // 800 + 20% max jitter + assert.strictEqual(delay3 >= 800, true) + assert.strictEqual(delay3 <= 960, true) // 800 + 20% max jitter }) await it('should calculate exponential delay with custom delay factor', () => { // Custom delayFactor = 50ms const delay0 = exponentialDelay(0, 50) - assert.ok(delay0 >= 50) - assert.ok(delay0 <= 60) // 50 + 20% max jitter + assert.strictEqual(delay0 >= 50, true) + assert.strictEqual(delay0 <= 60, true) // 50 + 20% max jitter const delay1 = exponentialDelay(1, 50) - assert.ok(delay1 >= 100) - assert.ok(delay1 <= 120) + assert.strictEqual(delay1 >= 100, true) + assert.strictEqual(delay1 <= 120, true) // Custom delayFactor = 200ms const delay2 = exponentialDelay(2, 200) - assert.ok(delay2 >= 800) // 2^2 * 200 = 800 - assert.ok(delay2 <= 960) + assert.strictEqual(delay2 >= 800, true) // 2^2 * 200 = 800 + assert.strictEqual(delay2 <= 960, true) }) await it('should follow 2^n exponential growth pattern', () => { @@ -608,8 +608,8 @@ await describe('Utils', async () => { for (let i = 1; i < delays.length; i++) { const ratio = delays[i] / delays[i - 1] // Allow for jitter variance - ratio should be roughly 2x - assert.ok(ratio > 1.5) - assert.ok(ratio < 2.5) + assert.strictEqual(ratio > 1.5, true) + assert.strictEqual(ratio < 2.5, true) } }) @@ -627,7 +627,7 @@ await describe('Utils', async () => { // With jitter, we expect at least some variation // (unlikely to get 10 identical values with secure random) - assert.ok(delays.size > 1) + assert.strictEqual(delays.size > 1, true) }) await it('should keep jitter within 0-20% range of base delay', () => { @@ -642,27 +642,27 @@ await describe('Utils', async () => { const jitter = delay - baseDelay // Jitter should be non-negative and at most 20% of base delay - assert.ok(jitter >= 0) - assert.ok(jitter <= baseDelay * 0.2) + assert.strictEqual(jitter >= 0, true) + assert.strictEqual(jitter <= baseDelay * 0.2, true) } }) await it('should handle edge cases (default retry, large retry, small factor)', () => { // Default retryNumber (0) const defaultRetry = exponentialDelay() - assert.ok(defaultRetry >= 100) // 2^0 * 100 - assert.ok(defaultRetry <= 120) + assert.strictEqual(defaultRetry >= 100, true) // 2^0 * 100 + assert.strictEqual(defaultRetry <= 120, true) // Large retry number (verify no overflow issues) const largeRetry = exponentialDelay(10, 100) // 2^10 * 100 = 102400ms base - assert.ok(largeRetry >= 102400) - assert.ok(largeRetry <= 122880) // 102400 + 20% + assert.strictEqual(largeRetry >= 102400, true) + assert.strictEqual(largeRetry <= 122880, true) // 102400 + 20% // Very small delay factor const smallFactor = exponentialDelay(2, 1) - assert.ok(smallFactor >= 4) // 2^2 * 1 - assert.ok(smallFactor < 5) // 4 + 20% + assert.strictEqual(smallFactor >= 4, true) // 2^2 * 1 + assert.strictEqual(smallFactor < 5, true) // 4 + 20% }) await it('should calculate appropriate delays for WebSocket reconnection scenarios', () => { @@ -671,26 +671,26 @@ await describe('Utils', async () => { // First reconnect attempt (retry 1) const firstDelay = exponentialDelay(1, delayFactor) - assert.ok(firstDelay >= 200) // 2^1 * 100 - assert.ok(firstDelay <= 240) + assert.strictEqual(firstDelay >= 200, true) // 2^1 * 100 + assert.strictEqual(firstDelay <= 240, true) // After several failures (retry 5) const fifthDelay = exponentialDelay(5, delayFactor) - assert.ok(fifthDelay >= 3200) // 2^5 * 100 - assert.ok(fifthDelay <= 3840) + assert.strictEqual(fifthDelay >= 3200, true) // 2^5 * 100 + assert.strictEqual(fifthDelay <= 3840, true) // Maximum practical retry (retry 10 = ~102 seconds) const maxDelay = exponentialDelay(10, delayFactor) - assert.ok(maxDelay >= 102400) // ~102 seconds - assert.ok(maxDelay <= 122880) + assert.strictEqual(maxDelay >= 102400, true) // ~102 seconds + assert.strictEqual(maxDelay <= 122880, true) }) await it('should return timestamped log prefix with optional string', () => { const result = logPrefix() assert.strictEqual(typeof result, 'string') - assert.ok(result.length > 0) + assert.strictEqual(result.length > 0, true) const withPrefix = logPrefix(' Test |') - assert.ok(withPrefix.includes(' Test |')) + assert.strictEqual(withPrefix.includes(' Test |'), true) }) await it('should deep merge objects with source overriding target', () => { @@ -754,17 +754,17 @@ await describe('Utils', async () => { await it('should generate random float rounded to specified scale', () => { const result = getRandomFloatRounded(10, 0, 2) - assert.ok(result >= 0) - assert.ok(result <= 10) + assert.strictEqual(result >= 0, true) + assert.strictEqual(result <= 10, true) // Check rounding to 2 decimal places const decimalStr = result.toString() if (decimalStr.includes('.')) { - assert.ok(decimalStr.split('.')[1].length <= 2) + assert.strictEqual(decimalStr.split('.')[1].length <= 2, true) } // Default scale const defaultScale = getRandomFloatRounded(10, 0) - assert.ok(defaultScale >= 0) - assert.ok(defaultScale <= 10) + assert.strictEqual(defaultScale >= 0, true) + assert.strictEqual(defaultScale <= 10, true) }) await it('should generate fluctuated random float within percentage range', () => { @@ -772,8 +772,8 @@ await describe('Utils', async () => { assert.strictEqual(getRandomFloatFluctuatedRounded(100, 0), 100) // 10% fluctuation: 100 ± 10 const result = getRandomFloatFluctuatedRounded(100, 10) - assert.ok(result >= 90) - assert.ok(result <= 110) + assert.strictEqual(result >= 90, true) + assert.strictEqual(result <= 110, true) // Invalid fluctuation percent assert.throws(() => { getRandomFloatFluctuatedRounded(100, -1) @@ -783,8 +783,8 @@ await describe('Utils', async () => { }, RangeError) // Negative static value with fluctuation const negResult = getRandomFloatFluctuatedRounded(-100, 10) - assert.ok(negResult >= -110) - assert.ok(negResult <= -90) + assert.strictEqual(negResult >= -110, true) + assert.strictEqual(negResult <= -90, true) }) await it('should detect Cloud Foundry environment from VCAP_APPLICATION', () => { diff --git a/tests/worker/WorkerUtils.test.ts b/tests/worker/WorkerUtils.test.ts index 799b39e4..4a6da254 100644 --- a/tests/worker/WorkerUtils.test.ts +++ b/tests/worker/WorkerUtils.test.ts @@ -112,24 +112,24 @@ await describe('WorkerUtils', async () => { results.push(randomized) // Each result should be within ±20% of base delay - assert.ok(randomized >= baseDelay - tolerance) - assert.ok(randomized <= baseDelay + tolerance) + assert.strictEqual(randomized >= baseDelay - tolerance, true) + assert.strictEqual(randomized <= baseDelay + tolerance, true) } // Verify we get some variation (not all values identical) const uniqueValues = new Set(results) - assert.ok(uniqueValues.size > 1) + assert.strictEqual(uniqueValues.size > 1, true) // Test with zero delay const zeroResult = randomizeDelay(0) - assert.ok(zeroResult >= 0) - assert.ok(zeroResult <= 0) + assert.strictEqual(zeroResult >= 0, true) + assert.strictEqual(zeroResult <= 0, true) // Test with negative delay (edge case) const negativeDelay = -100 const negativeResult = randomizeDelay(negativeDelay) const negativeTolerance = Math.abs(negativeDelay) * 0.2 - assert.ok(negativeResult >= negativeDelay - negativeTolerance) - assert.ok(negativeResult <= negativeDelay + negativeTolerance) + assert.strictEqual(negativeResult >= negativeDelay - negativeTolerance, true) + assert.strictEqual(negativeResult <= negativeDelay + negativeTolerance, true) }) })