From 1cbc3241a1e9091840fb4c7f22cf28493c60a468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 19 May 2026 23:19:07 +0200 Subject: [PATCH] fix(backend-test-utils): prevent suite crash when no databases are available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When eachSupportedId() returned an empty array, describe.each([]) would throw and crash the entire test suite. Return a placeholder ID instead, so individual tests fail with a clear error rather than preventing the entire suite from running. Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Fredrik Adelöw --- packages/backend-test-utils/src/cache/TestCaches.ts | 3 +++ packages/backend-test-utils/src/database/TestDatabases.ts | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/packages/backend-test-utils/src/cache/TestCaches.ts b/packages/backend-test-utils/src/cache/TestCaches.ts index d4553697bf..27c07daa32 100644 --- a/packages/backend-test-utils/src/cache/TestCaches.ts +++ b/packages/backend-test-utils/src/cache/TestCaches.ts @@ -108,6 +108,9 @@ export class TestCaches { } eachSupportedId(): [TestCacheId][] { + if (this.supportedIds.length === 0) { + return [['MISSING' as TestCacheId]]; + } return this.supportedIds.map(id => [id]); } diff --git a/packages/backend-test-utils/src/database/TestDatabases.ts b/packages/backend-test-utils/src/database/TestDatabases.ts index 8baac04193..46d966b6ee 100644 --- a/packages/backend-test-utils/src/database/TestDatabases.ts +++ b/packages/backend-test-utils/src/database/TestDatabases.ts @@ -124,6 +124,13 @@ export class TestDatabases { } eachSupportedId(): [TestDatabaseId][] { + if (this.supportedIds.length === 0) { + // Return a placeholder so that describe.each/it.each does not throw + // when no databases are available. The init() call will throw for + // the unknown ID, causing the test to be reported as failed rather + // than crashing the entire suite. + return [['MISSING' as TestDatabaseId]]; + } return this.supportedIds.map(id => [id]); }