-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { readFileSync } from 'node:fs'; | ||
import { basename } from 'node:path'; | ||
import fg from 'fast-glob'; | ||
import { analyzeOptions, analyzeSetupScript, analyzeTemplate, analyzeTsx, parse } from '@/index'; | ||
|
||
describe('fixtures', async () => { | ||
const frameworks = ['vue', 'react'] as const; | ||
for (const framework of frameworks) { | ||
const tests = await fg(`./fixtures/${framework}/**/*`); | ||
for (const test of tests) { | ||
const testName = `${framework}/${basename(test)}`; | ||
it(testName, async () => { | ||
const source = readFileSync(test, 'utf-8'); | ||
if (framework === 'vue') { | ||
const sfc = parse(source); | ||
if (test.includes('tsx')) { | ||
const { graph, nodesUsedInTemplate } = analyzeTsx( | ||
sfc.descriptor.script?.content || '', | ||
'vue', | ||
(sfc.descriptor.script?.loc.start.line || 1) - 1, | ||
); | ||
|
||
await expect(graph) | ||
.toMatchFileSnapshot(`./output/${testName}.graph.txt`); | ||
|
||
const nodes = sfc.descriptor.template?.content | ||
? analyzeTemplate(sfc.descriptor.template!.content) | ||
: new Set<string>(); | ||
|
||
await expect(new Set([...nodesUsedInTemplate, ...nodes])) | ||
.toMatchFileSnapshot(`./output/${testName}.nodes.txt`); | ||
} | ||
else if (sfc.descriptor.scriptSetup?.content) { | ||
const graph = analyzeSetupScript( | ||
sfc.descriptor.scriptSetup?.content || '', | ||
(sfc.descriptor.scriptSetup?.loc.start.line || 1) - 1, | ||
); | ||
await expect(graph) | ||
.toMatchFileSnapshot(`./output/${testName}.graph.txt`); | ||
|
||
const nodes = sfc.descriptor.template?.content | ||
? analyzeTemplate(sfc.descriptor.template!.content) | ||
: new Set<string>(); | ||
await expect(nodes) | ||
.toMatchFileSnapshot(`./output/${testName}.nodes.txt`); | ||
} | ||
else { | ||
const { graph, nodesUsedInTemplate } = analyzeOptions( | ||
sfc.descriptor.script?.content || '', | ||
(sfc.descriptor.script?.loc.start.line || 1) - 1, | ||
true, | ||
); | ||
await expect(graph) | ||
.toMatchFileSnapshot(`./output/${testName}.graph.txt`); | ||
|
||
const nodes = sfc.descriptor.template?.content | ||
? analyzeTemplate(sfc.descriptor.template!.content) | ||
: new Set<string>(); | ||
|
||
await expect(new Set([...nodesUsedInTemplate, ...nodes])) | ||
.toMatchFileSnapshot(`./output/${testName}.nodes.txt`); | ||
} | ||
} | ||
if (framework === 'react') { | ||
const { graph, nodesUsedInTemplate } = analyzeTsx( | ||
source, | ||
'react', | ||
0, | ||
); | ||
await expect(graph) | ||
.toMatchFileSnapshot(`./output/${testName}.graph.txt`); | ||
|
||
await expect(nodesUsedInTemplate) | ||
.toMatchFileSnapshot(`./output/${testName}.nodes.txt`); | ||
} | ||
}); | ||
} | ||
} | ||
}); |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.