From fcf593bcd53ef8c58588a5039698fc3754c34ba9 Mon Sep 17 00:00:00 2001 From: hoshinotsuyoshi Date: Tue, 19 Nov 2024 17:33:14 +0900 Subject: [PATCH] WIP --- .../cli/src/cli/runPreprocess.test.ts | 2 +- .../packages/cli/src/cli/runPreprocess.ts | 8 +++++-- frontend/packages/cli/src/cli/smoke.test.ts | 24 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/frontend/packages/cli/src/cli/runPreprocess.test.ts b/frontend/packages/cli/src/cli/runPreprocess.test.ts index 236f355d2..ace267a3d 100644 --- a/frontend/packages/cli/src/cli/runPreprocess.test.ts +++ b/frontend/packages/cli/src/cli/runPreprocess.test.ts @@ -26,7 +26,7 @@ describe('runPreprocess', () => { const nonExistentPath = path.join(tmpDir, 'non-existent.sql') expect(() => runPreprocess(nonExistentPath, tmpDir)).toThrow( - 'Invalid input path. Please provide a valid .sql file.', + 'Invalid input path. Please provide a valid file.', ) }) diff --git a/frontend/packages/cli/src/cli/runPreprocess.ts b/frontend/packages/cli/src/cli/runPreprocess.ts index b2713f444..6a211a312 100644 --- a/frontend/packages/cli/src/cli/runPreprocess.ts +++ b/frontend/packages/cli/src/cli/runPreprocess.ts @@ -4,11 +4,15 @@ import { parse } from '@liam/db-structure' export function runPreprocess(inputPath: string | null, publicDir: string) { if (inputPath && !fs.existsSync(inputPath)) { - throw new Error('Invalid input path. Please provide a valid .sql file.') + throw new Error('Invalid input path. Please provide a valid file.') } const input = inputPath ? readFileSync(inputPath, 'utf8') : '' - const json = parse(input, 'schemarb') + + // TODO: Expand support to additional formats, e.g., 'postgres' + const format = 'schemarb' + const json = parse(input, format) + const filePath = path.join(publicDir, 'schema.json') if (!fs.existsSync(publicDir)) { diff --git a/frontend/packages/cli/src/cli/smoke.test.ts b/frontend/packages/cli/src/cli/smoke.test.ts index 56aec0664..3fc414bd0 100644 --- a/frontend/packages/cli/src/cli/smoke.test.ts +++ b/frontend/packages/cli/src/cli/smoke.test.ts @@ -10,6 +10,30 @@ beforeAll(async () => { }) 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).toMatchInlineSnapshot(` + "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 {