🎨 Simplify test usage and change names

This commit is contained in:
Tw93
2025-08-22 12:47:37 +08:00
parent 8a15e989b0
commit 1761802105
13 changed files with 472 additions and 900 deletions

View File

@@ -5,9 +5,20 @@
## 运行测试
```bash
npm test
# 完整测试套件(推荐)
npm test # 运行完整测试套件包含真实构建测试8-12分钟
# 开发时快速测试
npm test -- --no-build # 跳过构建测试仅验证核心功能30秒
```
### 🚀 完整测试套件包含:
-**单元测试**CLI命令、参数验证、响应时间
-**集成测试**:进程管理、文件权限、依赖解析
-**构建器测试**:平台检测、架构检测、文件命名
-**真实构建测试**完整的GitHub.com应用打包验证
## 测试内容
### 单元测试6个

View File

@@ -1,217 +0,0 @@
#!/usr/bin/env node
/**
* GitHub.com Real Build Test
*
* This is a standalone test for actual GitHub.com app packaging
* to validate that both CLI and GitHub Actions scenarios work correctly.
*/
import { spawn, execSync } from "child_process";
import fs from "fs";
import path from "path";
import config from "./config.js";
console.log("🐙 GitHub.com Real Build Test");
console.log("==============================\n");
const testName = "GitHubRealTest";
const appFile = path.join(config.PROJECT_ROOT, `${testName}.app`);
const dmgFile = path.join(config.PROJECT_ROOT, `${testName}.dmg`);
// Cleanup function
const cleanup = () => {
try {
if (fs.existsSync(appFile)) {
if (fs.statSync(appFile).isDirectory()) {
fs.rmSync(appFile, { recursive: true, force: true });
} else {
fs.unlinkSync(appFile);
}
console.log("✅ Cleaned up .app file");
}
if (fs.existsSync(dmgFile)) {
fs.unlinkSync(dmgFile);
console.log("✅ Cleaned up .dmg file");
}
// Clean .pake directory
const pakeDir = path.join(config.PROJECT_ROOT, "src-tauri", ".pake");
if (fs.existsSync(pakeDir)) {
fs.rmSync(pakeDir, { recursive: true, force: true });
console.log("✅ Cleaned up .pake directory");
}
} catch (error) {
console.warn("⚠️ Cleanup warning:", error.message);
}
};
// Handle cleanup on exit
process.on("exit", cleanup);
process.on("SIGINT", () => {
console.log("\n🛑 Build interrupted by user");
cleanup();
process.exit(1);
});
process.on("SIGTERM", cleanup);
console.log("🔧 Testing GitHub.com packaging with CLI...");
console.log(
`Command: node ${config.CLI_PATH} https://github.com --name ${testName} --debug --width 1200 --height 780\n`,
);
const command = `node "${config.CLI_PATH}" "https://github.com" --name "${testName}" --debug --width 1200 --height 780`;
const child = spawn(command, {
shell: true,
cwd: config.PROJECT_ROOT,
stdio: ["pipe", "pipe", "pipe"],
env: {
...process.env,
PAKE_CREATE_APP: "1",
},
});
let buildStarted = false;
let configGenerated = false;
let compilationStarted = false;
console.log("📋 Build Progress:");
console.log("------------------");
child.stdout.on("data", (data) => {
const output = data.toString();
// Track build progress
if (output.includes("Installing package")) {
console.log("📦 Installing pake dependencies...");
}
if (output.includes("Package installed")) {
console.log("✅ Package installation completed");
}
if (output.includes("Building app")) {
buildStarted = true;
console.log("🏗️ Build process started...");
}
if (output.includes("Compiling")) {
compilationStarted = true;
console.log("⚙️ Rust compilation started...");
}
if (output.includes("Bundling")) {
console.log("📦 App bundling started...");
}
if (output.includes("Built application at:")) {
console.log("✅ Application built successfully!");
}
});
child.stderr.on("data", (data) => {
const output = data.toString();
// Track stderr progress (Tauri outputs build info to stderr)
if (output.includes("Installing package")) {
console.log("📦 Installing pake dependencies...");
}
if (output.includes("Building app")) {
buildStarted = true;
console.log("🏗️ Build process started...");
}
if (output.includes("Compiling")) {
compilationStarted = true;
console.log("⚙️ Rust compilation started...");
}
if (output.includes("Finished")) {
console.log("✅ Rust compilation finished!");
}
if (output.includes("Bundling")) {
console.log("📦 App bundling started...");
}
if (output.includes("Built application at:")) {
console.log("✅ Application built successfully!");
}
// Only show actual errors, filter out build progress
if (
!output.includes("warning:") &&
!output.includes("verbose") &&
!output.includes("npm info") &&
!output.includes("Installing package") &&
!output.includes("Package installed") &&
!output.includes("Building app") &&
!output.includes("Compiling") &&
!output.includes("Finished") &&
!output.includes("Built application at:") &&
!output.includes("Bundling") &&
!output.includes("npm http") &&
output.trim().length > 0
) {
console.log("❌ Build error:", output.trim());
}
});
// Set a 3-minute timeout for the test
const timeout = setTimeout(() => {
console.log("\n⏱ Build timeout reached (3 minutes)");
child.kill("SIGTERM");
if (buildStarted && compilationStarted) {
console.log("✅ SUCCESS: GitHub.com CLI build started successfully!");
console.log(" - Build process initiated ✓");
console.log(" - Rust compilation started ✓");
console.log(" - Configuration generated for GitHub.com ✓");
console.log("\n🎯 Test Result: PASS");
console.log(" The GitHub.com app build is working correctly.");
console.log(
" Build was terminated early to save time, but core functionality verified.",
);
process.exit(0);
} else if (buildStarted) {
console.log("⚠️ PARTIAL: Build started but compilation not detected");
console.log("🎯 Test Result: PARTIAL PASS");
process.exit(0);
} else {
console.log("❌ FAIL: Build did not start within timeout");
console.log("🎯 Test Result: FAIL");
process.exit(1);
}
}, 180000); // 3 minutes
child.on("close", (code) => {
clearTimeout(timeout);
console.log(`\n📊 Build Process Summary:`);
console.log("========================");
console.log(`Exit Code: ${code}`);
console.log(`Build Started: ${buildStarted ? "✅" : "❌"}`);
console.log(`Compilation Started: ${compilationStarted ? "✅" : "❌"}`);
// Check for output files
const appExists = fs.existsSync(appFile);
const dmgExists = fs.existsSync(dmgFile);
console.log(`App File (.app): ${appExists ? "✅" : "❌"}`);
console.log(`DMG File: ${dmgExists ? "✅" : "❌"}`);
if (buildStarted && compilationStarted) {
console.log("\n🎉 SUCCESS: GitHub.com CLI build verification completed!");
console.log(" All critical build stages detected.");
process.exit(0);
} else if (buildStarted) {
console.log(
"\n⚠ PARTIAL SUCCESS: Build started but may not have completed",
);
process.exit(0);
} else {
console.log("\n❌ FAILED: Build did not start properly");
process.exit(1);
}
});
child.on("error", (error) => {
clearTimeout(timeout);
console.log(`\n❌ Process Error: ${error.message}`);
console.log("🎯 Test Result: FAIL");
process.exit(1);
});
// Send empty input to handle any prompts
child.stdin.end();

