forked from vitejs/vite-plugin-vue
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvue-lib.spec.ts
37 lines (35 loc) · 1.26 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
37
import path from 'node:path'
import { build } from 'rolldown-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
// The build minify removed /* @__PURE__ */ at CompB, the rolldown preserve it is correct.
// 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}')
})
})