import { readFile, readdir } from 'node:fs/promises' import path from 'node:path' import { describe, expect, test } from 'vitest' import { compileStartOutput } from '../../src/compilers' async function getFilenames() { return await readdir(path.resolve(import.meta.dirname, './test-files')) } describe('createMiddleware compiles correctly', async () => { const filenames = await getFilenames() describe.each(filenames)('should handle "%s"', async (filename) => { const file = await readFile( path.resolve(import.meta.dirname, `./test-files/${filename}`), ) const code = file.toString() test.each(['client', 'server'] as const)( `should compile for ${filename} %s`, async (env) => { const compiledResult = compileStartOutput({ env, code, root: './test-files', filename, dce: false, }) await expect(compiledResult.code).toMatchFileSnapshot( `./snapshots/${env}/${filename}`, ) }, ) }) })