View File

@@ -1,253 +0,0 @@
#!/usr/bin/env node
/**
* GitHub.com Complete Build Test
*
* This test performs a complete build of github.com to verify
* that the entire packaging pipeline works correctly end-to-end.
*/
import { spawn } from "child_process";
import fs from "fs";
import path from "path";
import config from "./config.js";
console.log("🐙 GitHub.com Complete Build Test");
console.log("==================================\n");
const testName = "GitHub";
const appFile = path.join(config.PROJECT_ROOT, `${testName}.app`);
const dmgFile = path.join(config.PROJECT_ROOT, `${testName}.dmg`);
// Cleanup function
const cleanup = () => {
try {
if (fs.existsSync(appFile)) {
if (fs.statSync(appFile).isDirectory()) {
fs.rmSync(appFile, { recursive: true, force: true });
} else {
fs.unlinkSync(appFile);
}
console.log("✅ Cleaned up .app file");
}
if (fs.existsSync(dmgFile)) {
fs.unlinkSync(dmgFile);
console.log("✅ Cleaned up .dmg file");
}
// Clean .pake directory
const pakeDir = path.join(config.PROJECT_ROOT, "src-tauri", ".pake");
if (fs.existsSync(pakeDir)) {
fs.rmSync(pakeDir, { recursive: true, force: true });
console.log("✅ Cleaned up .pake directory");
}
} catch (error) {
console.warn("⚠️ Cleanup warning:", error.message);
}
};
// Handle cleanup on exit
process.on("exit", cleanup);
process.on("SIGINT", () => {
console.log("\n🛑 Build interrupted by user");
cleanup();
process.exit(1);
});
process.on("SIGTERM", cleanup);
console.log("🔧 Testing GitHub app packaging with optimal settings...");
console.log(
`Command: pake https://github.com --name ${testName} --width 1200 --height 800 --hide-title-bar\n`,
);
const command = `node "${config.CLI_PATH}" "https://github.com" --name "${testName}" --width 1200 --height 800 --hide-title-bar`;
const child = spawn(command, {
shell: true,
cwd: config.PROJECT_ROOT,
stdio: ["pipe", "pipe", "pipe"],
env: {
...process.env,
PAKE_CREATE_APP: "1",
},
});
let buildStarted = false;
let compilationStarted = false;
let bundlingStarted = false;
let buildCompleted = false;
console.log("📋 Build Progress:");
console.log("------------------");
child.stdout.on("data", (data) => {
const output = data.toString();
// Track build progress
if (output.includes("Installing package")) {
console.log("📦 Installing pake dependencies...");
}
if (output.includes("Package installed")) {
console.log("✅ Package installation completed");
}
if (output.includes("Building app")) {
buildStarted = true;
console.log("🏗️ Build process started...");
}
if (output.includes("Compiling")) {
compilationStarted = true;
console.log("⚙️ Rust compilation started...");
}
if (output.includes("Bundling")) {
bundlingStarted = true;
console.log("📦 App bundling started...");
}
if (output.includes("Built application at:")) {
buildCompleted = true;
console.log("✅ Application built successfully!");
}
if (output.includes("GitHub")) {
console.log("🐙 GitHub app configuration detected");
}
});
child.stderr.on("data", (data) => {
const output = data.toString();
// Track stderr progress (Tauri outputs build info to stderr)
if (output.includes("Installing package")) {
console.log("📦 Installing pake dependencies...");
}
if (output.includes("Building app")) {
buildStarted = true;
console.log("🏗️ Build process started...");
}
if (output.includes("Compiling")) {
compilationStarted = true;
console.log("⚙️ Rust compilation started...");
}
if (output.includes("Finished")) {
console.log("✅ Rust compilation finished!");
}
if (output.includes("Bundling")) {
bundlingStarted = true;
console.log("📦 App bundling started...");
}
if (output.includes("Built application at:")) {
buildCompleted = true;
console.log("✅ Application built successfully!");
}
// Only show actual errors, filter out build progress
if (
!output.includes("warning:") &&
!output.includes("verbose") &&
!output.includes("npm info") &&
!output.includes("Installing package") &&
!output.includes("Package installed") &&
!output.includes("Building app") &&
!output.includes("Compiling") &&
!output.includes("Finished") &&
!output.includes("Built application at:") &&
!output.includes("Bundling") &&
!output.includes("npm http") &&
!output.includes("Info Looking up installed") &&
output.trim().length > 0
) {
console.log("❌ Build error:", output.trim());
}
});
// Set a 10-minute timeout for the complete build (real packaging takes time)
// DON'T kill the process early - let it complete naturally
const timeout = setTimeout(() => {
console.log("\n⏱ Build timeout reached (10 minutes)");
// Check if we actually have output files even if process is still running
const appExists = fs.existsSync(appFile);
const dmgExists = fs.existsSync(dmgFile);
if (appExists || buildCompleted) {
console.log("🎉 SUCCESS: GitHub app was built successfully!");
console.log(" App file exists, build completed despite long duration");
child.kill("SIGTERM");
process.exit(0);
} else {
console.log("❌ TIMEOUT: Build did not complete within 10 minutes");
child.kill("SIGTERM");
process.exit(1);
}
}, 600000); // 10 minutes
child.on("close", (code) => {
clearTimeout(timeout);
console.log(`\n📊 GitHub App Build Summary:`);
console.log("=============================");
console.log(`Exit Code: ${code}`);
console.log(`Build Started: ${buildStarted ? "✅" : "❌"}`);
console.log(`Compilation Started: ${compilationStarted ? "✅" : "❌"}`);
console.log(`Bundling Started: ${bundlingStarted ? "✅" : "❌"}`);
console.log(`Build Completed: ${buildCompleted ? "✅" : "❌"}`);
// Check for output files
const appExists = fs.existsSync(appFile);
const dmgExists = fs.existsSync(dmgFile);
console.log(`App File (.app): ${appExists ? "✅" : "❌"}`);
console.log(`DMG File: ${dmgExists ? "✅" : "❌"}`);
// Check .app bundle structure if it exists
if (appExists) {
try {
const contentsPath = path.join(appFile, "Contents");
const macOSPath = path.join(contentsPath, "MacOS");
const resourcesPath = path.join(contentsPath, "Resources");
console.log(`App Bundle Structure:`);
console.log(` Contents/: ${fs.existsSync(contentsPath) ? "✅" : "❌"}`);
console.log(
` Contents/MacOS/: ${fs.existsSync(macOSPath) ? "✅" : "❌"}`,
);
console.log(
` Contents/Resources/: ${fs.existsSync(resourcesPath) ? "✅" : "❌"}`,
);
} catch (error) {
console.log(`App Bundle Check: ❌ (${error.message})`);
}
}
// Real success check: app file must exist and build must have completed
if (appExists && (buildCompleted || code === 0)) {
console.log("\n🎉 COMPLETE SUCCESS: GitHub app build fully completed!");
console.log(" 🐙 GitHub.com successfully packaged as desktop app");
console.log(" 🎯 Build completed with app file generated");
console.log(" 📱 App bundle created with proper structure");
process.exit(0);
} else if (appExists) {
console.log("\n✅ SUCCESS: GitHub app was built successfully!");
console.log(" 🐙 GitHub.com packaging completed with app file");
console.log(" 🎯 Build process successful");
process.exit(0);
} else if (code === 0 && buildStarted && compilationStarted) {
console.log(
"\n⚠ PARTIAL SUCCESS: Build process completed but no app file found",
);
console.log(" 🐙 GitHub.com build process executed successfully");
console.log(" ⚠️ App file may be in a different location");
process.exit(0);
} else {
console.log("\n❌ FAILED: GitHub app build did not complete successfully");
console.log(" ❌ No app file generated or build process failed");
process.exit(1);
}
});
child.on("error", (error) => {
clearTimeout(timeout);
console.log(`\n❌ Process Error: ${error.message}`);
console.log("🎯 Test Result: FAIL");
process.exit(1);
});
// Send empty input to handle any prompts
child.stdin.end();

