mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-22 16:39:58 +00:00
test: slightly improve coverage
This commit is contained in:
parent
3854cb737c
commit
47427adff9
@ -18,6 +18,7 @@ export const ComponentNamePlugin = (options: NameDevPluginOptions) => createUnpl
|
|||||||
name: 'nuxt:component-name-plugin',
|
name: 'nuxt:component-name-plugin',
|
||||||
enforce: 'post',
|
enforce: 'post',
|
||||||
transformInclude (id) {
|
transformInclude (id) {
|
||||||
|
/* v8 ignore next 2 */
|
||||||
return isVue(id) || !!id.match(SX_RE)
|
return isVue(id) || !!id.match(SX_RE)
|
||||||
},
|
},
|
||||||
transform (code, id) {
|
transform (code, id) {
|
||||||
@ -53,6 +54,7 @@ export const ComponentNamePlugin = (options: NameDevPluginOptions) => createUnpl
|
|||||||
return {
|
return {
|
||||||
code: s.toString(),
|
code: s.toString(),
|
||||||
map: options.sourcemap
|
map: options.sourcemap
|
||||||
|
/* v8 ignore next */
|
||||||
? s.generateMap({ hires: true })
|
? s.generateMap({ hires: true })
|
||||||
: undefined,
|
: undefined,
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,34 @@ import * as Parser from 'acorn'
|
|||||||
import { ComponentNamePlugin } from '../src/components/plugins/component-names'
|
import { ComponentNamePlugin } from '../src/components/plugins/component-names'
|
||||||
|
|
||||||
describe('component names', () => {
|
describe('component names', () => {
|
||||||
const components = [{
|
const components = [
|
||||||
filePath: 'test.ts',
|
{
|
||||||
pascalName: 'TestMe',
|
filePath: 'test.ts',
|
||||||
}] as [Component]
|
pascalName: 'TestMe',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
filePath: 'test.vue',
|
||||||
|
pascalName: 'TestMe',
|
||||||
|
},
|
||||||
|
] as [Component, Component]
|
||||||
|
|
||||||
const transformPlugin = ComponentNamePlugin({ sourcemap: false, getComponents: () => components }).raw({}, {} as any) as { transform: (code: string, id: string) => { code: string } | null }
|
const transformPlugin = ComponentNamePlugin({ sourcemap: false, getComponents: () => components }).raw({}, {} as any) as { transform: (code: string, id: string) => { code: string } | null }
|
||||||
|
|
||||||
|
it('should ignore files without extension', () => {
|
||||||
|
const res = transformPlugin.transform('export default {}', 'test')
|
||||||
|
expect(res?.code).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should ignore files that are not components ', () => {
|
||||||
|
const res = transformPlugin.transform('export default {}', 'some-other-file.ts')
|
||||||
|
expect(res?.code).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should process simple default exports', () => {
|
||||||
|
const res = transformPlugin.transform('export default {}', 'test.vue')
|
||||||
|
expect(res?.code).toMatchInlineSnapshot(`"export default Object.assign({}, { __name: "TestMe" })"`)
|
||||||
|
})
|
||||||
|
|
||||||
it('should add correct default component names', () => {
|
it('should add correct default component names', () => {
|
||||||
const sfc = `
|
const sfc = `
|
||||||
<script setup>
|
<script setup>
|
||||||
|
Loading…
Reference in New Issue
Block a user