Monorepo for Aesthetic.Computer aesthetic.computer
at main 110 lines 3.7 kB view raw
1#!/usr/bin/env node 2 3// Test script for ac-pack utility 4// Tests packing a simple piece and verifying the output 5 6import { promises as fs } from "fs"; 7import path from "path"; 8import { fileURLToPath } from "url"; 9import { AcPacker } from "./ac-pack.mjs"; 10 11const __filename = fileURLToPath(import.meta.url); 12const __dirname = path.dirname(__filename); 13 14async function runTests() { 15 console.log("🧪 Running ac-pack tests...\n"); 16 17 // Test 1: Pack a simple JavaScript piece 18 try { 19 console.log("📋 Test 1: Packing 'brush' piece..."); 20 const packer = new AcPacker("brush", { 21 title: "Test Brush", 22 description: "Test packing of brush piece" 23 }); 24 25 await packer.pack(); 26 27 // Verify the output 28 const outputDir = path.join(__dirname, "..", "tokens", "brush"); 29 const zipPath = `${outputDir}.zip`; 30 31 // Check if files exist 32 const indexExists = await fs.access(path.join(outputDir, "index.html")).then(() => true).catch(() => false); 33 const zipExists = await fs.access(zipPath).then(() => true).catch(() => false); 34 const bootExists = await fs.access(path.join(outputDir, "aesthetic.computer", "boot.mjs")).then(() => true).catch(() => false); 35 36 console.log(` ✅ index.html: ${indexExists ? 'exists' : 'missing'}`); 37 console.log(` ✅ ZIP file: ${zipExists ? 'exists' : 'missing'}`); 38 console.log(` ✅ boot.mjs: ${bootExists ? 'exists' : 'missing'}`); 39 40 if (indexExists && zipExists && bootExists) { 41 console.log(" 🎉 Test 1 PASSED\n"); 42 } else { 43 console.log(" ❌ Test 1 FAILED\n"); 44 return false; 45 } 46 47 } catch (error) { 48 console.log(` ❌ Test 1 FAILED: ${error.message}\n`); 49 return false; 50 } 51 52 // Test 2: Pack a Lisp piece 53 try { 54 console.log("📋 Test 2: Packing 'brush' Lisp piece..."); 55 const packer = new AcPacker("brush", { 56 title: "Test Lisp Brush", 57 description: "Test packing of Lisp brush piece" 58 }); 59 60 await packer.pack(); 61 62 console.log(" 🎉 Test 2 PASSED\n"); 63 64 } catch (error) { 65 console.log(` ❌ Test 2 FAILED: ${error.message}\n`); 66 return false; 67 } 68 69 // Test 3: Verify index.html content 70 try { 71 console.log("📋 Test 3: Verifying HTML content..."); 72 const outputDir = path.join(__dirname, "..", "tokens", "brush"); 73 const indexPath = path.join(outputDir, "index.html"); 74 const indexContent = await fs.readFile(indexPath, "utf8"); 75 76 const hasTitle = indexContent.includes("<title>"); 77 const hasOgImage = indexContent.includes('property="og:image"'); 78 const hasBootScript = indexContent.includes("boot.mjs"); 79 const hasTeiaMode = indexContent.includes("acTEIA_MODE"); 80 81 console.log(` ✅ Has title tag: ${hasTitle}`); 82 console.log(` ✅ Has og:image meta: ${hasOgImage}`); 83 console.log(` ✅ Has boot script: ${hasBootScript}`); 84 console.log(` ✅ Has Teia mode: ${hasTeiaMode}`); 85 86 if (hasTitle && hasOgImage && hasBootScript && hasTeiaMode) { 87 console.log(" 🎉 Test 3 PASSED\n"); 88 } else { 89 console.log(" ❌ Test 3 FAILED\n"); 90 return false; 91 } 92 93 } catch (error) { 94 console.log(` ❌ Test 3 FAILED: ${error.message}\n`); 95 return false; 96 } 97 98 console.log("🎉 All tests passed! ac-pack is working correctly.\n"); 99 100 console.log("📋 Next steps:"); 101 console.log("1. Install archiver: cd utilities && npm install"); 102 console.log("2. Test with a real piece: node utilities/ac-pack.mjs paint"); 103 console.log("3. Upload the generated zip to teia.art/mint"); 104 105 return true; 106} 107 108if (import.meta.url === `file://${process.argv[1]}`) { 109 runTests().catch(console.error); 110}