mirror of
https://github.com/kremalicious/blog.git
synced 2024-11-22 18:00:06 +01:00
Matthias Kretschmann
c123dd9d68
* astro-redirect-from prototype * move out plugin * switch to astro-redirect-from * fixes * new post: astro-redirect-from * fix dependency * test fixes * downgrade and lock astro * until fix for https://github.com/withastro/astro/issues/8649 has been released * mention debug json file * fix e2e test
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { test, expect, vi } from 'vitest'
|
|
import fs from 'node:fs/promises'
|
|
import path from 'node:path'
|
|
import { glob } from 'glob'
|
|
import { copyZipFiles } from './move-downloads'
|
|
import { fileURLToPath } from 'node:url'
|
|
import chalk from 'chalk'
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
|
|
test('copyZipFiles should copy zip files', async () => {
|
|
// Create temporary directories and files
|
|
const sourceDir = path.join(__dirname, 'tmp_source')
|
|
const destDir = path.join(__dirname, 'tmp_dest')
|
|
await fs.mkdir(sourceDir, { recursive: true })
|
|
await fs.mkdir(destDir, { recursive: true })
|
|
await fs.writeFile(path.join(sourceDir, 'file1.zip'), 'content1')
|
|
await fs.writeFile(path.join(sourceDir, 'file2.zip'), 'content2')
|
|
|
|
const globMock = vi.spyOn(glob, 'sync')
|
|
globMock.mockReturnValue(['file1.zip', 'file2.zip'])
|
|
|
|
const mockOra = {
|
|
start: vi.fn(),
|
|
succeed: vi.fn(),
|
|
fail: vi.fn()
|
|
}
|
|
|
|
await copyZipFiles(sourceDir, destDir, mockOra as any)
|
|
|
|
const file1 = await fs.readFile(path.join(destDir, 'file1.zip'), 'utf-8')
|
|
const file2 = await fs.readFile(path.join(destDir, 'file2.zip'), 'utf-8')
|
|
expect(file1).toBe('content1')
|
|
expect(file2).toBe('content2')
|
|
|
|
expect(mockOra.succeed).toHaveBeenCalledWith(
|
|
`${chalk.bold('[move-downloads]')} Copied 2 .zip files to ${destDir}`
|
|
)
|
|
|
|
// Cleanup
|
|
await fs.rm(sourceDir, { recursive: true, force: true })
|
|
await fs.rm(destDir, { recursive: true, force: true })
|
|
})
|