8000 test: slightly improve coverage · nuxt/nuxt@d992c0d · GitHub
[go: up one dir, main page]

Skip to content

Commit d992c0d

Browse files
committed
test: slightly improve coverage
1 parent 556ad34 commit d992c0d

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

packages/nuxt/src/components/plugins/component-names.ts

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const ComponentNamePlugin = (options: NameDevPluginOptions) => createUnpl
1818
name: 'nuxt:component-name-plugin',
1919
enforce: 'post',
2020
transformInclude (id) {
21+
/* v8 ignore next 2 */
2122
return isVue(id) || !!id.match(SX_RE)
2223
},
2324
transform (code, id) {
@@ -53,6 +54,7 @@ export const ComponentNamePlugin = (options: NameDevPluginOptions) => createUnpl
5354
return {
5455
code: s.toString(),
5556
map: options.sourcemap
57+
/* v8 ignore next */
5658
? s.generateMap({ hires: true })
5759
: undefined,
5860
}

packages/nuxt/test/component-names.test.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,34 @@ import * as Parser from 'acorn'
66
import { ComponentNamePlugin } from '../src/components/plugins/component-names'
77

88
describe('component names', () => {
9-
const components = [{
10-
filePath: 'test.ts',
11-
pascalName: 'TestMe',
12-
}] as [Component]
9+
const components = [
10+
{
11+
filePath: 'test.ts',
12+
pascalName: 'TestMe',
13+
},
14+
{
15+
filePath: 'test.vue',
16+
pascalName: 'TestMe',
17+
},
18+
] as [Component, Component]
1319

1420
const transformPlugin = ComponentNamePlugin({ sourcemap: false, getComponents: () => components }).raw({}, {} as any) as { transform: (code: string, id: string) => { code: string } | null }
1521

22+
it('should ignore files without extension', () => {
23+
const res = transformPlugin.transform('export default {}', 'test')
24+
expect(res?.code).toBeUndefined()
25+
})
26+
27+
it('should ignore files that are not components ', () => {
28+
const res = transformPlugin.transform('export default {}', 'some-other-file.ts')
29+
expect(res?.code).toBeUndefined()
30+
})
31+
32+
it('should process simple default exports', () => {
33+
const res = transformPlugin.transform('export default {}', 'test.vue')
34+
expect(res?.code).toMatchInlineSnapshot(`"export default Object.assign({}, { __name: "TestMe" })"`)
35+
})
36+
1637
it('should add correct default component names', () => {
1738
const sfc = `
1839
<script setup>

0 commit comments

Comments
 (0)
0