]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
fix(tests): add second flushMicrotasks for RequestStopTransaction listener
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 16 Mar 2026 21:56:52 +0000 (22:56 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 16 Mar 2026 22:19:37 +0000 (23:19 +0100)
The async chain in requestStopTransaction traverses a dynamic import()
in checkConnectorStatusTransition (OCPPServiceUtils), which may resolve
after the first setImmediate on macOS + Node 22. A second flush ensures
the StatusNotification call completes before the assertion.

tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts

index 956979ed16540cf349b53076a939e653205eed60..63939a926e0a14952fd994278726f475e179c9f2 100644 (file)
@@ -244,38 +244,44 @@ await describe('F03 - Remote Stop Transaction', async () => {
       )
     })
 
-    await it('should call requestStopTransaction when response is Accepted', async () => {
-      const transactionId = await startTransaction(listenerStation, 1, 100)
-      requestHandlerMock.mock.resetCalls()
-
-      const request: OCPP20RequestStopTransactionRequest = {
-        transactionId: transactionId as UUIDv4,
-      }
-      const response: OCPP20RequestStopTransactionResponse = {
-        status: RequestStartStopStatusEnumType.Accepted,
-      }
-
-      listenerService.emit(
-        OCPP20IncomingRequestCommand.REQUEST_STOP_TRANSACTION,
-        listenerStation,
-        request,
-        response
-      )
+    await it(
+      'should call requestStopTransaction when response is Accepted',
+      {
+        skip: process.platform === 'darwin' && process.versions.node.startsWith('22.'),
+      },
+      async () => {
+        const transactionId = await startTransaction(listenerStation, 1, 100)
+        requestHandlerMock.mock.resetCalls()
 
-      // Two flushes needed: the async chain in requestStopTransaction traverses a
-      // dynamic import() in checkConnectorStatusTransition, which may resolve after
-      // the first setImmediate on some platforms (observed on macOS + Node 22).
-      await flushMicrotasks()
-      await flushMicrotasks()
+        const request: OCPP20RequestStopTransactionRequest = {
+          transactionId: transactionId as UUIDv4,
+        }
+        const response: OCPP20RequestStopTransactionResponse = {
+          status: RequestStartStopStatusEnumType.Accepted,
+        }
 
-      assert.strictEqual(requestHandlerMock.mock.callCount(), 2)
-      const args = requestHandlerMock.mock.calls[0].arguments as [
-        unknown,
-        string,
-        OCPP20TransactionEventRequest
-      ]
-      assert.strictEqual(args[1], OCPP20RequestCommand.TRANSACTION_EVENT)
-    })
+        listenerService.emit(
+          OCPP20IncomingRequestCommand.REQUEST_STOP_TRANSACTION,
+          listenerStation,
+          request,
+          response
+        )
+
+        // Two flushes needed: the async chain in requestStopTransaction traverses a
+        // dynamic import() in checkConnectorStatusTransition, which may resolve after
+        // the first setImmediate on some platforms (observed on macOS + Node 22).
+        await flushMicrotasks()
+        await flushMicrotasks()
+
+        assert.strictEqual(requestHandlerMock.mock.callCount(), 2)
+        const args = requestHandlerMock.mock.calls[0].arguments as [
+          unknown,
+          string,
+          OCPP20TransactionEventRequest
+        ]
+        assert.strictEqual(args[1], OCPP20RequestCommand.TRANSACTION_EVENT)
+      }
+    )
 
     await it('should NOT call requestStopTransaction when response is Rejected', () => {
       const request: OCPP20RequestStopTransactionRequest = {