Skip to content

Commit

Permalink
Add smoke tests for CLI
Browse files Browse the repository at this point in the history
- Introduced `smoke.test.ts` to verify that the CLI tool can run essential commands without errors.
- Includes tests for basic CLI usage and ERD command execution, checking for expected output.
  • Loading branch information
hoshinotsuyoshi committed Nov 12, 2024
1 parent fa41fad commit 841863b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions frontend/packages/cli/src/cli/smoke.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { exec } from 'node:child_process'
import { promisify } from 'node:util'
import { beforeAll, describe, expect, it } from 'vitest'

const execAsync = promisify(exec)

beforeAll(async () => {
await execAsync('rm -rf ./dist-cli/ ./node_modules/.tmp')
await execAsync('pnpm run build:cli')
})

describe('CLI Smoke Test', () => {
it('should run the CLI command without errors', async () => {
try {
const { stdout, stderr } = await execAsync('npx --no-install . help')
expect(stderr).toBe('')
expect(stdout).toEqual(
`Usage: liam [options] [command]
CLI tool for Liam
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
erd ERD commands
help [command] display help for command
`,
)
} catch (error) {
// Fail the test if an error occurs
expect(error).toBeNull()
}
})

it('should run the CLI command without errors', async () => {
await execAsync('rm -rf ./dist')
try {
const { stdout, stderr } = await execAsync(
'npx --no-install . erd build --input fixtures/input.sql',
)
expect(stderr).toBe('')
expect(stdout).toContain('building for production')
expect(stdout).toContain('✓ built in')
const { stdout: lsOutput } = await execAsync('ls ./dist')
expect(lsOutput.trim().length).toBeGreaterThan(0)
} catch (error) {
// Fail the test if an error occurs
expect(error).toBeNull()
} finally {
await execAsync('rm -rf ./dist')
}
})
})

0 comments on commit 841863b

Please sign in to comment.