this repo has no description
at main 55 lines 2.0 kB view raw
1import assert from 'node:assert/strict' 2import { access, mkdir, rm, writeFile } from 'node:fs/promises' 3import { join } from 'node:path' 4import { describe, test } from 'node:test' 5import { extractZip } from '../src/extract.js' 6 7describe('Enhanced Zip Extraction Fallbacks', () => { 8 test('handles when all zip tools fail', async () => { 9 const testDir = './test-all-zip-tools-fail' 10 const archivePath = join(testDir, 'test.zip') 11 12 await mkdir(testDir, { recursive: true }) 13 await writeFile(archivePath, Buffer.from('fake zip content')) 14 15 try { 16 await assert.rejects( 17 async () => await extractZip(archivePath, testDir), 18 /Failed to extract zip file. Please ensure unzip, PowerShell, or 7z is available/, 19 ) 20 } finally { 21 await rm(testDir, { recursive: true }).catch(() => {}) 22 } 23 }) 24 25 test('handles zip file that does not exist', async () => { 26 const nonExistentPath = './nonexistent/file.zip' 27 const outputDir = './test-zip-nonexistent' 28 29 await assert.rejects(async () => await extractZip(nonExistentPath, outputDir), /Failed to extract zip file/) 30 }) 31 32 test('creates output directory if it does not exist', async () => { 33 const testDir = './test-zip-create-output' 34 const archivePath = join(testDir, 'test.zip') 35 const outputDir = join(testDir, 'nested/output') 36 37 await mkdir(testDir, { recursive: true }) 38 await writeFile(archivePath, Buffer.from('fake zip content')) 39 40 try { 41 // Will fail during extraction but should create directory first 42 await assert.rejects( 43 async () => await extractZip(archivePath, outputDir), 44 // Expected to fail with tool errors 45 ) 46 47 // Verify output directory was created even though extraction failed 48 await access(outputDir) // Should not throw 49 50 assert.ok(true, 'Created output directory before attempting extraction') 51 } finally { 52 await rm(testDir, { recursive: true }).catch(() => {}) 53 } 54 }) 55})