From fa16dcd8014943387f23e06db56f9a5a8bc418c4 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Mon, 3 Feb 2025 10:41:43 -0500 Subject: [PATCH] feat: add logging around fixture downloads --- .../__test__/generic-modification.spec.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts b/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts index e2b015aec..8244a4cbd 100644 --- a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts +++ b/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts @@ -13,6 +13,7 @@ import SSOFileModification from '@app/unraid-api/unraid-file-modifier/modificati interface ModificationTestCase { ModificationClass: new (...args: ConstructorParameters) => FileModification; fileUrl: string; + fileName: string; } const testCases: ModificationTestCase[] = [ @@ -20,16 +21,19 @@ const testCases: ModificationTestCase[] = [ ModificationClass: DefaultPageLayoutModification, fileUrl: 'https://github.com/unraid/webgui/raw/refs/heads/master/emhttp/plugins/dynamix/include/DefaultPageLayout.php', + fileName: 'DefaultPageLayout.php', }, { ModificationClass: NotificationsPageModification, fileUrl: 'https://github.com/unraid/webgui/raw/refs/heads/master/emhttp/plugins/dynamix/Notifications.page', + fileName: 'Notifications.page', }, { fileUrl: 'https://github.com/unraid/webgui/raw/refs/heads/master/emhttp/plugins/dynamix/include/.login.php', ModificationClass: SSOFileModification, + fileName: '.login.php', }, ]; @@ -40,9 +44,16 @@ async function testModification(testCase: ModificationTestCase) { const path = resolve(__dirname, `../__fixtures__/downloaded/${fileName}`); let originalContent = ''; if (!existsSync(path)) { - originalContent = await fetch(testCase.fileUrl).then((response) => response.text()); - await writeFile(path, originalContent); + try { + console.log('Downloading file', testCase.fileUrl); + originalContent = await fetch(testCase.fileUrl).then((response) => response.text()); + await writeFile(path, originalContent); + } catch (error) { + console.error('Failed to download file', error); + throw new Error('Failed to download file for testing'); + } } else { + console.log('Using existing fixture file', path); originalContent = await readFile(path, 'utf-8'); } @@ -72,7 +83,7 @@ async function testModification(testCase: ModificationTestCase) { } describe('File modifications', () => { - test.each(testCases)(`$fileUrl modifier correctly applies to fresh install`, async (testCase) => { + test.each(testCases)(`$fileName modifier correctly applies to fresh install`, async (testCase) => { await testModification(testCase); }); });