From 738d1251020e047bc911e7c8b04d4044a42a33f1 Mon Sep 17 00:00:00 2001 From: zcf0508 Date: Fri, 12 Jul 2024 16:08:44 +0800 Subject: [PATCH] chore: add tests for node used in style --- test/fixtures.test.ts | 11 +++++++---- test/output/vue/options-setup.vue.nodes.txt | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/test/fixtures.test.ts b/test/fixtures.test.ts index b7c8b33..fbf697f 100644 --- a/test/fixtures.test.ts +++ b/test/fixtures.test.ts @@ -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; @@ -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 || '', @@ -27,7 +30,7 @@ describe('fixtures', async () => { ? analyzeTemplate(sfc.descriptor.template!.content) : new Set(); - await expect(new Set([...nodesUsedInTemplate, ...nodes])) + await expect(new Set([...nodesUsedInStyle, ...nodesUsedInTemplate, ...nodes])) .toMatchFileSnapshot(`./output/${testName}.nodes.txt`); } else if (sfc.descriptor.scriptSetup?.content) { @@ -41,7 +44,7 @@ describe('fixtures', async () => { const nodes = sfc.descriptor.template?.content ? analyzeTemplate(sfc.descriptor.template!.content) : new Set(); - await expect(nodes) + await expect(new Set([...nodesUsedInStyle, ...nodes])) .toMatchFileSnapshot(`./output/${testName}.nodes.txt`); } else { @@ -57,7 +60,7 @@ describe('fixtures', async () => { ? analyzeTemplate(sfc.descriptor.template!.content) : new Set(); - await expect(new Set([...nodesUsedInTemplate, ...nodes])) + await expect(new Set([...nodesUsedInStyle, ...nodesUsedInTemplate, ...nodes])) .toMatchFileSnapshot(`./output/${testName}.nodes.txt`); } } diff --git a/test/output/vue/options-setup.vue.nodes.txt b/test/output/vue/options-setup.vue.nodes.txt index 33e0124..8aba6ac 100644 --- a/test/output/vue/options-setup.vue.nodes.txt +++ b/test/output/vue/options-setup.vue.nodes.txt @@ -1,9 +1,9 @@ Set { + "count", "ComponentD", "msgRef", "msg", "plus", - "count", "number", "add", } \ No newline at end of file