UNPKG

codebase-asset-optimizer

Version:

Professional CLI development tool for optimizing and managing assets in codebases. Detects unused assets, optimizes images to WebP, optimizes videos, and automatically replaces asset references. GIFs are preserved unchanged to maintain animation functiona

100 lines โ€ข 4.56 kB
#!/usr/bin/env node /** * UX Integration Test for codebase-asset-optimizer * Tests the complete user experience from installation to optimization */ import fs from 'fs-extra'; import path from 'path'; import chalk from 'chalk'; import { execSync } from 'child_process'; const TEST_PROJECT_DIR = path.join(process.cwd(), 'test-project'); async function runCommand(command, description) { console.log(chalk.blue(`\n๐Ÿ”„ ${description}`)); console.log(chalk.gray(` Command: ${command}`)); try { const output = execSync(command, { cwd: process.cwd(), encoding: 'utf8', stdio: 'pipe' }); console.log(chalk.green(' โœ… Success')); return output; } catch (error) { console.log(chalk.red(' โŒ Failed')); console.log(chalk.red(` Error: ${error.message}`)); throw error; } } async function testUXFlow() { console.log(chalk.cyan('\n๐Ÿงช UX Integration Test')); console.log(chalk.cyan('================================\n')); // Test 1: Build the project await runCommand('npm run build', 'Building project'); // Test 2: Audit test project await runCommand('npm run audit:assets test-project', 'Auditing test project assets'); // Test 3: Dry run optimization console.log(chalk.blue('\n๐Ÿ”„ Testing dry-run optimization')); const dryRunOutput = await runCommand('npm run optimize:assets:dry test-project', 'Running dry-run optimization'); // Verify dry-run output contains expected elements if (dryRunOutput.includes('DRY RUN MODE') && dryRunOutput.includes('No files will be modified')) { console.log(chalk.green(' โœ… Dry-run mode working correctly')); } else { throw new Error('Dry-run mode not functioning as expected'); } // Test 4: Check interactive mode help await runCommand('npm run assets:interactive -- --help', 'Testing interactive mode help'); // Test 5: Verify test project structure console.log(chalk.blue('\n๐Ÿ”„ Verifying test project structure')); const testProjectExists = await fs.pathExists(TEST_PROJECT_DIR); const publicDirExists = await fs.pathExists(path.join(TEST_PROJECT_DIR, 'public')); const srcDirExists = await fs.pathExists(path.join(TEST_PROJECT_DIR, 'src')); if (testProjectExists && publicDirExists && srcDirExists) { console.log(chalk.green(' โœ… Test project structure verified')); } else { throw new Error('Test project structure incomplete'); } // Test 6: Check asset counts console.log(chalk.blue('\n๐Ÿ”„ Checking asset inventory')); const imagesDir = path.join(TEST_PROJECT_DIR, 'public', 'images'); const videosDir = path.join(TEST_PROJECT_DIR, 'public', 'videos'); const imageFiles = await fs.readdir(imagesDir); const videoFiles = await fs.readdir(videosDir); console.log(chalk.green(` โœ… Found ${imageFiles.length} images, ${videoFiles.length} videos`)); // Test 7: Verify npm scripts are available console.log(chalk.blue('\n๐Ÿ”„ Verifying npm scripts')); const packageJson = await fs.readJson('package.json'); const requiredScripts = [ 'optimize:assets', 'optimize:assets:dry', 'audit:assets', 'clean:assets', 'assets:interactive' ]; const missingScripts = requiredScripts.filter(script => !packageJson.scripts[script]); if (missingScripts.length === 0) { console.log(chalk.green(' โœ… All npm scripts present')); } else { throw new Error(`Missing scripts: ${missingScripts.join(', ')}`); } console.log(chalk.green('\n๐ŸŽ‰ UX Integration Test PASSED!')); console.log(chalk.blue('\n๐Ÿ“Š Test Summary:')); console.log(chalk.white(' โœ… Build process works')); console.log(chalk.white(' โœ… Audit functionality verified')); console.log(chalk.white(' โœ… Dry-run mode prevents modifications')); console.log(chalk.white(' โœ… Interactive mode accessible')); console.log(chalk.white(' โœ… Test project structure complete')); console.log(chalk.white(` โœ… Asset inventory: ${imageFiles.length} images, ${videoFiles.length} videos`)); console.log(chalk.white(' โœ… All npm scripts configured')); console.log(chalk.cyan('\n๐Ÿš€ Ready for production use!')); } // Run the test testUXFlow().catch((error) => { console.error(chalk.red('\nโŒ UX Integration Test FAILED!')); console.error(chalk.red(`Error: ${error.message}`)); process.exit(1); }); //# sourceMappingURL=test-ux.js.map