test: harmonize event listener test pattern across OCPP command test files (#1730)
* test: harmonize event listener test pattern across OCPP command test files
Add event listener test sections to 7 OCPP incoming request command test
files (4 OCPP 1.6, 3 OCPP 2.0) following the reference pattern from
RequestStopTransaction, TriggerMessage, UpdateFirmware, and GetLog tests.
Each listener section contains: registration test, accepted-fires test,
rejected-not-fires test, and error-graceful test.
Also restructures CustomerInformation to wrap existing listener tests in a
properly named describe block, and adds createOCPP16ListenerStation helper
to OCPP16TestUtils.ts.
- Extract createOCPP20ListenerStation to OCPP20TestUtils.ts, removing
duplication between RequestStart and RequestStop test files
- Replace inline import('node:test').mock.fn with top-level mock import
in RemoteStartTransaction tests
- Remove redundant mock.reset() from 3 listener afterEach blocks —
standardCleanup() already calls mock.restoreAll()
- Replace all await Promise.resolve() with flushMicrotasks() across 5
OCPP 2.0 test files for more robust async side-effect flushing
* fix(tests): replace remaining await Promise.resolve() with flushMicrotasks()
8 occurrences in 5 files (3 OCPP16, 2 OCPP20) missed in the initial
review fix. Now all listener tests use flushMicrotasks() consistently.
- Fix import paths in 7 OCPP 2.0 test files: ../../../../tests/helpers/
→ ../../../helpers/ (correct relative path, consistent with 35 sibling
files in the same directory)
- Add eventType assertion in RequestStartTransaction listener test to
verify TransactionEvent(Started) per E02.FR.01
- Add flushMicrotasks() to RequestStopTransaction listener test for
consistent emit→flush→assert pattern
* refactor(tests): move mock.method to beforeEach and parameterize trigger tests
- Move duplicated mock.method calls into listener beforeEach blocks
in 5 files (UpdateFirmware, GetLog, GetBaseReport, CustomerInfo,
Firmware). Rejection tests override inline. Net -147 lines.
- Parameterize OCPP16 + OCPP20 TriggerMessage trigger-fires tests
using data-driven triggerCases arrays (already done in prior commit,
this commit includes the Firmware mock cleanup).
* style(tests): remove inconsistent separator comment in RemoteStopUnlock
The listener section had a '// ───' separator not used in any of
the other 10 test files. The await describe block is sufficient.
* docs(tests): add summary line to startTransaction JSDoc
* docs(tests): add event listener testing section to TEST_STYLE_GUIDE
Add §11 documenting the established listener test pattern: emit()
direct, flushMicrotasks(), listenerCount first, accepted/rejected/error
triad, mock.method in beforeEach. Add listener station factories to
§9 mock factories table and flushMicrotasks to §10 utility table.
* docs(tests): fix incorrect mock API in §11 code example
Replace Jest-style mockImplementation() with Node.js test runner
mock.method() override pattern matching actual test code.
* fix(tests): align all 112 test files with TEST_STYLE_GUIDE
- Move @file JSDoc headers above first import in 3 files (GetVariables,
MessageChannelUtils, Utils)
- Replace await Promise.resolve() with flushMicrotasks() in
AutomaticTransactionGenerator
- Replace 6 setTimeout(resolve, 50) hacks with flushMicrotasks() in
ChargingStationWorkerBroadcastChannel
- Document spec traceability prefix exception (G03.FR.xx, G04.INT.xx)
in TEST_STYLE_GUIDE §1 naming conventions
* docs(tests): align TEST_STYLE_GUIDE with actual test infrastructure
- Fix createMockChargingStation location (ChargingStationTestUtils →
helpers/StationHelpers)
- Add 7 widely-used factories to §9 table (10+ usages each)
- Remove unused expectAcceptedAuthorization from §9 auth table
- All locations verified against actual exports
- Core Principles: clarify assert.ok is for boolean/existence only
- §5: add missing quotes around glob in test script (matches package.json)
- §10: restore setupConnectorWithTransaction/clearConnectorTransaction
(27 usages across test suite — should not have been removed)