From 0353609d22717a50cd001e62d92238592199228a Mon Sep 17 00:00:00 2001 From: Ahmed Magdy Date: Fri, 17 Apr 2026 17:24:08 +0200 Subject: [PATCH] Fix an error with meow in cli.js --- .gitignore | 1 + cli.js | 1 - test/cli.test.js | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index fab6258..9b628b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ cache/ reports/ +.DS_Store # Created by https://www.toptal.com/developers/gitignore/api/node # Edit at https://www.toptal.com/developers/gitignore?templates=node diff --git a/cli.js b/cli.js index 85c80f8..3602b78 100755 --- a/cli.js +++ b/cli.js @@ -194,7 +194,6 @@ const cli = meow(createHelpText(), { allowUnknownFlags: false, importMeta: import.meta, inferType: false, - input: [], flags: CLI_FLAGS, }) diff --git a/test/cli.test.js b/test/cli.test.js index 88444a5..655b9d6 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -1,3 +1,26 @@ +import {spawnSync} from 'node:child_process' +import {readFileSync} from 'node:fs' +import {fileURLToPath} from 'node:url' + +const cliPath = fileURLToPath(new URL('../cli.js', import.meta.url)) +const packageJson = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')) + +/** + * Run the CLI in a child process so the entrypoint is exercised end to end. + * @param {string[]} args - CLI arguments + * @returns {import('node:child_process').SpawnSyncReturns} Child process result + */ +function runCli(args) { + return spawnSync(process.execPath, [cliPath, ...args], { + encoding: 'utf8', + env: { + ...process.env, + DEBUG: 'false', + GITHUB_TOKEN: '', + }, + }) +} + describe('cli', () => { beforeEach(() => {}) @@ -7,13 +30,22 @@ describe('cli', () => { * Test CLI help functionality */ test('should display help information with --help flag', () => { - // TODO: Implement test logic + const result = runCli(['--help']) + + expect(result.status).toBe(0) + expect(result.stdout).toContain('Usage') + expect(result.stdout).toContain('action-reporting-cli') }) /** * Test CLI version functionality */ test('should display version information with --version flag', () => { - // TODO: Implement test logic + const result = runCli(['--version']) + const outputLines = result.stdout.trim().split('\n') + const lastLine = outputLines[outputLines.length - 1] + + expect(result.status).toBe(0) + expect(lastLine).toBe(packageJson.version) }) })