Files
tuono/packages/tuono-fs-router-vite-plugin/tests/generator.spec.ts
T

32 lines
978 B
TypeScript
Raw Normal View History

2024-07-08 21:39:00 +02:00
import fs from 'fs/promises'
2024-12-01 10:07:35 +01:00
2024-07-08 21:39:00 +02:00
import { describe, it, expect } from 'vitest'
2024-12-01 10:07:35 +01:00
2024-07-08 21:39:00 +02:00
import { routeGenerator } from '../src/generator'
describe('generator works', async () => {
const folderNames = await fs.readdir(`${process.cwd()}/tests/generator`)
2024-07-08 21:39:00 +02:00
it.each(folderNames)(
2024-07-08 21:39:00 +02:00
'should wire-up the routes for a "%s" tree',
async (folderName) => {
const testDirPath = `${process.cwd()}/tests/generator/${folderName}`
2024-07-08 21:39:00 +02:00
await routeGenerator({
folderName: `${testDirPath}/routes`,
generatedRouteTree: `${testDirPath}/routeTree.gen.ts`,
2024-07-08 21:39:00 +02:00
})
const generatedFilePath = `${testDirPath}/routeTree.gen.ts`
const expectedFilePath = `${testDirPath}/routeTree.expected.ts`
const generatedFileContent = await fs.readFile(generatedFilePath, 'utf-8')
2024-07-08 21:39:00 +02:00
await expect(generatedFileContent).toMatchFileSnapshot(
expectedFilePath,
`${generatedFilePath} content should be equal to ${expectedFilePath}`,
)
2024-07-08 21:39:00 +02:00
},
)
})