44 * Focuses on CLI-specific functionality and parsing behavior.
55 */
66
7+ import { start , type ServerInstance } from '../src/index' ;
78import { OPTIONS , parseCliOptions , setOptions } from '../src/options' ;
89
910describe ( 'CLI Functionality' , ( ) => {
1011 let originalArgv : string [ ] ;
12+ let serverInstances : ServerInstance [ ] = [ ] ;
1113
1214 beforeEach ( ( ) => {
1315 // Store original process.argv
1416 originalArgv = process . argv ;
17+ // Clear server instances array
18+ serverInstances = [ ] ;
1519 } ) ;
1620
17- afterEach ( ( ) => {
21+ afterEach ( async ( ) => {
22+ // Clean up all server instances
23+ for ( const server of serverInstances ) {
24+ if ( server . isRunning ( ) ) {
25+ await server . stop ( ) ;
26+ }
27+ }
28+ serverInstances = [ ] ;
29+
1830 // Restore original process.argv
1931 process . argv = originalArgv ;
2032 } ) ;
@@ -28,9 +40,11 @@ describe('CLI Functionality', () => {
2840
2941 expect ( cliOptions . docsHost ) . toBe ( true ) ;
3042
31- // Test setOptions() with CLI options
32- setOptions ( cliOptions ) ;
43+ // Test start() with CLI options
44+ const server = await start ( cliOptions ) ;
45+ serverInstances . push ( server ) ;
3346 expect ( OPTIONS . docsHost ) . toBe ( true ) ;
47+ expect ( server . isRunning ( ) ) . toBe ( true ) ;
3448 } ) ;
3549
3650 it ( 'should handle CLI without --docs-host flag' , async ( ) => {
@@ -41,13 +55,11 @@ describe('CLI Functionality', () => {
4155
4256 expect ( cliOptions . docsHost ) . toBe ( false ) ;
4357
44- // Test setOptions with CLI options
45- setOptions ( cliOptions ) ;
46- expect ( OPTIONS . docsHost ) . toBe ( false ) ;
47-
48- // Test setOptions() with CLI options
49- setOptions ( cliOptions ) ;
58+ // Test start() with CLI options
59+ const server = await start ( cliOptions ) ;
60+ serverInstances . push ( server ) ;
5061 expect ( OPTIONS . docsHost ) . toBe ( false ) ;
62+ expect ( server . isRunning ( ) ) . toBe ( true ) ;
5163 } ) ;
5264
5365 it ( 'should handle CLI with other arguments' , async ( ) => {
@@ -58,35 +70,35 @@ describe('CLI Functionality', () => {
5870
5971 expect ( cliOptions . docsHost ) . toBe ( false ) ;
6072
61- // Test setOptions with CLI options
62- setOptions ( cliOptions ) ;
63- expect ( OPTIONS . docsHost ) . toBe ( false ) ;
64-
65- // Test setOptions() with CLI options
66- setOptions ( cliOptions ) ;
73+ // Test start() with CLI options
74+ const server = await start ( cliOptions ) ;
75+ serverInstances . push ( server ) ;
6776 expect ( OPTIONS . docsHost ) . toBe ( false ) ;
77+ expect ( server . isRunning ( ) ) . toBe ( true ) ;
6878 } ) ;
6979
7080 it ( 'should handle multiple CLI calls' , async ( ) => {
7181 // First CLI call with --docs-host
7282 process . argv = [ 'node' , 'script.js' , '--docs-host' ] ;
7383 const cliOptions1 = parseCliOptions ( ) ;
7484
75- setOptions ( cliOptions1 ) ;
76- setOptions ( cliOptions1 ) ;
85+ const server1 = await start ( cliOptions1 ) ;
86+ serverInstances . push ( server1 ) ;
7787
7888 expect ( cliOptions1 . docsHost ) . toBe ( true ) ;
7989 expect ( OPTIONS . docsHost ) . toBe ( true ) ;
90+ expect ( server1 . isRunning ( ) ) . toBe ( true ) ;
8091
8192 // Second CLI call without --docs-host
8293 process . argv = [ 'node' , 'script.js' ] ;
8394 const cliOptions2 = parseCliOptions ( ) ;
8495
85- setOptions ( cliOptions2 ) ;
86- setOptions ( cliOptions2 ) ;
96+ const server2 = await start ( cliOptions2 ) ;
97+ serverInstances . push ( server2 ) ;
8798
8899 expect ( cliOptions2 . docsHost ) . toBe ( false ) ;
89100 expect ( OPTIONS . docsHost ) . toBe ( false ) ;
101+ expect ( server2 . isRunning ( ) ) . toBe ( true ) ;
90102 } ) ;
91103 } ) ;
92104} ) ;
0 commit comments