Skip to content

Commit a772c2a

Browse files
committed
test: add some basic e2e tests
1 parent eb3087d commit a772c2a

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const main = defineCommand({
2121
...cwdArgs,
2222
command: {
2323
type: 'positional',
24+
required: false,
2425
},
2526
},
2627
subCommands: commands,

test/e2e/commands.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type { TestFunction } from 'vitest'
2+
import type { commands } from '../../src/commands'
3+
4+
import { spawnSync } from 'node:child_process'
5+
6+
import { fileURLToPath } from 'node:url'
7+
import { describe, expect, it } from 'vitest'
8+
9+
const fixtureDir = fileURLToPath(new URL('../../playground', import.meta.url))
10+
11+
describe('commands', () => {
12+
const tests: Record<keyof typeof commands, 'todo' | TestFunction<object>> = {
13+
_dev: 'todo',
14+
add: 'todo',
15+
analyze: 'todo',
16+
build: 'todo',
17+
cleanup: 'todo',
18+
devtools: 'todo',
19+
module: 'todo',
20+
prepare: 'todo',
21+
preview: 'todo',
22+
start: 'todo',
23+
test: 'todo',
24+
typecheck: 'todo',
25+
upgrade: 'todo',
26+
dev: 'todo',
27+
generate: 'todo',
28+
init: 'todo',
29+
info: 'todo',
30+
}
31+
32+
it('throws error if no command is provided', async () => {
33+
const res = spawnSync('pnpm', ['nuxi'], {
34+
cwd: fixtureDir,
35+
})
36+
expect(res.status).toBe(1)
37+
expect(res.stderr.toString()).toBe('[error] No command specified.\n')
38+
})
39+
40+
it('throws error if wrong command is provided', async () => {
41+
const res = spawnSync('pnpm', ['nuxi', 'foo'], {
42+
cwd: fixtureDir,
43+
})
44+
expect(res.status).toBe(1)
45+
expect(res.stderr.toString()).toBe('[error] Unknown command `foo`\n')
46+
})
47+
48+
const testsToRun = Object.entries(tests).filter(([_, value]) => value !== 'todo')
49+
it.each(testsToRun)(`%s`, (_, test) => (test as () => Promise<void>)())
50+
51+
for (const [command, value] of Object.entries(tests)) {
52+
if (value === 'todo') {
53+
it.todo(command)
54+
}
55+
}
56+
})

0 commit comments

Comments
 (0)