2024-06-15 23:03:24 +00:00
|
|
|
import { fileURLToPath } from 'node:url'
|
2024-02-05 11:24:39 +00:00
|
|
|
import { resolve } from 'pathe'
|
2023-10-31 13:30:54 +00:00
|
|
|
import { expect, it, vi } from 'vitest'
|
2023-02-13 22:42:04 +00:00
|
|
|
import type { ComponentsDir } from 'nuxt/schema'
|
2021-11-15 16:22:46 +00:00
|
|
|
|
2023-10-16 21:58:40 +00:00
|
|
|
import { scanComponents } from '../src/components/scan'
|
2023-03-11 21:16:01 +00:00
|
|
|
|
2024-06-15 23:03:24 +00:00
|
|
|
const fixtureDir = fileURLToPath(new URL('fixture', import.meta.url))
|
2022-08-22 10:12:02 +00:00
|
|
|
const rFixture = (...p: string[]) => resolve(fixtureDir, ...p)
|
2021-11-15 16:22:46 +00:00
|
|
|
|
2022-02-28 16:11:46 +00:00
|
|
|
vi.mock('@nuxt/kit', () => ({
|
2024-04-05 18:08:32 +00:00
|
|
|
isIgnored: () => false,
|
2022-02-28 16:11:46 +00:00
|
|
|
}))
|
|
|
|
|
2021-11-15 16:22:46 +00:00
|
|
|
const dirs: ComponentsDir[] = [
|
2022-11-24 12:24:14 +00:00
|
|
|
{
|
|
|
|
path: rFixture('components/islands'),
|
|
|
|
enabled: true,
|
|
|
|
extensions: [
|
2024-04-05 18:08:32 +00:00
|
|
|
'vue',
|
2022-11-24 12:24:14 +00:00
|
|
|
],
|
|
|
|
pattern: '**/*.{vue,}',
|
|
|
|
ignore: [
|
|
|
|
'**/*.stories.{js,ts,jsx,tsx}',
|
|
|
|
'**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}',
|
2024-04-05 18:08:32 +00:00
|
|
|
'**/*.d.ts',
|
2022-11-24 12:24:14 +00:00
|
|
|
],
|
|
|
|
transpile: false,
|
2024-04-05 18:08:32 +00:00
|
|
|
island: true,
|
2022-11-24 12:24:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: rFixture('components/global'),
|
|
|
|
enabled: true,
|
|
|
|
extensions: [
|
2024-04-05 18:08:32 +00:00
|
|
|
'vue',
|
2022-11-24 12:24:14 +00:00
|
|
|
],
|
|
|
|
pattern: '**/*.{vue,}',
|
|
|
|
ignore: [
|
|
|
|
'**/*.stories.{js,ts,jsx,tsx}',
|
|
|
|
'**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}',
|
2024-04-05 18:08:32 +00:00
|
|
|
'**/*.d.ts',
|
2022-11-24 12:24:14 +00:00
|
|
|
],
|
|
|
|
transpile: false,
|
2024-04-05 18:08:32 +00:00
|
|
|
global: true,
|
2022-11-24 12:24:14 +00:00
|
|
|
},
|
2021-11-15 16:22:46 +00:00
|
|
|
{
|
|
|
|
path: rFixture('components'),
|
|
|
|
enabled: true,
|
|
|
|
extensions: [
|
2024-04-05 18:08:32 +00:00
|
|
|
'vue',
|
2021-11-15 16:22:46 +00:00
|
|
|
],
|
|
|
|
pattern: '**/*.{vue,}',
|
|
|
|
ignore: [
|
|
|
|
'**/*.stories.{js,ts,jsx,tsx}',
|
|
|
|
'**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}',
|
2024-04-05 18:08:32 +00:00
|
|
|
'**/*.d.ts',
|
2021-11-15 16:22:46 +00:00
|
|
|
],
|
2024-04-05 18:08:32 +00:00
|
|
|
transpile: false,
|
2021-11-15 16:22:46 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: rFixture('components'),
|
|
|
|
enabled: true,
|
|
|
|
extensions: [
|
2024-04-05 18:08:32 +00:00
|
|
|
'vue',
|
2021-11-15 16:22:46 +00:00
|
|
|
],
|
|
|
|
pattern: '**/*.{vue,}',
|
|
|
|
ignore: [
|
|
|
|
'**/*.stories.{js,ts,jsx,tsx}',
|
|
|
|
'**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}',
|
2024-04-05 18:08:32 +00:00
|
|
|
'**/*.d.ts',
|
2021-11-15 16:22:46 +00:00
|
|
|
],
|
2024-04-05 18:08:32 +00:00
|
|
|
transpile: false,
|
2021-11-15 16:22:46 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: rFixture('components'),
|
|
|
|
extensions: [
|
2024-04-05 18:08:32 +00:00
|
|
|
'vue',
|
2021-11-15 16:22:46 +00:00
|
|
|
],
|
|
|
|
prefix: 'nuxt',
|
|
|
|
enabled: true,
|
|
|
|
pattern: '**/*.{vue,}',
|
|
|
|
ignore: [
|
|
|
|
'**/*.stories.{js,ts,jsx,tsx}',
|
|
|
|
'**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}',
|
2024-04-05 18:08:32 +00:00
|
|
|
'**/*.d.ts',
|
2021-11-15 16:22:46 +00:00
|
|
|
],
|
2024-04-05 18:08:32 +00:00
|
|
|
transpile: false,
|
|
|
|
},
|
2021-11-15 16:22:46 +00:00
|
|
|
]
|
2024-04-23 12:19:12 +00:00
|
|
|
const dirUnable = dirs.map((d) => { return { ...d, enabled: false } })
|
2021-11-15 16:22:46 +00:00
|
|
|
const expectedComponents = [
|
2022-11-24 12:24:14 +00:00
|
|
|
{
|
|
|
|
chunkName: 'components/isle-server',
|
|
|
|
export: 'default',
|
|
|
|
global: undefined,
|
|
|
|
island: true,
|
|
|
|
kebabName: 'isle',
|
|
|
|
mode: 'server',
|
|
|
|
pascalName: 'Isle',
|
|
|
|
prefetch: false,
|
|
|
|
preload: false,
|
2023-03-06 11:33:40 +00:00
|
|
|
priority: 1,
|
2024-04-05 18:08:32 +00:00
|
|
|
shortPath: 'components/islands/Isle.vue',
|
2022-11-24 12:24:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
chunkName: 'components/glob',
|
|
|
|
export: 'default',
|
|
|
|
global: true,
|
|
|
|
island: undefined,
|
|
|
|
kebabName: 'glob',
|
|
|
|
mode: 'all',
|
|
|
|
pascalName: 'Glob',
|
|
|
|
prefetch: false,
|
|
|
|
preload: false,
|
2023-03-06 11:33:40 +00:00
|
|
|
priority: 1,
|
2024-04-05 18:08:32 +00:00
|
|
|
shortPath: 'components/global/Glob.vue',
|
2022-11-24 12:24:14 +00:00
|
|
|
},
|
2021-11-15 16:22:46 +00:00
|
|
|
{
|
2022-04-19 19:13:55 +00:00
|
|
|
mode: 'all',
|
2021-11-15 16:22:46 +00:00
|
|
|
pascalName: 'HelloWorld',
|
|
|
|
kebabName: 'hello-world',
|
|
|
|
chunkName: 'components/hello-world',
|
|
|
|
shortPath: 'components/HelloWorld.vue',
|
|
|
|
export: 'default',
|
|
|
|
global: undefined,
|
2022-11-24 12:24:14 +00:00
|
|
|
island: undefined,
|
2021-11-15 16:22:46 +00:00
|
|
|
prefetch: false,
|
2023-03-06 11:33:40 +00:00
|
|
|
preload: false,
|
2024-04-05 18:08:32 +00:00
|
|
|
priority: 1,
|
2021-11-15 16:22:46 +00:00
|
|
|
},
|
|
|
|
{
|
2022-04-19 19:13:55 +00:00
|
|
|
mode: 'client',
|
2021-11-15 16:22:46 +00:00
|
|
|
pascalName: 'Nuxt3',
|
|
|
|
kebabName: 'nuxt3',
|
2022-04-19 19:13:55 +00:00
|
|
|
chunkName: 'components/nuxt3-client',
|
|
|
|
shortPath: 'components/Nuxt3.client.vue',
|
2021-11-15 16:22:46 +00:00
|
|
|
export: 'default',
|
|
|
|
global: undefined,
|
2022-11-24 12:24:14 +00:00
|
|
|
island: undefined,
|
2021-11-15 16:22:46 +00:00
|
|
|
prefetch: false,
|
2023-03-06 11:33:40 +00:00
|
|
|
preload: false,
|
2024-04-05 18:08:32 +00:00
|
|
|
priority: 1,
|
2021-11-15 16:22:46 +00:00
|
|
|
},
|
|
|
|
{
|
2022-04-19 19:13:55 +00:00
|
|
|
mode: 'server',
|
|
|
|
pascalName: 'Nuxt3',
|
|
|
|
kebabName: 'nuxt3',
|
|
|
|
chunkName: 'components/nuxt3-server',
|
|
|
|
shortPath: 'components/Nuxt3.server.vue',
|
|
|
|
export: 'default',
|
|
|
|
global: undefined,
|
2022-11-24 12:24:14 +00:00
|
|
|
island: undefined,
|
2022-04-19 19:13:55 +00:00
|
|
|
prefetch: false,
|
2023-03-06 11:33:40 +00:00
|
|
|
preload: false,
|
2024-04-05 18:08:32 +00:00
|
|
|
priority: 1,
|
2022-04-19 19:13:55 +00:00
|
|
|
},
|
2023-02-16 12:47:42 +00:00
|
|
|
{
|
|
|
|
chunkName: 'components/client-component-with-props',
|
|
|
|
export: 'default',
|
|
|
|
global: undefined,
|
|
|
|
island: undefined,
|
|
|
|
kebabName: 'client-component-with-props',
|
|
|
|
mode: 'all',
|
|
|
|
pascalName: 'ClientComponentWithProps',
|
|
|
|
prefetch: false,
|
|
|
|
preload: false,
|
2023-03-06 11:33:40 +00:00
|
|
|
priority: 1,
|
2024-04-05 18:08:32 +00:00
|
|
|
shortPath: 'components/client/ComponentWithProps.vue',
|
2023-02-16 12:47:42 +00:00
|
|
|
},
|
2023-02-08 08:59:57 +00:00
|
|
|
{
|
|
|
|
chunkName: 'components/client-with-client-only-setup',
|
|
|
|
export: 'default',
|
|
|
|
global: undefined,
|
|
|
|
island: undefined,
|
|
|
|
kebabName: 'client-with-client-only-setup',
|
|
|
|
mode: 'all',
|
|
|
|
pascalName: 'ClientWithClientOnlySetup',
|
|
|
|
prefetch: false,
|
|
|
|
preload: false,
|
2023-03-06 11:33:40 +00:00
|
|
|
priority: 1,
|
2024-04-05 18:08:32 +00:00
|
|
|
shortPath: 'components/client/WithClientOnlySetup.vue',
|
2023-02-08 08:59:57 +00:00
|
|
|
},
|
2022-04-19 19:13:55 +00:00
|
|
|
{
|
|
|
|
mode: 'server',
|
2021-11-15 16:22:46 +00:00
|
|
|
pascalName: 'ParentFolder',
|
|
|
|
kebabName: 'parent-folder',
|
2022-04-19 19:13:55 +00:00
|
|
|
chunkName: 'components/parent-folder-server',
|
|
|
|
shortPath: 'components/parent-folder/index.server.vue',
|
2021-11-15 16:22:46 +00:00
|
|
|
export: 'default',
|
|
|
|
global: undefined,
|
2022-11-24 12:24:14 +00:00
|
|
|
island: undefined,
|
2021-11-15 16:22:46 +00:00
|
|
|
prefetch: false,
|
2023-03-06 11:33:40 +00:00
|
|
|
preload: false,
|
2024-04-05 18:08:32 +00:00
|
|
|
priority: 1,
|
2022-11-24 12:24:14 +00:00
|
|
|
},
|
2023-05-15 12:34:04 +00:00
|
|
|
{
|
|
|
|
chunkName: 'components/same-name-same',
|
|
|
|
export: 'default',
|
|
|
|
global: undefined,
|
|
|
|
island: undefined,
|
|
|
|
kebabName: 'same-name-same',
|
|
|
|
mode: 'all',
|
|
|
|
pascalName: 'SameNameSame',
|
|
|
|
prefetch: false,
|
|
|
|
preload: false,
|
|
|
|
priority: 1,
|
2024-04-05 18:08:32 +00:00
|
|
|
shortPath: 'components/same-name/same/Same.vue',
|
2023-05-15 12:34:04 +00:00
|
|
|
},
|
2022-11-24 12:24:14 +00:00
|
|
|
{
|
|
|
|
chunkName: 'components/some-glob',
|
|
|
|
export: 'default',
|
|
|
|
global: true,
|
|
|
|
island: undefined,
|
|
|
|
kebabName: 'some-glob',
|
|
|
|
mode: 'all',
|
|
|
|
pascalName: 'SomeGlob',
|
|
|
|
prefetch: false,
|
|
|
|
preload: false,
|
2023-03-06 11:33:40 +00:00
|
|
|
priority: 1,
|
2024-04-05 18:08:32 +00:00
|
|
|
shortPath: 'components/some-glob.global.vue',
|
2022-11-24 12:24:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
chunkName: 'components/some-server',
|
|
|
|
export: 'default',
|
|
|
|
global: undefined,
|
|
|
|
island: true,
|
|
|
|
kebabName: 'some',
|
|
|
|
mode: 'server',
|
|
|
|
pascalName: 'Some',
|
|
|
|
prefetch: false,
|
|
|
|
preload: false,
|
2023-03-06 11:33:40 +00:00
|
|
|
priority: 1,
|
2024-04-05 18:08:32 +00:00
|
|
|
shortPath: 'components/some.island.vue',
|
|
|
|
},
|
2021-11-15 16:22:46 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
const srcDir = rFixture('.')
|
|
|
|
|
|
|
|
it('components:scanComponents', async () => {
|
|
|
|
const scannedComponents = await scanComponents(dirs, srcDir)
|
|
|
|
for (const c of scannedComponents) {
|
2023-04-14 12:53:21 +00:00
|
|
|
// @ts-expect-error filePath is not optional but we don't want it to be in the snapshot
|
2021-11-15 16:22:46 +00:00
|
|
|
delete c.filePath
|
2024-09-05 15:38:43 +00:00
|
|
|
// @ts-expect-error _scanned is added internally but we don't want it to be in the snapshot
|
|
|
|
delete c._scanned
|
2021-11-15 16:22:46 +00:00
|
|
|
}
|
|
|
|
expect(scannedComponents).deep.eq(expectedComponents)
|
|
|
|
})
|
2024-04-23 12:19:12 +00:00
|
|
|
|
|
|
|
it('components:scanComponents:unable', async () => {
|
|
|
|
const scannedComponents = await scanComponents(dirUnable, srcDir)
|
|
|
|
expect(scannedComponents).deep.eq([])
|
|
|
|
})
|