From e5ec78ae1e9a8cb74e1e32e30b5aa6392a92d9c4 Mon Sep 17 00:00:00 2001 From: chk <79915315+ChKendel@users.noreply.github.com> Date: Fri, 12 Jun 2026 18:33:37 +0200 Subject: [PATCH] small things --- test/RobotConfigService.test.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/RobotConfigService.test.js b/test/RobotConfigService.test.js index 6090faf..7e7452d 100644 --- a/test/RobotConfigService.test.js +++ b/test/RobotConfigService.test.js @@ -69,6 +69,37 @@ function cleanupTestFiles() { } } +// robot.json gehört zur Betriebskonfiguration und darf durch Tests NICHT dauerhaft +// gelöscht werden. Wir sichern den Inhalt vor der Suite und stellen ihn danach exakt +// wieder her — inklusive aller Snapshot-Dateien, die schon vorher da waren. +let _savedRobotJson = null; // null = Datei existierte nicht +let _savedSnapshotFiles = {}; // filename → content (nur Dateien, die VOR den Tests da waren) + +beforeAll(() => { + fs.mkdirSync(DATA_DIR, { recursive: true }); + // robot.json sichern + try { _savedRobotJson = fs.readFileSync(ROBOT_JSON, 'utf8'); } catch { _savedRobotJson = null; } + // Snapshot-Dateien sichern (robot_YYYYMMDD_HHmmss.json) + for (const f of fs.readdirSync(DATA_DIR)) { + if (/^robot_\d{8}_\d{6}\.json$/.test(f)) { + _savedSnapshotFiles[f] = fs.readFileSync(path.join(DATA_DIR, f), 'utf8'); + } + } +}); + +afterAll(() => { + // Testdateien bereinigen + cleanupTestFiles(); + // robot.json wiederherstellen + if (_savedRobotJson !== null) { + fs.writeFileSync(ROBOT_JSON, _savedRobotJson, 'utf8'); + } + // Vor-Test-Snapshots wiederherstellen + for (const [f, content] of Object.entries(_savedSnapshotFiles)) { + fs.writeFileSync(path.join(DATA_DIR, f), content, 'utf8'); + } +}); + beforeEach(() => { fs.mkdirSync(DATA_DIR, { recursive: true }); cleanupTestFiles();