forked from unocss/unocss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixtures.test.ts
80 lines (70 loc) · 2.28 KB
/
fixtures.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
import { join, resolve } from 'path'
import { build } from 'vite'
import { describe, expect, it } from 'vitest'
import fs from 'fs-extra'
import fg from 'fast-glob'
describe.concurrent('fixtures', () => {
it('vite client', async () => {
const root = resolve(__dirname, 'fixtures/vite')
await fs.emptyDir(join(root, 'dist'))
await build({
root,
logLevel: 'warn',
build: {
sourcemap: true,
},
})
const css = await fg('dist/**/*.css', { cwd: root, absolute: true })
.then(r => Promise.all(r.map(f => fs.readFile(f, 'utf8'))))
.then(r => r.join('\n'))
const js = await fg('dist/**/*.js', { cwd: root, absolute: true })
.then(r => Promise.all(r.map(f => fs.readFile(f, 'utf8'))))
.then(r => r.join('\n'))
// basic
expect(css).contains('.text-red')
// transformer-variant-group
expect(css).contains('.text-sm')
// transformer-compile-class
expect(css).contains('.uno-tacwqa')
// transformer-directives
expect(css).not.contains('@apply')
expect(css).not.contains('--at-apply')
expect(css).contains('gap:.25rem')
expect(css).contains('gap:.5rem')
// transformer-variant-group
expect(js).contains('text-sm')
// transformer-compile-class
expect(js).contains('uno-tacwqa')
})
it('vite lib', async () => {
const root = resolve(__dirname, 'fixtures/vite-lib')
await fs.emptyDir(join(root, 'dist'))
await build({
root,
logLevel: 'warn',
build: {
sourcemap: true,
},
})
const files = await fg('dist/**/*.{umd,iife}.js', { cwd: root, absolute: true })
expect(files).toHaveLength(2)
for (const path of files) {
const code = await fs.readFile(path, 'utf-8')
// basic
expect(code).contains('.text-red')
// transformer-variant-group
expect(code).contains('.text-sm')
// transformer-compile-class
expect(code).contains('.uno-tacwqa')
// transformer-directives
expect(code).not.contains('@apply')
expect(code).not.contains('--at-apply')
expect(code).contains('gap:.25rem')
expect(code).contains('gap:.5rem')
// transformer-variant-group
expect(code).contains('text-sm')
// transformer-compile-class
expect(code).contains('uno-tacwqa')
}
})
})