Skip to content

Commit b9f88c5

Browse files
authored
test(router-plugin): split addHmr snapshot testing (#4612)
1 parent 9ebcb2a commit b9f88c5

File tree

663 files changed

+501
-4793
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

663 files changed

+501
-4793
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { readFile, readdir } from 'node:fs/promises'
2+
import path from 'node:path'
3+
import { describe, expect, it } from 'vitest'
4+
5+
import { compileCodeSplitReferenceRoute } from '../src/core/code-splitter/compilers'
6+
import { defaultCodeSplitGroupings } from '../src/core/constants'
7+
import { frameworks } from './constants'
8+
9+
function getFrameworkDir(framework: string) {
10+
const files = path.resolve(__dirname, `./add-hmr/test-files/${framework}`)
11+
const snapshots = path.resolve(__dirname, `./add-hmr/snapshots/${framework}`)
12+
return { files, snapshots }
13+
}
14+
15+
describe('add-hmr works', () => {
16+
describe.each(frameworks)('FRAMEWORK=%s', async (framework) => {
17+
const dirs = getFrameworkDir(framework)
18+
const filenames = await readdir(dirs.files)
19+
20+
it.each(filenames)(
21+
`should add hmr in "reference" for "%s"`,
22+
async (filename) => {
23+
const file = await readFile(path.join(dirs.files, filename))
24+
const code = file.toString()
25+
26+
const compileResult = compileCodeSplitReferenceRoute({
27+
code,
28+
filename,
29+
id: filename,
30+
addHmr: true,
31+
codeSplitGroupings: defaultCodeSplitGroupings,
32+
targetFramework: framework,
33+
})
34+
35+
await expect(compileResult.code).toMatchFileSnapshot(
36+
path.join(dirs.snapshots, filename.replace('.tsx', '@true.tsx')),
37+
)
38+
},
39+
)
40+
41+
it.each(filenames)(
42+
`should NOT add hmr in "reference" for "%s"`,
43+
async (filename) => {
44+
const file = await readFile(path.join(dirs.files, filename))
45+
const code = file.toString()
46+
47+
const compileResult = compileCodeSplitReferenceRoute({
48+
code,
49+
filename,
50+
id: filename,
51+
addHmr: false,
52+
codeSplitGroupings: defaultCodeSplitGroupings,
53+
targetFramework: framework,
54+
})
55+
56+
await expect(compileResult.code).toMatchFileSnapshot(
57+
path.join(dirs.snapshots, filename.replace('.tsx', '@false.tsx')),
58+
)
59+
},
60+
)
61+
})
62+
})

0 commit comments

Comments
 (0)