-
-
Notifications
You must be signed in to change notification settings - Fork 779
/
fixtures.test.ts
138 lines (117 loc) · 4.05 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
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
import { join, resolve } from 'path'
import { execa } from 'execa'
import { build } from 'vite'
import { describe, expect, it } from 'vitest'
import fs from 'fs-extra'
import fg from 'fast-glob'
const isMacOS = process.platform === 'darwin'
async function getGlobContent(cwd: string, glob: string) {
return await fg(glob, { cwd, absolute: true })
.then(r => Promise.all(r.map(f => fs.readFile(f, 'utf8'))))
.then(r => r.join('\n'))
}
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 getGlobContent(root, 'dist/**/*.css')
const js = await getGlobContent(root, 'dist/**/*.js')
// 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')
}
})
it('vite lib rollupOptions', async () => {
const root = resolve(__dirname, 'fixtures/vite-lib-rollupoptions')
await fs.emptyDir(join(root, 'dist'))
await build({
root,
logLevel: 'warn',
})
const files = await fg(['dist/**/index.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')
}
})
it('vue cli 4', async () => {
const root = resolve(__dirname, '../examples/vue-cli4')
await fs.emptyDir(join(root, 'dist'))
await execa('npm', ['run', isMacOS ? 'build:macos' : 'build'], { stdio: 'ignore', cwd: root })
const css = await getGlobContent(root, 'dist/**/*.css')
expect(css).contains('.w-200px')
expect(css).contains('[font~="mono"]')
}, 60_000)
it('vue cli 5', async () => {
const root = resolve(__dirname, '../examples/vue-cli5')
await fs.emptyDir(join(root, 'dist'))
await execa('npm', ['run', 'build'], { stdio: 'ignore', cwd: root })
const css = await getGlobContent(root, 'dist/**/*.css')
expect(css).contains('.w-200px')
expect(css).contains('[font~="mono"]')
}, 60_000)
})