Skip to content

Commit

Permalink
chore: add tests for node used in style
Browse files Browse the repository at this point in the history
  • Loading branch information
zcf0508 committed Jul 12, 2024
1 parent 6d4ba23 commit 738d125
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions test/fixtures.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from 'node:fs';
import { basename } from 'node:path';
import fg from 'fast-glob';
import { analyzeOptions, analyzeSetupScript, analyzeTemplate, analyzeTsx, parse } from '@/index';
import { analyzeOptions, analyzeSetupScript, analyzeStyle, analyzeTemplate, analyzeTsx, parse } from '@/index';

describe('fixtures', async () => {
const frameworks = ['vue', 'react'] as const;
Expand All @@ -13,6 +13,9 @@ describe('fixtures', async () => {
const source = readFileSync(test, 'utf-8');
if (framework === 'vue') {
const sfc = parse(source);

const nodesUsedInStyle = analyzeStyle(sfc.descriptor.styles || []);

if (test.includes('tsx')) {
const { graph, nodesUsedInTemplate } = analyzeTsx(
sfc.descriptor.script?.content || '',
Expand All @@ -27,7 +30,7 @@ describe('fixtures', async () => {
? analyzeTemplate(sfc.descriptor.template!.content)
: new Set<string>();

await expect(new Set([...nodesUsedInTemplate, ...nodes]))
await expect(new Set([...nodesUsedInStyle, ...nodesUsedInTemplate, ...nodes]))
.toMatchFileSnapshot(`./output/${testName}.nodes.txt`);
}
else if (sfc.descriptor.scriptSetup?.content) {
Expand All @@ -41,7 +44,7 @@ describe('fixtures', async () => {
const nodes = sfc.descriptor.template?.content
? analyzeTemplate(sfc.descriptor.template!.content)
: new Set<string>();
await expect(nodes)
await expect(new Set([...nodesUsedInStyle, ...nodes]))
.toMatchFileSnapshot(`./output/${testName}.nodes.txt`);
}
else {
Expand All @@ -57,7 +60,7 @@ describe('fixtures', async () => {
? analyzeTemplate(sfc.descriptor.template!.content)
: new Set<string>();

await expect(new Set([...nodesUsedInTemplate, ...nodes]))
await expect(new Set([...nodesUsedInStyle, ...nodesUsedInTemplate, ...nodes]))
.toMatchFileSnapshot(`./output/${testName}.nodes.txt`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/output/vue/options-setup.vue.nodes.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Set {
"count",
"ComponentD",
"msgRef",
"msg",
"plus",
"count",
"number",
"add",
}

0 comments on commit 738d125

Please sign in to comment.