|
| 1 | +#!/usr/bin/env node |
| 2 | +import { execSync } from 'node:child_process'; |
| 3 | +import { mkdtempSync, rmSync, existsSync, readFileSync } from 'node:fs'; |
| 4 | +import { join } from 'node:path'; |
| 5 | +import { tmpdir } from 'node:os'; |
| 6 | + |
| 7 | +const TARBALL = '../create-zero-ui-1.1.0.tgz'; |
| 8 | + |
| 9 | +console.log('🧪 Testing CLI package with npx (no global install)...\n'); |
| 10 | + |
| 11 | +// Create temp test directory |
| 12 | +const testDir = mkdtempSync(join(tmpdir(), 'test-zero-ui-')); |
| 13 | +const tarballPath = join(process.cwd(), TARBALL); |
| 14 | + |
| 15 | +try { |
| 16 | + console.log('🚀 Testing CLI execution with npx...'); |
| 17 | + process.chdir(testDir); |
| 18 | + |
| 19 | + // Run the CLI using npx (completely isolated, no global install) |
| 20 | + try { |
| 21 | + execSync(`npx ${tarballPath} .`, { stdio: 'pipe', timeout: 30000 }); |
| 22 | + console.log('✅ CLI executed without errors'); |
| 23 | + } catch (error) { |
| 24 | + console.log('⚠️ CLI execution had issues:', error.message); |
| 25 | + // Check if basic setup still worked despite the known core CLI issue |
| 26 | + } |
| 27 | + |
| 28 | + // Validate results |
| 29 | + console.log('\n🔍 Validating installation results...'); |
| 30 | + |
| 31 | + const checks = [ |
| 32 | + { name: 'package.json created', test: () => existsSync('package.json') }, |
| 33 | + { |
| 34 | + name: '@react-zero-ui/core installed', |
| 35 | + test: () => { |
| 36 | + if (!existsSync('package.json')) return false; |
| 37 | + const pkg = JSON.parse(readFileSync('package.json', 'utf-8')); |
| 38 | + return pkg.dependencies && '@react-zero-ui/core' in pkg.dependencies; |
| 39 | + }, |
| 40 | + }, |
| 41 | + { |
| 42 | + name: '@tailwindcss/postcss dev dependency', |
| 43 | + test: () => { |
| 44 | + if (!existsSync('package.json')) return false; |
| 45 | + const pkg = JSON.parse(readFileSync('package.json', 'utf-8')); |
| 46 | + return pkg.devDependencies && '@tailwindcss/postcss' in pkg.devDependencies; |
| 47 | + }, |
| 48 | + }, |
| 49 | + { name: 'node_modules created', test: () => existsSync('node_modules') }, |
| 50 | + ]; |
| 51 | + |
| 52 | + let allPassed = true; |
| 53 | + for (const check of checks) { |
| 54 | + const passed = check.test(); |
| 55 | + console.log(`${passed ? '✅' : '❌'} ${check.name}`); |
| 56 | + if (!passed) allPassed = false; |
| 57 | + } |
| 58 | + |
| 59 | + console.log('\n📊 Test Summary:'); |
| 60 | + if (allPassed) { |
| 61 | + console.log('🎉 All checks passed! CLI package is ready to publish.'); |
| 62 | + process.exit(0); |
| 63 | + } else { |
| 64 | + console.log('❌ Some checks failed. Review before publishing.'); |
| 65 | + process.exit(1); |
| 66 | + } |
| 67 | +} catch (error) { |
| 68 | + console.error('💥 Test failed:', error.message); |
| 69 | + process.exit(1); |
| 70 | +} finally { |
| 71 | + // Cleanup temp directory only |
| 72 | + console.log('\n🧹 Cleaning up...'); |
| 73 | + try { |
| 74 | + process.chdir(process.cwd()); |
| 75 | + rmSync(testDir, { recursive: true, force: true }); |
| 76 | + console.log('✅ Cleanup complete'); |
| 77 | + } catch (e) { |
| 78 | + console.log('⚠️ Cleanup had issues:', e.message); |
| 79 | + } |
| 80 | +} |
0 commit comments