]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
docs: update TEST_STYLE_GUIDE with standardCleanup and describe naming conventions
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 28 Feb 2026 22:22:22 +0000 (23:22 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 28 Feb 2026 22:22:22 +0000 (23:22 +0100)
tests/TEST_STYLE_GUIDE.md

index cb7be8521c0ea5fde864a6099897d3a99e8af4c9..8dbfb6d94c8925df9a70ffad3bbd3442913d5db6 100644 (file)
@@ -42,20 +42,28 @@ it('starts successfully', () => {}) // No 'should'
 ### Files & Suites
 
 - **Files**: Use descriptive names matching the module under test: `ModuleName.test.ts`
-- **Test suites**: Use `describe()` with clear, specific descriptions
-- **OCPP tests**: Use requirement codes: `describe('B11 & B12 - Reset', () => {})`
+- **Test suites**: Use `describe()` with the module name only - NO "test suite" suffix
+- **OCPP tests**: Use requirement codes: `describe('B11 - Reset', () => {})`
 - **Auth tests**: Reference spec sections: `describe('G03.FR.01 - AuthCache Conformance', () => {})`
 - **Variables**: Use camelCase for variables, functions, and test helpers
 - **Constants**: Use SCREAMING_SNAKE_CASE for test constants
 
-**Example:**
+**describe() Naming:**
+
+✅ **Good:**
 
 ```typescript
-describe('ChargingStation lifecycle', () => {
-  it('should start successfully with valid configuration', async () => {
-    // test implementation
-  })
-})
+describe('ChargingStation', () => {}) // Module name only
+describe('B11 - Reset', () => {}) // OCPP spec code + description
+describe('Utils', () => {}) // Simple and clear
+```
+
+❌ **Bad:**
+
+```typescript
+describe('ChargingStation test suite', () => {}) // Don't add "test suite"
+describe('B11 & B12 - Reset', () => {}) // Split into separate describes
+describe('WorkerUtils test suite', () => {}) // Redundant suffix
 ```
 
 ## Test Structure (AAA Pattern)
@@ -363,13 +371,22 @@ await describe('My Test Suite', async () => {
 **ALWAYS include `afterEach()` cleanup to prevent test pollution:**
 
 ```typescript
+import { standardCleanup } from '../helpers/TestLifecycleHelpers.js'
+
 afterEach(() => {
+  standardCleanup()
   mock.restoreAll()
-  mock.timers.reset()
-  // Clean up any resources created in tests
 })
 ```
 
+### standardCleanup() (MANDATORY)
+
+The `standardCleanup()` function from `tests/helpers/TestLifecycleHelpers.ts` MUST be called in every test file's `afterEach()` hook. It:
+
+- Clears shared caches (MockIdTagsCache, MockSharedLRUCache)
+- Resets any singleton state
+- Ensures test isolation
+
 ### What to Clean Up
 
 - Mock timers: `mock.timers.reset()`