forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue-lib.spec.ts
36 lines (34 loc) · 1.15 KB
/
vue-lib.spec.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
import path from 'node:path'
import { build } from 'vite'
import { describe, expect, test } from 'vitest'
import type { OutputChunk, RollupOutput } from 'rollup'
describe('vue component library', () => {
test('should output tree shakeable css module code', async () => {
// Build lib
await build({
logLevel: 'silent',
configFile: path.resolve(__dirname, '../vite.config.lib.ts')
})
// Build app
const { output } = (await build({
logLevel: 'silent',
configFile: path.resolve(__dirname, '../vite.config.consumer.ts')
})) as RollupOutput
const { code } = output.find(
(e) => e.type === 'chunk' && e.isEntry
) as OutputChunk
// Unused css module should be treeshaked
expect(code).toContain('styleA') // styleA is used by CompA
expect(code).not.toContain('styleB') // styleB is not used
})
test('should inject css when cssCodeSplit = true', async () => {
// Build lib
const { output } = (
await build({
logLevel: 'silent',
configFile: path.resolve(__dirname, '../vite.config.lib-css.ts')
})
)[0]
expect(output[0].code).toContain('.card{padding:4rem}')
})
})