forked from unocss/unocss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntime.test.ts
101 lines (91 loc) · 3.01 KB
/
runtime.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { createGenerator } from '@unocss/core'
import presetUno from '@unocss/preset-uno'
import presetTagify from '@unocss/preset-tagify'
import { describe, expect, test } from 'vitest'
import { autoPrefixer, decodeHtml } from '../packages/runtime/src/utils'
function mockElementWithStyle() {
const store: any = {}
return {
style: {
WebkitFilter: '',
WebkitPerspective: '',
WebkitVars: '',
msHyphens: '',
MsNonHyphens: '',
setProperty(key: string, val: string) {
store[key] = val
},
getPropertyValue(key: string) {
return store[key]
},
},
}
}
const targets = [
'filter', // whitelisted in function
'perspect-1px', // Webkit prefix
'hyphens-auto', // ms prefix
'[--vars:value]', // css variable
'[-vars:value]',
'[vars:value]',
'[filter:none]',
'[perspective:0]',
'[hyphens:none]',
'[non-hyphens:none]',
].join(' ')
describe('runtime auto prefixer', () => {
test('without autoprefixer', async () => {
const uno = createGenerator({
presets: [
presetUno(),
],
})
const { css } = await uno.generate(targets, { preflights: false })
expect(css).toMatchSnapshot()
})
test('using autoprefixer', async () => {
const uno = createGenerator({
presets: [
presetUno(),
],
postprocess: [
autoPrefixer(mockElementWithStyle().style as any),
],
})
const { css } = await uno.generate(targets, { preflights: false })
expect(css).toMatchSnapshot()
})
test('runtime tagify', async () => {
const uno = createGenerator({
presets: [
presetUno(),
presetTagify(),
],
})
const { css } = await uno.generate(`
<flex>
<text-red> red text </text-red>
<text-green5:10 />
<m-1 class="p2"> margin </m-1>
<btn> shortcut </btn>
<hover:color-red> variant </hover:color-red>
<scale-2> zoom </scale-2>
<shadow-xl> modal </shadow-xl>
</flex>
`, { preflights: false })
expect(css).toMatchSnapshot()
})
})
describe('runtime decode html', () => {
test('decode function', async () => {
expect(decodeHtml('<tag class="[&_*]:text-red>"')).toMatchInlineSnapshot('"<tag class=\\"[&_*]:text-red>\\""')
expect(decodeHtml('<tag class="[&_*]:text-red>"')).toMatchInlineSnapshot('"<tag class=\\"[&_*]:text-red>\\""')
expect(decodeHtml('<tag class="[&>*]:text-red>"')).toMatchInlineSnapshot('"<tag class=\\"[&>*]:text-red>\\""')
expect(decodeHtml('<tag class="[&>*]:text-red>"')).toMatchInlineSnapshot('"<tag class=\\"[&>*]:text-red>\\""')
expect(decodeHtml('<tag class="[&<*]:text-red>"')).toMatchInlineSnapshot('"<tag class=\\"[&<*]:text-red>\\""')
expect(decodeHtml('<tag class="[&<*]:text-red>"')).toMatchInlineSnapshot('"<tag class=\\"[&<*]:text-red>\\""')
})
test('not decoding all entities', async () => {
expect(decodeHtml('<tag class="[&_*]:content-[ ]>"')).toMatchInlineSnapshot('"<tag class=\\"[&_*]:content-[ ]>\\""')
})
})