forked from unocss/unocss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-async.test.ts
48 lines (46 loc) · 1.19 KB
/
generate-async.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
import { createGenerator } from '@unocss/core'
import { describe, expect, test } from 'vitest'
describe('generate-async', () => {
test('rule-first', async () => {
const order: number[] = []
const uno = createGenerator({
rules: [
[/^rule$/, () => new Promise(resolve => setTimeout(() => {
order.push(1)
resolve('/* rule */')
}, 10))],
],
preflights: [
{
getCSS: () => new Promise(resolve => setTimeout(() => {
order.push(2)
resolve('/* preflight */')
}, 20)),
},
],
})
await uno.generate('rule')
expect(order).eql([1, 2])
})
test('preflight-first', async () => {
const order: number[] = []
const uno = createGenerator({
rules: [
[/^rule$/, () => new Promise(resolve => setTimeout(() => {
order.push(2)
resolve('/* rule */')
}, 20))],
],
preflights: [
{
getCSS: () => new Promise(resolve => setTimeout(() => {
order.push(1)
resolve('/* preflight */')
}, 10)),
},
],
})
await uno.generate('rule')
expect(order).eql([1, 2])
})
})