forked from unplugin/unplugin-vue-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform.test.ts
65 lines (59 loc) · 1.66 KB
/
transform.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
import { describe, expect, it } from 'vitest'
import type { ComponentResolver } from '../src'
import { Context } from '../src/core/context'
const resolver: ComponentResolver[] = [
{
type: 'component',
resolve: name => ({ path: `test/component/${name}` }),
},
{
type: 'directive',
resolve: name => ({ path: `test/directive/${name}` }),
},
]
describe('transform', () => {
it('vue2 transform should work', async() => {
const code = `
var render = function () {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _c("test-comp", {
directives: [
{ name: "loading", rawName: "v-loading", value: 123, expression: "123" }
]
})
}
var staticRenderFns = []
render._withStripped = true
export { render, staticRenderFns }
`
const ctx = new Context({
resolvers: [resolver],
transformer: 'vue2',
directives: true,
})
ctx.sourcemap = false
expect(await ctx.transform(code, '')).toMatchSnapshot()
})
it('vue3 transform should work', async() => {
const code = `
const render = (_ctx, _cache) => {
const _component_test_comp = _resolveComponent("test-comp")
const _directive_loading = _resolveDirective("loading")
return _withDirectives(
(_openBlock(),
_createBlock(_component_test_comp, null, null, 512 /* NEED_PATCH */)),
[[_directive_loading, 123]]
)
}
`
const ctx = new Context({
resolvers: [resolver],
transformer: 'vue3',
directives: true,
})
ctx.sourcemap = false
expect(await ctx.transform(code, '')).toMatchSnapshot()
})
})