forked from unocss/unocss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preset-mini.test.ts
141 lines (123 loc) · 3.29 KB
/
preset-mini.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { createGenerator, escapeSelector } from '@unocss/core'
import presetMini from '@unocss/preset-mini'
import { describe, expect, test } from 'vitest'
import { presetMiniNonTargets, presetMiniTargets } from './assets/preset-mini-targets'
import { presetWindTargets } from './assets/preset-wind-targets'
const uno = createGenerator({
presets: [
presetMini({
dark: 'media',
}),
],
theme: {
colors: {
custom: {
a: 'var(--custom)',
b: 'rgba(var(--custom), %alpha)',
},
a: {
b: {
c: '#514543',
},
camelCase: '#234',
},
},
},
})
describe('preset-mini', () => {
test('dark customizing selector', async () => {
const uno = createGenerator({
presets: [
presetMini({
dark: {
dark: '[data-mode="dark"]',
light: '[data-mode="light"]',
},
}),
],
})
const { css } = await uno.generate([
'dark:bg-white',
'dark:text-lg',
'dark:hover:rounded',
'light:bg-black',
'light:text-sm',
'light:disabled:w-full',
].join(' '), {
preflights: false,
})
expect(css).toMatchSnapshot()
})
test('targets', async () => {
const code = presetMiniTargets.join(' ')
const { css } = await uno.generate(code)
const { css: css2 } = await uno.generate(code)
const unmatched = []
for (const i of presetMiniTargets) {
if (!css.includes(escapeSelector(i)))
unmatched.push(i)
}
expect(unmatched).toEqual([])
expect(css).toMatchSnapshot()
expect(css).toEqual(css2)
})
test('utils from preset-wind should be non-targets', async () => {
const code = presetWindTargets.join(' ')
const { css, matched } = await uno.generate(code, { preflights: false })
expect(Array.from(matched)).toEqual([])
expect(css).toBe('')
})
test('custom var prefix', async () => {
const uno = createGenerator({
presets: [
presetMini({
variablePrefix: 'hi-',
}),
],
})
const { css } = await uno.generate([
'text-opacity-50',
'text-red',
'scale-100',
].join(' '), { preflights: false })
expect(css).toMatchSnapshot()
})
test('nested theme colors', async () => {
const { css, matched } = await uno.generate([
'text-a-b-c',
'text-a-camel-case',
'bg-a-b-c',
], { preflights: false })
expect(css).toMatchSnapshot('')
expect(matched.size).toBe(3)
})
test('none targets', async () => {
const { css, matched } = await uno.generate(new Set(presetMiniNonTargets), { minify: true, preflights: false })
expect(css).toMatchInlineSnapshot('""')
expect([...matched]).toEqual([])
})
test('fontSize theme', async () => {
const uno = createGenerator({
presets: [
presetMini(),
],
theme: {
fontSize: {
small: '1rem',
medium: ['2rem', '1.5em'],
xs: '2rem',
lg: ['3rem', '1.5em'],
},
},
})
const { css } = await uno.generate([
'text-small',
'text-medium',
'text-xs',
'text-lg',
].join(' '), { preflights: false })
// @ts-expect-error types
expect(uno.config.theme.fontSize.lg).toEqual(['3rem', '1.5em'])
expect(css).toMatchSnapshot()
})
})