Skip to content

Commit

Permalink
refactor: test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
zcf0508 committed Jul 12, 2024
1 parent 8b84222 commit 6d4ba23
Show file tree
Hide file tree
Showing 62 changed files with 2,582 additions and 640 deletions.
4 changes: 2 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default typegen(antfu({
}, [
{
ignores: [
'test/**/*.vue',
'test/**/*.jsx',
'fixtures/**/*',
'test/output/**/*',
'public/**/*',
'components/ui/**/*',
],
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function funC(varB) { // 这是注释
const [ varD, varE ] = funC(varB)
onMounted(() => {
funC()
funC?.()
})
const props1 = withDefaults(defineProps<{test: number}>(), {
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"eslint-plugin-security": "^3.0.1",
"eslint-plugin-vue-hook-optimizer": "workspace:*",
"eslint-typegen": "^0.2.4",
"fast-glob": "^3.3.2",
"lodash-es": "^4.17.21",
"nodemon": "^3.1.0",
"ts-node": "^10.9.2",
Expand Down
19 changes: 5 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions test/fixtures.test.ts
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`);
}
});
}
}
});
21 changes: 0 additions & 21 deletions test/options-base-defineComponent/TestComponent.graph.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/options-base-defineComponent/TestComponent.nodes.ts

This file was deleted.

22 changes: 0 additions & 22 deletions test/options-base-defineComponent/index.test.ts

This file was deleted.

19 changes: 0 additions & 19 deletions test/options-base-jsx/TestComponent.graph.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/options-base-jsx/TestComponent.nodes.ts

This file was deleted.

20 changes: 0 additions & 20 deletions test/options-base-jsx/index.test.ts

This file was deleted.

19 changes: 0 additions & 19 deletions test/options-base/TestComponent.graph.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/options-base/TestComponent.nodes.ts

This file was deleted.

19 changes: 0 additions & 19 deletions test/options-base/index.test.ts

This file was deleted.

27 changes: 0 additions & 27 deletions test/options-setup-jsx/TestComponent.graph.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/options-setup-jsx/TestComponent.nodes.ts

This file was deleted.

20 changes: 0 additions & 20 deletions test/options-setup-jsx/index.test.ts

This file was deleted.

29 changes: 0 additions & 29 deletions test/options-setup/TestComponent.graph.ts

This file was deleted.

1 change: 0 additions & 1 deletion test/options-setup/TestComponent.nodes.ts

This file was deleted.

Loading

0 comments on commit 6d4ba23

Please sign in to comment.