1+ import { spawnSync } from 'node:child_process'
2+ import { readFileSync } from 'node:fs'
3+ import { fileURLToPath } from 'node:url'
4+
5+ const cliPath = fileURLToPath ( new URL ( '../cli.js' , import . meta. url ) )
6+ const packageJson = JSON . parse ( readFileSync ( new URL ( '../package.json' , import . meta. url ) , 'utf8' ) )
7+
8+ /**
9+ * Run the CLI in a child process so the entrypoint is exercised end to end.
10+ * @param {string[] } args - CLI arguments
11+ * @returns {import('node:child_process').SpawnSyncReturns<string> } Child process result
12+ */
13+ function runCli ( args ) {
14+ return spawnSync ( process . execPath , [ cliPath , ...args ] , {
15+ encoding : 'utf8' ,
16+ env : {
17+ ...process . env ,
18+ DEBUG : 'false' ,
19+ GITHUB_TOKEN : '' ,
20+ } ,
21+ } )
22+ }
23+
124describe ( 'cli' , ( ) => {
225 beforeEach ( ( ) => { } )
326
@@ -7,13 +30,22 @@ describe('cli', () => {
730 * Test CLI help functionality
831 */
932 test ( 'should display help information with --help flag' , ( ) => {
10- // TODO: Implement test logic
33+ const result = runCli ( [ '--help' ] )
34+
35+ expect ( result . status ) . toBe ( 0 )
36+ expect ( result . stdout ) . toContain ( 'Usage' )
37+ expect ( result . stdout ) . toContain ( 'action-reporting-cli' )
1138 } )
1239
1340 /**
1441 * Test CLI version functionality
1542 */
1643 test ( 'should display version information with --version flag' , ( ) => {
17- // TODO: Implement test logic
44+ const result = runCli ( [ '--version' ] )
45+ const outputLines = result . stdout . trim ( ) . split ( '\n' )
46+ const lastLine = outputLines [ outputLines . length - 1 ]
47+
48+ expect ( result . status ) . toBe ( 0 )
49+ expect ( lastLine ) . toBe ( packageJson . version )
1850 } )
1951} )
0 commit comments