generated from sonofmagic/monorepo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvite.test.ts
83 lines (82 loc) · 2.4 KB
/
vite.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
import type { RollupOutput } from 'rollup'
import path from 'pathe'
import utwm from '@/vite'
import { build } from 'vite'
// .replace(/(\r?\n){3,}/g, '\n\n')
const appRoot = path.resolve(__dirname, 'fixtures/vite-repo')
describe('vite build', () => {
it('common build ', async () => {
const res = (await build({
root: appRoot,
build: {
write: false,
cssMinify: false,
rollupOptions: {
output: {
entryFileNames: `[name].js`,
chunkFileNames: `[name].js`,
assetFileNames: `[name].[ext]`,
},
},
},
plugins: [
utwm({
classListPath: path.resolve(appRoot, '.tw-patch/tw-class-list.json'),
}),
],
})) as RollupOutput
const output = res.output
expect(output.length).toBe(3)
const jsFile = output[0]
expect(jsFile.type).toBe('chunk')
expect(jsFile.code).toMatchSnapshot()
expect(jsFile.code).toContain('ease-out')
expect(output[1].type).toBe('asset')
if (output[1].type === 'asset') {
expect(output[1].source).toMatchSnapshot()
}
expect(output[2].type).toBe('asset')
if (output[2].type === 'asset') {
expect(output[2].source.toString().replace(/(\r?\n)+/g, '\n')).toMatchSnapshot()
}
})
it('common build change class prefix', async () => {
const res = (await build({
root: appRoot,
build: {
write: false,
cssMinify: false,
rollupOptions: {
output: {
entryFileNames: `[name].js`,
chunkFileNames: `[name].js`,
assetFileNames: `[name].[ext]`,
},
},
},
plugins: [
utwm({
classListPath: path.resolve(appRoot, '.tw-patch/tw-class-list.json'),
classGenerator: {
classPrefix: 'ice-',
},
}),
],
})) as RollupOutput
const output = res.output
expect(output.length).toBe(3)
const jsFile = output[0]
expect(jsFile.type).toBe('chunk')
expect(jsFile.code).toMatchSnapshot()
expect(jsFile.code).toContain('ease-out')
expect(output[1].type).toBe('asset')
if (output[1].type === 'asset') {
expect(output[1].source).toMatchSnapshot()
}
expect(output[2].type).toBe('asset')
if (output[2].type === 'asset') {
const res = output[2].source.toString().replace(/(\r?\n)+/g, '\n')
expect(res).toMatchSnapshot()
}
})
})