|
| 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