forked from unocss/unocss
/
extractor.test.ts
45 lines (37 loc) · 2.33 KB
/
extractor.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { extractorSplit, extractorSvelte } from '@unocss/core'
import { expect, it } from 'vitest'
it('extractorSplit', async () => {
async function extract(code: string) {
return [...await extractorSplit.extract({ code, original: code }) || []]
}
expect(await extract('foo')).eql(['foo'])
expect(await extract('<div class="text-red border">foo</div>')).toContain('text-red')
expect(await extract('<div class="<sm:text-lg">foo</div>')).toContain('<sm:text-lg')
expect(await extract('"class=\"bg-white\""')).toContain('bg-white')
})
it('extractorSvelte uses regular split with non .svelte files', async () => {
async function extract(code: string) {
return [...await extractorSvelte.extract({ code, original: code }) || []]
}
expect(await extract('foo')).eql(['foo'])
expect(await extract('<div class="text-red border">foo</div>')).toContain('text-red')
expect(await extract('<div class="<sm:text-lg">foo</div>')).toContain('<sm:text-lg')
expect(await extract('"class=\"bg-white\""')).toContain('bg-white')
expect(await extract('<div class:text-orange-400={foo} />')).toContain('class:text-orange-400=')
expect(await extract('class:text-gray-800={$page.url.pathname.startsWith(\'/test\')}')).toContain('class:text-gray-800=')
expect(await extract('<div class="data-[a~=b]:text-red">foo</div>')).toContain('data-[a~=b]:text-red')
expect(await extract('<div class:text-[32px]="{true}" />')).toContain('class:text-[32px]=')
})
it('extractorSvelte uses svelte-specific split with .svelte files', async () => {
async function extract(code: string) {
return [...await extractorSvelte.extract({ code, original: code, id: 'file.svelte' }) || []]
}
expect(await extract('foo')).eql(['foo'])
expect(await extract('<div class="text-red border">foo</div>')).toContain('text-red')
expect(await extract('<div class="<sm:text-lg">foo</div>')).toContain('<sm:text-lg')
expect(await extract('"class=\"bg-white\""')).toContain('bg-white')
expect(await extract('<div class:text-orange-400={foo} />')).toContain('text-orange-400')
expect(await extract('class:text-gray-800={$page.url.pathname.startsWith(\'/test\')}')).toContain('text-gray-800')
expect(await extract('<div class="data-[a~=b]:text-red">foo</div>')).toContain('data-[a~=b]:text-red')
expect(await extract('<div class:text-[32px]="{true}" />')).toContain('text-[32px]')
})