forked from vuejs/rollup-plugin-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.e2e.ts
118 lines (97 loc) · 2.98 KB
/
core.e2e.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
import { rollup, RollupOutput, RollupWarning } from 'rollup'
describe('simple', () => {
let result!: RollupOutput
beforeAll(async () => {
result = await roll('simple')
})
it('should compile <template>', () => {
expect(result.output[0].code).toEqual(expect.stringContaining('.render ='))
})
})
describe('no-template', () => {
let result!: RollupOutput
beforeAll(async () => {
result = await roll('no-template')
})
it('should leave the render function alone when no template is in the SFC', () => {
expect(result.output[0].code).not.toEqual(
expect.stringContaining('.render =')
)
})
})
describe('custom-block', () => {
let result!: RollupOutput
beforeAll(async () => {
result = await roll('custom-block')
})
it('should compile <i18n>', () => {
expect(result.output[0].code).toEqual(
expect.stringContaining(
'component.i18n = {"say":{"hello":"Hello :name"}}'
)
)
})
})
describe('css-modules', () => {
let result!: RollupOutput
beforeAll(async () => {
result = await roll('css-modules')
})
it('should process <style module> blocks', () => {
expect(result.output[0].code).toEqual(
expect.stringContaining('cssModules["$style"] =')
)
expect(result.output[0].code).not.toEqual(
expect.stringContaining('.red {\n color: red;\n}')
)
expect(result.output[0].code).toEqual(expect.stringContaining('.red___'))
expect(result.output[0].code).toEqual(
expect.stringContaining('{"red":"red___')
)
})
it('should process <style scoped> blocks', () => {
expect(result.output[0].code).toEqual(
expect.stringContaining('.__scopeId = "data-v-')
)
expect(result.output[0].code).not.toEqual(
expect.stringContaining('.green {\n color: green;\n}')
)
expect(result.output[0].code).toEqual(
expect.stringContaining('.green[data-v-')
)
})
})
describe('typescript', () => {
let result!: RollupOutput
beforeAll(async () => {
result = await roll('typescript')
})
it('should compile <script lang="ts">', () => {
expect(result.output[0].code).toEqual(
expect.stringContaining("name: 'App'")
)
expect(result.output[0].code).toEqual(
expect.stringContaining("title: 'Bar'")
)
})
})
import Path from 'path'
async function roll(name: string) {
const configFile = `../examples/${name}/rollup.config.js`
const configModule = require(configFile)
const configs = configModule.__esModule ? configModule.default : configModule
const config = Array.isArray(configs) ? configs[0] : configs
config.input = Path.resolve(__dirname, Path.dirname(configFile), config.input)
delete config.output
config.onwarn = function (warning: RollupWarning, warn: Function) {
switch (warning.code) {
case 'UNUSED_EXTERNAL_IMPORT':
return
default:
warning.message = `(${name}) ${warning.message}`
warn(warning)
}
}
const bundle = await rollup(config)
return bundle.generate({ format: 'esm' })
}