]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
fix: prevent tests from polluting production log files
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 18 Mar 2026 20:33:51 +0000 (21:33 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 18 Mar 2026 20:33:51 +0000 (21:33 +0100)
Set NODE_ENV=test via cross-env in all three test scripts (test,
test:debug, test:coverage). Logger checks NODE_ENV and sets silent
mode, preventing file writes to logs/combined.log and logs/error.log
during test runs.

package.json
src/utils/Logger.ts

index 354cce651904c40f50735854b0011790e810cb5d..68acd375a8614690bb0363b67f9290e902609ebd 100644 (file)
@@ -68,9 +68,9 @@
     "lint": "cross-env TIMING=1 eslint --cache src tests scripts ./*.js ./*.ts",
     "lint:fix": "cross-env TIMING=1 eslint --cache --fix src tests scripts ./*.js ./*.ts",
     "format": "prettier --cache --write .; eslint --cache --fix src tests scripts ./*.js ./*.ts",
-    "test": "node --import tsx --test --test-force-exit 'tests/**/*.test.ts'",
-    "test:debug": "node --import tsx --test --inspect 'tests/**/*.test.ts'",
-    "test:coverage": "mkdir -p coverage && node --import tsx --test --test-force-exit --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info 'tests/**/*.test.ts'",
+    "test": "cross-env NODE_ENV=test node --import tsx --test --test-force-exit 'tests/**/*.test.ts'",
+    "test:debug": "cross-env NODE_ENV=test node --import tsx --test --inspect 'tests/**/*.test.ts'",
+    "test:coverage": "mkdir -p coverage && cross-env NODE_ENV=test node --import tsx --test --test-force-exit --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info 'tests/**/*.test.ts'",
     "clinic:clean": "clinic clean",
     "sea": "pnpm exec rimraf ./dist/evse-simulator ./dist/evse-simulator.blob && node --experimental-sea-config sea-config.json && pnpm dlx ncp $(volta which node || n which lts || nvm which node || command -v node) ./dist/evse-simulator && pnpm dlx postject ./dist/evse-simulator NODE_SEA_BLOB ./dist/evse-simulator.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 && pnpm exec rimraf ./dist/evse-simulator.blob"
   },
index fd282638d7282eb8f32a025231f4e94c06a6352d..96c94a62b2e48f48f6bb6a65ca1f3d18882abe52 100644 (file)
@@ -78,7 +78,10 @@ const getLoggerInstance = (): WinstonLogger => {
   loggerInstance = createLogger({
     format: logFormat,
     level: logConfiguration.level,
-    silent: logConfiguration.enabled === false || logTransports.length === 0,
+    silent:
+      logConfiguration.enabled === false ||
+      logTransports.length === 0 ||
+      process.env.NODE_ENV === 'test',
     transports: logTransports,
   })
   //