mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
91 lines
2.8 KiB
TypeScript
91 lines
2.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { applyDefaults } from 'untyped'
|
|
|
|
import { NuxtConfigSchema } from '../src'
|
|
import type { NuxtOptions } from '../src'
|
|
|
|
describe('nuxt folder structure', () => {
|
|
it('should resolve directories for v3 setup correctly', async () => {
|
|
const result = await applyDefaults(NuxtConfigSchema, {})
|
|
expect(getDirs(result as unknown as NuxtOptions)).toMatchInlineSnapshot(`
|
|
{
|
|
"dir": {
|
|
"app": "app",
|
|
"modules": "modules",
|
|
"public": "public",
|
|
},
|
|
"rootDir": "<cwd>",
|
|
"serverDir": "<cwd>/server",
|
|
"srcDir": "<cwd>",
|
|
"workspaceDir": "<cwd>",
|
|
}
|
|
`)
|
|
})
|
|
|
|
it('should resolve directories with a custom `srcDir` and `rootDir`', async () => {
|
|
const result = await applyDefaults(NuxtConfigSchema, { srcDir: 'src/', rootDir: '/test' })
|
|
expect(getDirs(result as unknown as NuxtOptions)).toMatchInlineSnapshot(`
|
|
{
|
|
"dir": {
|
|
"app": "app",
|
|
"modules": "modules",
|
|
"public": "public",
|
|
},
|
|
"rootDir": "/test",
|
|
"serverDir": "/test/src/server",
|
|
"srcDir": "/test/src",
|
|
"workspaceDir": "/test",
|
|
}
|
|
`)
|
|
})
|
|
|
|
it('should resolve directories when opting-in to v4 schema', async () => {
|
|
const result = await applyDefaults(NuxtConfigSchema, { future: { compatibilityVersion: 4 } })
|
|
expect(getDirs(result as unknown as NuxtOptions)).toMatchInlineSnapshot(`
|
|
{
|
|
"dir": {
|
|
"app": "<cwd>/app",
|
|
"modules": "<cwd>/modules",
|
|
"public": "<cwd>/public",
|
|
},
|
|
"rootDir": "<cwd>",
|
|
"serverDir": "<cwd>/server",
|
|
"srcDir": "<cwd>/app",
|
|
"workspaceDir": "<cwd>",
|
|
}
|
|
`)
|
|
})
|
|
|
|
it('should resolve directories when opting-in to v4 schema with a custom `srcDir` and `rootDir`', async () => {
|
|
const result = await applyDefaults(NuxtConfigSchema, { future: { compatibilityVersion: 4 }, srcDir: 'customApp/', rootDir: '/test' })
|
|
expect(getDirs(result as unknown as NuxtOptions)).toMatchInlineSnapshot(`
|
|
{
|
|
"dir": {
|
|
"app": "/test/customApp",
|
|
"modules": "/test/modules",
|
|
"public": "/test/public",
|
|
},
|
|
"rootDir": "/test",
|
|
"serverDir": "/test/server",
|
|
"srcDir": "/test/customApp",
|
|
"workspaceDir": "/test",
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
function getDirs (options: NuxtOptions) {
|
|
const stripRoot = (dir: string) => dir.replace(process.cwd(), '<cwd>')
|
|
return {
|
|
rootDir: stripRoot(options.rootDir),
|
|
serverDir: stripRoot(options.serverDir),
|
|
srcDir: stripRoot(options.srcDir),
|
|
dir: {
|
|
app: stripRoot(options.dir.app),
|
|
modules: stripRoot(options.dir.modules),
|
|
public: stripRoot(options.dir.public),
|
|
},
|
|
workspaceDir: stripRoot(options.workspaceDir!),
|
|
}
|
|
}
|