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
556ad34642
commit
d992c0da95
@ -18,6 +18,7 @@ export const ComponentNamePlugin = (options: NameDevPluginOptions) => createUnpl
|
||||
name: 'nuxt:component-name-plugin',
|
||||
enforce: 'post',
|
||||
transformInclude (id) {
|
||||
/* v8 ignore next 2 */
|
||||
return isVue(id) || !!id.match(SX_RE)
|
||||
},
|
||||
transform (code, id) {
|
||||
@ -53,6 +54,7 @@ export const ComponentNamePlugin = (options: NameDevPluginOptions) => createUnpl
|
||||
return {
|
||||
code: s.toString(),
|
||||
map: options.sourcemap
|
||||
/* v8 ignore next */
|
||||
? s.generateMap({ hires: true })
|
||||
: undefined,
|
||||
}
|
||||
|
@ -6,13 +6,34 @@ import * as Parser from 'acorn'
|
||||
import { ComponentNamePlugin } from '../src/components/plugins/component-names'
|
||||
|
||||
describe('component names', () => {
|
||||
const components = [{
|
||||
filePath: 'test.ts',
|
||||
pascalName: 'TestMe',
|
||||
}] as [Component]
|
||||
const components = [
|
||||
{
|
||||
filePath: 'test.ts',
|
||||
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 }
|
||||
|
||||
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', () => {
|
||||
const sfc = `
|
||||
<script setup>
|
||||
|
Loading…
Reference in New Issue
Block a user