forked from nuxt/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(nuxt3): add tests, comments and example for components scan (nu…
…xt#1455) Co-authored-by: Pooya Parsa <pyapar@gmail.com>
- Loading branch information
Showing
9 changed files
with
183 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div> | ||
Awesome Component | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
import { defineNuxtConfig } from 'nuxt3' | ||
|
||
export default defineNuxtConfig({ | ||
vite: false | ||
vite: false, | ||
components: { | ||
dirs: [ | ||
'~/components', | ||
{ | ||
path: '~/other-components-folder', | ||
extensions: ['vue'], | ||
prefix: 'nuxt' | ||
} | ||
] | ||
} | ||
}) |
5 changes: 5 additions & 0 deletions
5
examples/with-components/other-components-folder/with-prefix.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div> | ||
Awesome Component | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div> | ||
This is HelloWorld component! | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<b style="color: #00C58E"> | ||
From Nuxt 3 | ||
</b> | ||
</template> |
5 changes: 5 additions & 0 deletions
5
packages/nuxt3/test/fixture/components/parent-folder/index.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div> | ||
Awesome Component | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { resolve } from 'path' | ||
import { ComponentsDir } from '@nuxt/kit' | ||
import { expect } from 'chai' | ||
import { scanComponents } from '../src/components/scan' | ||
|
||
const fixtureDir = resolve(__dirname, 'fixture') | ||
const rFixture = (...p) => resolve(fixtureDir, ...p) | ||
|
||
const dirs: ComponentsDir[] = [ | ||
{ | ||
path: rFixture('components'), | ||
level: 0, | ||
enabled: true, | ||
extensions: [ | ||
'vue' | ||
], | ||
pattern: '**/*.{vue,}', | ||
ignore: [ | ||
'**/*.stories.{js,ts,jsx,tsx}', | ||
'**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}', | ||
'**/*.d.ts' | ||
], | ||
transpile: false | ||
}, | ||
{ | ||
path: rFixture('components'), | ||
level: 0, | ||
enabled: true, | ||
extensions: [ | ||
'vue' | ||
], | ||
pattern: '**/*.{vue,}', | ||
ignore: [ | ||
'**/*.stories.{js,ts,jsx,tsx}', | ||
'**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}', | ||
'**/*.d.ts' | ||
], | ||
transpile: false | ||
}, | ||
{ | ||
path: rFixture('components'), | ||
extensions: [ | ||
'vue' | ||
], | ||
prefix: 'nuxt', | ||
level: 0, | ||
enabled: true, | ||
pattern: '**/*.{vue,}', | ||
ignore: [ | ||
'**/*.stories.{js,ts,jsx,tsx}', | ||
'**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}', | ||
'**/*.d.ts' | ||
], | ||
transpile: false | ||
} | ||
] | ||
|
||
const expectedComponents = [ | ||
{ | ||
pascalName: 'HelloWorld', | ||
kebabName: 'hello-world', | ||
chunkName: 'components/hello-world', | ||
shortPath: 'components/HelloWorld.vue', | ||
export: 'default', | ||
global: undefined, | ||
level: 0, | ||
prefetch: false, | ||
preload: false | ||
}, | ||
{ | ||
pascalName: 'Nuxt3', | ||
kebabName: 'nuxt3', | ||
chunkName: 'components/nuxt3', | ||
shortPath: 'components/Nuxt3.vue', | ||
export: 'default', | ||
global: undefined, | ||
level: 0, | ||
prefetch: false, | ||
preload: false | ||
}, | ||
{ | ||
pascalName: 'ParentFolder', | ||
kebabName: 'parent-folder', | ||
chunkName: 'components/parent-folder', | ||
shortPath: 'components/parent-folder/index.vue', | ||
export: 'default', | ||
global: undefined, | ||
level: 0, | ||
prefetch: false, | ||
preload: false | ||
} | ||
] | ||
|
||
const srcDir = rFixture('.') | ||
|
||
it('components:scanComponents', async () => { | ||
const scannedComponents = await scanComponents(dirs, srcDir) | ||
for (const c of scannedComponents) { | ||
delete c.filePath | ||
} | ||
expect(scannedComponents).deep.eq(expectedComponents) | ||
}) |