/
preset-mini.test.ts
88 lines (76 loc) · 2.17 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
import { createGenerator, escapeSelector } from '@unocss/core'
import { describe, expect, test } from 'vitest'
import presetWeapp from '../src/index'
import { presetMiniNonTargets, presetMiniTargets } from './assets/preset-mini-targets'
import { presetWindTargets } from './assets/preset-wind-targets'
const uno = createGenerator({
presets: [
presetWeapp({
dark: 'media',
}),
],
theme: {
colors: {
custom: {
a: 'var(--custom)',
b: 'rgba(var(--custom), %alpha)',
},
a: {
b: {
c: '#514543',
},
camelCase: '#234',
},
},
},
})
describe('preset-mini', () => {
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: [
presetWeapp({
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([])
})
})