View File

@@ -234,7 +234,7 @@ runner.addTest(
"GitHub Actions Environment Simulation",
async () => {
try {
// Create a temporary test script that simulates build_with_pake_cli.js
// Create a temporary test script that simulates github-action-build.js
const testScript = `
const { execSync } = require('child_process');
@@ -298,7 +298,7 @@ runner.addTest(
runner.trackTempDir(tempDir);
// Test cleanup script logic (from build_with_pake_cli.js)
// Test cleanup script logic (from github-action-build.js)
const cleanupScript = `
const fs = require('fs');
const path = require('path');
@@ -340,7 +340,7 @@ process.exit(cleanedDirs > 0 ? 0 : 1);
}
},
TIMEOUTS.MEDIUM,
"Tests configuration cleanup logic from build_with_pake_cli.js",
"Tests configuration cleanup logic from github-action-build.js",
);
// Test 5: Icon fetching simulation
@@ -539,7 +539,7 @@ runner.addTest(
const requiredElements = [
"npm install pake-cli@latest --no-package-lock", // Latest version installation
"timeout-minutes: 15", // Sufficient timeout
"node ./script/build_with_pake_cli.js", // Build script execution
"node ./script/github-action-build.js", // Build script execution
"ubuntu-24.04", // Linux support
"macos-latest", // macOS support
"windows-latest", // Windows support
@@ -738,7 +738,7 @@ console.log('URL:', process.env.URL);
console.log('NAME:', process.env.NAME);
console.log('WIDTH x HEIGHT:', process.env.WIDTH + 'x' + process.env.HEIGHT);
// Simulate the build script execution (script/build_with_pake_cli.js equivalent)
// Simulate the build script execution (script/github-action-build.js equivalent)
const fs = require('fs');
// Simulate pake-cli installation check
@@ -800,7 +800,7 @@ const path = require('path');
const { execSync } = require('child_process');
// Check if build script exists
const buildScript = path.join(process.cwd(), 'script', 'build_with_pake_cli.js');
const buildScript = path.join(process.cwd(), 'script', 'github-action-build.js');
const fs = require('fs');
if (!fs.existsSync(buildScript)) {

View File

@@ -81,11 +81,6 @@ class PakeTestRunner {
}
}
if (quick) {
console.log("⚡ Running Quick Tests...");
await this.runQuickTests();
}
this.cleanup();
this.displayFinalResults();
@@ -1047,49 +1042,6 @@ class PakeTestRunner {
);
}
async runQuickTests() {
// Only run essential tests for quick mode
await this.runTest(
"Quick Version Check",
() => {
const output = execSync(`node "${config.CLI_PATH}" --version`, {
encoding: "utf8",
timeout: 3000,
});
return /^\d+\.\d+\.\d+/.test(output.trim());
},
TIMEOUTS.QUICK,
);
await this.runTest(
"Quick Help Check",
() => {
const output = execSync(`node "${config.CLI_PATH}" --help`, {
encoding: "utf8",
timeout: 3000,
});
return output.includes("Usage: cli [url] [options]");
},
TIMEOUTS.QUICK,
);
await this.runTest(
"Quick Environment Check",
() => {
const platform = process.platform;
const arch = process.arch;
const nodeVersion = process.version;
return (
typeof platform === "string" &&
typeof arch === "string" &&
nodeVersion.startsWith("v")
);
},
TIMEOUTS.QUICK,
);
}
// Helper function to check if files exist (handles wildcards)
checkFileExists(filePath) {
if (filePath.includes("*")) {
@@ -1238,15 +1190,15 @@ class PakeTestRunner {
// Command line interface
const args = process.argv.slice(2);
// Parse command line arguments
// Complete test suite by default - no more smart modes
const options = {
unit: args.includes("--unit") || args.length === 0,
integration: args.includes("--integration") || args.length === 0,
builder: args.includes("--builder") || args.length === 0,
unit: !args.includes("--no-unit"),
integration: !args.includes("--no-integration"),
builder: !args.includes("--no-builder"),
pakeCliTests: args.includes("--pake-cli"),
e2e: args.includes("--e2e") || args.includes("--full"),
realBuild: args.includes("--real-build") || args.length === 0, // Include real build in default tests
quick: args.includes("--quick"),
e2e: args.includes("--e2e"),
realBuild: !args.includes("--no-build"), // Always include real build test
quick: false, // Remove quick mode
};
// Help message
@@ -1254,26 +1206,31 @@ if (args.includes("--help") || args.includes("-h")) {
console.log(`
🚀 Pake CLI Test Suite
Usage: node tests/index.js [options]
Usage: npm test [-- options]
Options:
--unit Run unit tests (default)
--integration Run integration tests (default)
--builder Run builder tests (default)
--pake-cli Run pake-cli GitHub Actions tests
--e2e, --full Run end-to-end tests
--real-build Run complete real build test (8+ minutes on non-macOS, 12+ minutes multi-arch on macOS)
--quick Run only essential tests (fast)
--help, -h Show this help message
Complete Test Suite (Default):
npm test # Run complete test suite with real build (8-12 minutes)
Test Components:
✅ Unit Tests # CLI commands, validation, response time
✅ Integration Tests # Process spawning, file permissions, dependencies
✅ Builder Tests # Platform detection, architecture, file naming
✅ Real Build Test # Complete GitHub.com app build with packaging
Optional Components:
--e2e Add end-to-end configuration tests
--pake-cli Add pake-cli GitHub Actions tests
Skip Components (if needed):
--no-unit Skip unit tests
--no-integration Skip integration tests
--no-builder Skip builder tests
--no-build Skip real build test
Examples:
npm test # Run all default tests (multi-arch on macOS)
node tests/index.js # Run all default tests (multi-arch on macOS)
node tests/index.js --quick # Quick test (30 seconds)
node tests/index.js --real-build # Complete build test (multi-arch on macOS, single-arch elsewhere)
node tests/index.js --pake-cli # GitHub Actions tests
node tests/index.js --e2e # Full end-to-end tests
node tests/index.js --unit --integration # Specific tests only
npm test # Complete test suite (recommended)
npm test -- --e2e # Complete suite + end-to-end tests
npm test -- --no-build # Skip real build (faster for development)
Environment:
CI=1 # Enable CI mode