diff --git a/packages/image-shrink/vitest.config.ts b/packages/image-shrink/vitest.config.ts index 13aa2748..2f736be8 100644 --- a/packages/image-shrink/vitest.config.ts +++ b/packages/image-shrink/vitest.config.ts @@ -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)) @@ -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