Skip to content

Commit

Permalink
chore: fix snapshots folder creation
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Feb 21, 2024
1 parent 36b7d8e commit e4395ac
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/image-shrink/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig, type PluginOption } from 'vite'
import url from 'url'
import path from 'path'
import getRawBody from 'raw-body'
import { writeFile } from 'fs/promises'
import { writeFile, mkdir, access } from 'fs/promises'

const __dirname = url.fileURLToPath(new URL('.', import.meta.url))

Expand All @@ -16,10 +16,13 @@ const uploadPlugin = (): PluginOption => ({
filename: string
}
const body = await getRawBody(req)
await writeFile(
path.resolve(__dirname, './src/test/snapshots/', filename),
body
)
const snapshotsFolder = path.join(__dirname, './src/test/snapshots/')
try {
await access(snapshotsFolder)
} catch (err) {
await mkdir(snapshotsFolder)
}
await writeFile(path.resolve(snapshotsFolder, filename), body)
res.statusCode = 200
res.end('ok')
return
Expand Down

0 comments on commit e4395ac

Please sign in to comment.