@@ -5,28 +5,34 @@ import { dirname, join } from 'path'
55import { readFileSync } from 'fs'
66import { fileURLToPath } from 'url'
77
8+ const __filename = fileURLToPath ( import . meta. url )
9+ const __dirname = dirname ( __filename )
10+
811// Get package.json data using a function to avoid top-level await
912function getPackageJson ( ) {
10- const __filename = fileURLToPath ( import . meta. url )
11- const __dirname = dirname ( __filename )
1213 return JSON . parse ( readFileSync ( join ( __dirname , '../../package.json' ) , 'utf8' ) )
1314}
1415
1516const pkg = getPackageJson ( )
1617
18+ // Helper function to run the CLI using tsx (TypeScript executor)
19+ function runCLI ( args = '' ) {
20+ return execSync ( `tsx ${ join ( __dirname , '../index.ts' ) } ${ args } ` , { encoding : 'utf8' } )
21+ }
22+
1723describe ( 'CLI' , ( ) => {
1824 test ( 'version command should display correct version information' , ( ) => {
19- // Run the CLI with the version command
20- const output = execSync ( 'node dist/index.js version', { encoding : 'utf8' } )
25+ // Run the CLI with the version command directly from TypeScript source
26+ const output = runCLI ( ' version')
2127
2228 // Verify the output contains version information and package details
2329 expect ( output ) . toContain ( pkg . name )
2430 expect ( output ) . toContain ( pkg . version )
2531 } )
2632
2733 test ( 'CLI should show help when no arguments are provided' , ( ) => {
28- // Run the CLI without any arguments
29- const output = execSync ( 'node dist/index.js' , { encoding : 'utf8' } )
34+ // Run the CLI without any arguments directly from TypeScript source
35+ const output = runCLI ( '' )
3036
3137 // Verify the output contains help information
3238 expect ( output ) . toContain ( 'Usage:' )
0 commit comments