Skip to content

Commit 734f65b

Browse files
committed
test: add tests for prefix
1 parent c6d77c0 commit 734f65b

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

test/__snapshots__/transform.test.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ import __unplugin_components_0 from 'test/component/ElInfiniteScroll';
6363
}
6464
`;
6565

66+
exports[`prefix transform > transform with prefix should work 1`] = `
67+
{
68+
"code": "/* unplugin-vue-components disabled */import __unplugin_components_2 from 'test/component/test-comp.vue';
69+
import __unplugin_components_1 from 'test/component/test-comp.vue';
70+
import __unplugin_components_0 from 'test/component/test-comp.vue';
71+
72+
const render = (_ctx, _cache) => {
73+
const _component_test_comp = __unplugin_components_0
74+
const _component_testComp = __unplugin_components_1
75+
const _component_testComp = __unplugin_components_2
76+
77+
return _withDirectives(
78+
(_openBlock(),
79+
_createBlock(_component_test_comp, null, null, 512 /* NEED_PATCH */)),
80+
_createBlock(_component_testComp, null, null, 512 /* NEED_PATCH */)),
81+
_createBlock(_component_TestComp, null, null, 512 /* NEED_PATCH */))
82+
)
83+
}
84+
",
85+
}
86+
`;
87+
6688
exports[`transform > vue2 transform should work 1`] = `
6789
{
6890
"code": "/* unplugin-vue-components disabled */import __unplugin_directives_0 from 'test/directive/Loading';

test/transform.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ComponentResolver } from '../src'
22
import { describe, expect, it } from 'vitest'
3+
import { pascalCase } from '../src'
34
import { Context } from '../src/core/context'
45

56
const resolver: ComponentResolver[] = [
@@ -173,3 +174,38 @@ describe('component and directive as same name', () => {
173174
expect(await ctx.transform(code, '')).toMatchSnapshot()
174175
})
175176
})
177+
178+
describe('prefix transform', () => {
179+
it('transform with prefix should work', async () => {
180+
const code = `
181+
const render = (_ctx, _cache) => {
182+
const _component_test_comp = _resolveComponent("custom-prefix-test-comp")
183+
const _component_testComp = _resolveComponent("CustomPrefixTestComp")
184+
const _component_testComp = _resolveComponent("customPrefixTestComp")
185+
186+
return _withDirectives(
187+
(_openBlock(),
188+
_createBlock(_component_test_comp, null, null, 512 /* NEED_PATCH */)),
189+
_createBlock(_component_testComp, null, null, 512 /* NEED_PATCH */)),
190+
_createBlock(_component_TestComp, null, null, 512 /* NEED_PATCH */))
191+
)
192+
}
193+
`
194+
195+
const ctx = new Context({
196+
prefix: 'CustomPrefix',
197+
directives: true,
198+
})
199+
ctx.sourcemap = false
200+
const componentName = 'TestComp'
201+
const name = `${pascalCase(ctx.options.prefix)}${pascalCase(componentName)}`
202+
// @ts-expect-error for test
203+
ctx._componentNameMap = {
204+
[name]: {
205+
as: name,
206+
from: 'test/component/test-comp.vue',
207+
},
208+
}
209+
expect(await ctx.transform(code, '')).toMatchSnapshot()
210+
})
211+
})

0 commit comments

Comments
 (0)