@@ -268,74 +268,6 @@ test('CLI script handles different target directories', async () => {
268268 }
269269} ) ;
270270
271- test ( 'CLI script imports and executes library CLI' , async ( ) => {
272- const testDir = createTestDir ( ) ;
273-
274- try {
275- // Create a minimal package.json
276- const packageJson = { name : 'test' , version : '1.0.0' } ;
277- fs . writeFileSync ( path . join ( testDir , 'package.json' ) , JSON . stringify ( packageJson ) ) ;
278-
279- // Create mock node_modules structure
280- const nodeModulesDir = path . join ( testDir , 'node_modules' , '@austinserb' , 'react-zero-ui' ) ;
281- fs . mkdirSync ( nodeModulesDir , { recursive : true } ) ;
282-
283- // Create mock CLI module that matches the actual structure
284- const mockCLI = `
285- // Mock implementation of the CLI
286- async function runZeroUiInit() {
287- console.log('Mock CLI executed successfully');
288- }
289-
290- function cli(argv = process.argv.slice(2)) {
291- await runZeroUiInit(argv);
292- return Promise.resolve();
293- }
294-
295- module.exports = cli;
296- module.exports.default = cli;
297- ` ;
298-
299- fs . writeFileSync ( path . join ( nodeModulesDir , 'cli.cjs' ) , mockCLI ) ;
300-
301- // Create package.json for the mock module
302- const mockPackageJson = {
303- name : '@react-zero-ui/core' ,
304- main : 'index.js' ,
305- exports : { './cli' : { types : './cli.d.ts' , require : './cli.cjs' , import : './cli.cjs' } } ,
306- } ;
307- fs . writeFileSync ( path . join ( nodeModulesDir , 'package.json' ) , JSON . stringify ( mockPackageJson ) ) ;
308-
309- // Mock npm to avoid actual installation
310- const mockNpmScript = `#!/bin/bash\necho "Mock npm install completed"` ;
311- const mockNpmPath = path . join ( testDir , 'npm' ) ;
312- fs . writeFileSync ( mockNpmPath , mockNpmScript ) ;
313- fs . chmodSync ( mockNpmPath , '755' ) ;
314-
315- const originalPath = process . env . PATH ;
316- process . env . PATH = `${ testDir } :${ originalPath } ` ;
317-
318- try {
319- const result = await runCLIScript ( testDir , 10000 ) . catch ( err => {
320- console . log ( 'CLI run resulted in:' , err . message ) ;
321- return { error : err . message } ;
322- } ) ;
323-
324- // Check that CLI was executed
325- assert (
326- result . stdout . includes ( 'Mock CLI executed successfully' ) || result . stdout . includes ( 'Zero-UI installed' ) ,
327- 'CLI should execute library CLI function'
328- ) ;
329-
330- console . log ( '✅ CLI script successfully imports and executes library CLI' ) ;
331- } finally {
332- process . env . PATH = originalPath ;
333- }
334- } finally {
335- cleanupTestDir ( testDir ) ;
336- }
337- } ) ;
338-
339271// Additional test for library CLI functionality
340272test ( 'Library CLI initializes project correctly' , async ( ) => {
341273 const testDir = createTestDir ( ) ;
@@ -546,81 +478,6 @@ test('CLI script handles invalid target directory', async () => {
546478 }
547479} ) ;
548480
549- // Test CLI script exit codes
550- test ( 'CLI script returns appropriate exit codes' , async ( ) => {
551- const testDir = createTestDir ( ) ;
552-
553- try {
554- // Create package.json to speed up the test
555- const packageJson = { name : 'test' , version : '1.0.0' } ;
556- fs . writeFileSync ( path . join ( testDir , 'package.json' ) , JSON . stringify ( packageJson ) ) ;
557-
558- // Mock npm to simulate successful installation
559- const mockNpmScript = `#!/bin/bash\necho "Mock npm successful"; exit 0` ;
560- const mockNpmPath = path . join ( testDir , 'npm' ) ;
561- fs . writeFileSync ( mockNpmPath , mockNpmScript ) ;
562- fs . chmodSync ( mockNpmPath , '755' ) ;
563-
564- // Create mock CLI module
565- const nodeModulesDir = path . join ( testDir , 'node_modules' , '@austinserb' , 'react-zero-ui' ) ;
566- fs . mkdirSync ( nodeModulesDir , { recursive : true } ) ;
567-
568- const mockCLI = `
569- function cli() {
570- console.log('CLI executed successfully');
571- return Promise.resolve();
572- }
573- module.exports = cli;
574- module.exports.default = cli;
575- ` ;
576-
577- fs . writeFileSync ( path . join ( nodeModulesDir , 'cli.cjs' ) , mockCLI ) ;
578-
579- const mockPackageJson = { name : '@react-zero-ui/core' , exports : { './cli' : { require : './cli.cjs' , import : './cli.cjs' } } } ;
580- fs . writeFileSync ( path . join ( nodeModulesDir , 'package.json' ) , JSON . stringify ( mockPackageJson ) ) ;
581-
582- const originalPath = process . env . PATH ;
583- process . env . PATH = `${ testDir } :${ originalPath } ` ;
584-
585- try {
586- const binScript = path . resolve ( __dirname , '../../../cli/bin.js' ) ;
587-
588- const result = await new Promise ( ( resolve , reject ) => {
589- const child = spawn ( 'node' , [ binScript , '.' ] , { cwd : testDir , stdio : [ 'pipe' , 'pipe' , 'pipe' ] } ) ;
590-
591- let stdout = '' ;
592- child . stdout . on ( 'data' , data => {
593- stdout += data . toString ( ) ;
594- } ) ;
595-
596- const timer = setTimeout ( ( ) => {
597- child . kill ( 'SIGKILL' ) ;
598- resolve ( { timedOut : true } ) ;
599- } , 10000 ) ;
600-
601- child . on ( 'close' , code => {
602- clearTimeout ( timer ) ;
603- resolve ( { code, stdout } ) ;
604- } ) ;
605-
606- child . on ( 'error' , error => {
607- clearTimeout ( timer ) ;
608- reject ( error ) ;
609- } ) ;
610- } ) ;
611-
612- // Should complete successfully or timeout (which is expected due to our mocks)
613- assert ( result . code === 0 || result . timedOut || result . stdout . includes ( 'Zero-UI installed' ) , 'CLI should complete successfully' ) ;
614-
615- console . log ( '✅ CLI script returns appropriate exit codes' ) ;
616- } finally {
617- process . env . PATH = originalPath ;
618- }
619- } finally {
620- cleanupTestDir ( testDir ) ;
621- }
622- } ) ;
623-
624481// Test library CLI with actual useUI components
625482test ( 'Library CLI processes useUI hooks correctly' , async ( ) => {
626483 const testDir = createTestDir ( ) ;
0 commit comments