/
preset-mini.test.ts
71 lines (61 loc) · 1.82 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
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)',
},
},
},
})
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: [
presetMini({
variablePrefix: 'hi-',
}),
],
})
const { css } = await uno.generate([
'text-opacity-50',
'text-red',
'scale-100',
].join(' '), { preflights: false })
expect(css).toMatchSnapshot()
})
test('none targets', async () => {
const { css, matched } = await uno.generate(new Set(presetMiniNonTargets), { minify: true, preflights: false })
expect(css).toMatchInlineSnapshot('""')
expect([...matched]).toEqual([])
})
})