Skip to content

Commit f850a17

Browse files
committed
test(generate): cover build overrides
1 parent 8db925e commit f850a17

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { runCommand } from 'citty'
2+
import { beforeEach, describe, expect, it, vi } from 'vitest'
3+
4+
import generate from '../../../src/commands/generate'
5+
6+
const { loadNuxt, buildNuxt, writeTypes, clearBuildDir } = vi.hoisted(() => ({
7+
loadNuxt: vi.fn(),
8+
buildNuxt: vi.fn(),
9+
writeTypes: vi.fn(),
10+
clearBuildDir: vi.fn(),
11+
}))
12+
13+
vi.mock('@clack/prompts', async importOriginal => ({
14+
...await importOriginal<typeof import('@clack/prompts')>(),
15+
intro: vi.fn(),
16+
outro: vi.fn(),
17+
}))
18+
vi.mock('../../../src/utils/banner', () => ({ showBanner: vi.fn() }))
19+
vi.mock('../../../src/utils/env', () => ({ overrideEnv: vi.fn() }))
20+
vi.mock('../../../src/utils/fs', () => ({ clearBuildDir }))
21+
vi.mock('../../../src/utils/kit', () => ({
22+
loadKit: () => Promise.resolve({
23+
loadNuxt,
24+
buildNuxt,
25+
writeTypes,
26+
useNitro: () => ({
27+
options: {
28+
preset: 'static',
29+
output: {
30+
dir: '/project/dist',
31+
publicDir: '/project/dist',
32+
},
33+
},
34+
}),
35+
}),
36+
}))
37+
vi.mock('../../../src/utils/lockfile', () => ({
38+
acquireLock: () => ({ release: vi.fn() }),
39+
acquireOutputLock: () => ({ release: vi.fn() }),
40+
formatLockError: vi.fn(),
41+
}))
42+
43+
beforeEach(() => {
44+
vi.clearAllMocks()
45+
loadNuxt.mockResolvedValue({
46+
hook: vi.fn(),
47+
ready: vi.fn(),
48+
options: {
49+
buildDir: '/project/.nuxt',
50+
rootDir: '/project',
51+
ssr: true,
52+
},
53+
})
54+
})
55+
56+
describe('generate', () => {
57+
it('enables Nuxt generation and Nitro static output', async () => {
58+
await runCommand(generate, { rawArgs: ['/project'] })
59+
60+
expect(loadNuxt).toHaveBeenCalledWith(expect.objectContaining({
61+
cwd: '/project',
62+
overrides: expect.objectContaining({
63+
_generate: true,
64+
nitro: expect.objectContaining({ static: true }),
65+
}),
66+
}))
67+
expect(clearBuildDir).toHaveBeenCalledWith('/project/.nuxt')
68+
expect(writeTypes).toHaveBeenCalled()
69+
expect(buildNuxt).toHaveBeenCalled()
70+
})
71+
72+
it('does not expose the build-only prerender option', () => {
73+
expect(generate.args).not.toHaveProperty('prerender')
74+
})
75+
})

0 commit comments

Comments
 (0)