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
JavaScript
/**
* 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