Skip to content

Commit a2b7c92

Browse files
committed
test: add missing coverage and fix mock return types
Add test for projectDirectoryExists check in custom mode validation path, which was only covered for full mode. Fix all exec/execFile mock return values from '' to undefined to match the actual Promise<void> signatures.
1 parent 687f8d5 commit a2b7c92

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

source/__tests__/nonInteractive.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,23 @@ describe('nonInteractive — validation', () => {
114114
expect(output.error).toMatch(/Unknown features: banana/)
115115
})
116116

117-
it('rejects when project directory already exists', async () => {
117+
it('rejects when project directory already exists (full mode)', async () => {
118118
vi.mocked(projectDirectoryExists).mockReturnValueOnce(true)
119119
await expect(runNonInteractive({ name: 'my_app', mode: 'full' })).rejects.toThrow()
120120
const output = getLastJsonOutput()
121121
expect(output.success).toBe(false)
122122
expect(output.error).toMatch(/already exists/)
123123
})
124+
125+
it('rejects when project directory already exists (custom mode)', async () => {
126+
vi.mocked(projectDirectoryExists).mockReturnValueOnce(true)
127+
await expect(
128+
runNonInteractive({ name: 'my_app', mode: 'custom', features: 'demo' }),
129+
).rejects.toThrow()
130+
const output = getLastJsonOutput()
131+
expect(output.success).toBe(false)
132+
expect(output.error).toMatch(/already exists/)
133+
})
124134
})
125135

126136
describe('nonInteractive — full mode execution', () => {

source/__tests__/operations/cleanupFiles.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
22
import type { FeatureName } from '../../constants/config.js'
33

44
vi.mock('../../operations/exec.js', () => ({
5-
exec: vi.fn().mockResolvedValue(''),
6-
execFile: vi.fn().mockResolvedValue(''),
5+
exec: vi.fn().mockResolvedValue(undefined),
6+
execFile: vi.fn().mockResolvedValue(undefined),
77
}))
88

99
vi.mock('node:fs', () => ({

source/__tests__/operations/cloneRepo.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
22
import { repoUrl } from '../../constants/config.js'
33

44
vi.mock('../../operations/exec.js', () => ({
5-
exec: vi.fn().mockResolvedValue(''),
6-
execFile: vi.fn().mockResolvedValue(''),
5+
exec: vi.fn().mockResolvedValue(undefined),
6+
execFile: vi.fn().mockResolvedValue(undefined),
77
}))
88

99
const { exec, execFile } = await import('../../operations/exec.js')
@@ -71,11 +71,9 @@ describe('cloneRepo', () => {
7171
const callOrder: string[] = []
7272
vi.mocked(execFile).mockImplementation(async (file, args) => {
7373
callOrder.push(`${file} ${args[0]}`)
74-
return ''
7574
})
7675
vi.mocked(exec).mockImplementation(async (_cmd) => {
7776
callOrder.push('git checkout')
78-
return ''
7977
})
8078

8179
await cloneRepo('my_app')

source/__tests__/operations/installPackages.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
22
import { featureDefinitions } from '../../constants/config.js'
33

44
vi.mock('../../operations/exec.js', () => ({
5-
exec: vi.fn().mockResolvedValue(''),
6-
execFile: vi.fn().mockResolvedValue(''),
5+
exec: vi.fn().mockResolvedValue(undefined),
6+
execFile: vi.fn().mockResolvedValue(undefined),
77
}))
88

99
const { execFile } = await import('../../operations/exec.js')
@@ -72,7 +72,6 @@ describe('installPackages', () => {
7272
if (args[0] === 'run' && args[1] === 'postinstall') {
7373
callOrder.push('postinstall')
7474
}
75-
return ''
7675
})
7776

7877
await installPackages('/project/my_app', 'custom', ['demo'])

0 commit comments

Comments
 (0)