import { readFile, readdir } from 'node:fs/promises' import path from 'node:path' import { describe, expect, test } from 'vitest' import { compileStartOutputFactory } from '../../src/start-compiler-plugin/compilers' const compileStartOutput = compileStartOutputFactory('react') 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, filename, dce: true, }) await expect(compiledResult.code).toMatchFileSnapshot( `./snapshots/${env}/${filename}`, ) }, ) }) })