refactor: packages folder

This commit is contained in:
Valerio Ageno
2024-05-02 19:01:49 +02:00
parent da111ac56e
commit 6dc33f8e3e
39 changed files with 8 additions and 556 deletions
+33
View File
@@ -0,0 +1,33 @@
import { readFile, readdir } from 'fs/promises'
import path from 'path'
import { expect, test } from 'vitest'
import { makeCompile, splitFile } from '../src/compiler'
import { SPLIT_PREFIX } from '../src/constants'
async function splitTestFile(opts: { file: string }): Promise<void> {
const code = (
await readFile(path.resolve(__dirname, `./test-files/${opts.file}`))
).toString()
const filename = opts.file.replace(__dirname, '')
const result = await splitFile({
code,
compile: makeCompile({
root: './test-files',
}),
filename: `${filename}?${SPLIT_PREFIX}`,
})
await expect(result.code).toMatchFileSnapshot(
`./snapshots/${filename.replace('.tsx', '')}?split.tsx`,
)
}
test('it compiles and splits', async (): Promise<void> => {
// get the list of files from the /test-files directory
const files = await readdir(path.resolve(__dirname, './test-files'))
for (const file of files) {
await splitTestFile({ file })
}
})
@@ -0,0 +1,3 @@
export const ImportedRoute = (): JSX.Element => {
return <h1>Imported route</h1>
}
@@ -0,0 +1,3 @@
export default function Route(): JSX.Element {
return <h1>Test route</h1>;
}
@@ -0,0 +1,4 @@
function PostsRoute() {
return <h1>Post route</h1>;
}
export default PostsRoute;
@@ -0,0 +1,2 @@
import { ImportedRoute } from '../shared/imported';
export default ImportedRoute;
@@ -0,0 +1,5 @@
import * as React from 'react'
export default function Route(): JSX.Element {
return <h1>Test route</h1>
}
@@ -0,0 +1,7 @@
import * as React from 'react'
function PostsRoute() {
return <h1>Post route</h1>
}
export default PostsRoute
@@ -0,0 +1,4 @@
import * as React from 'react'
import { ImportedRoute } from '../shared/imported'
export default ImportedRoute