🐛 Fix testing under Linux and Windows

This commit is contained in:
Tw93
2025-08-22 08:07:34 +08:00
parent e165bb1c7a
commit 4bb900cd75

View File

@@ -680,12 +680,18 @@ class PakeTestRunner {
} }
}); });
let errorOutput = "";
child.stderr.on("data", (data) => { child.stderr.on("data", (data) => {
const output = data.toString(); const output = data.toString();
if (output.includes("Building app")) buildStarted = true; if (output.includes("Building app")) buildStarted = true;
if (output.includes("Compiling")) compilationStarted = true; if (output.includes("Compiling")) compilationStarted = true;
if (output.includes("Finished")) if (output.includes("Finished"))
console.log(" ✅ Compilation finished!"); console.log(" ✅ Compilation finished!");
// Capture error output for debugging
if (output.includes("error:") || output.includes("Error:") || output.includes("ERROR")) {
errorOutput += output;
}
}); });
// Real timeout - 8 minutes for actual build // Real timeout - 8 minutes for actual build
@@ -732,9 +738,11 @@ class PakeTestRunner {
expectedFiles.installer, expectedFiles.installer,
); );
if (appExists) { if (appExists || installerExists) {
console.log(" 🎉 Real build test SUCCESS: App file generated!"); console.log(" 🎉 Real build test SUCCESS: Build file(s) generated!");
console.log(` 📱 App location: ${actualAppPath}`); if (appExists) {
console.log(` 📱 App location: ${actualAppPath}`);
}
if (installerExists) { if (installerExists) {
console.log(` 💿 Installer location: ${actualInstallerPath}`); console.log(` 💿 Installer location: ${actualInstallerPath}`);
} }
@@ -742,11 +750,52 @@ class PakeTestRunner {
resolve(true); resolve(true);
} else if (code === 0 && buildStarted && compilationStarted) { } else if (code === 0 && buildStarted && compilationStarted) {
console.log( console.log(
" ⚠️ Build process completed but no app file found", " ⚠️ Build process completed but no build files found",
); );
console.log(` 📍 Expected location: ${expectedFiles.app}`); console.log(` 📍 Expected app location: ${expectedFiles.app}`);
console.log(` 📍 Expected installer location: ${expectedFiles.installer}`);
// Debug: List actual files in target directories to help diagnose
const targetDir = path.join(config.PROJECT_ROOT, 'src-tauri/target');
if (fs.existsSync(targetDir)) {
console.log(" 🔍 Debug: Listing target directory structure...");
try {
this.listTargetContents(targetDir);
} catch (error) {
console.log(` ⚠️ Could not list target contents: ${error.message}`);
}
}
resolve(false); resolve(false);
} else { } else {
console.log(` ❌ Build process failed with exit code: ${code}`);
if (buildStarted) {
console.log(" 📊 Build was started but failed during execution");
if (errorOutput.trim()) {
console.log(" 🔍 Error details:");
errorOutput.split('\n').forEach(line => {
if (line.trim()) console.log(` ${line.trim()}`);
});
}
// Debug: List actual files in target directories to help diagnose
const targetDir = path.join(config.PROJECT_ROOT, 'src-tauri/target');
if (fs.existsSync(targetDir)) {
console.log(" 🔍 Debug: Listing target directory structure...");
try {
this.listTargetContents(targetDir);
} catch (error) {
console.log(` ⚠️ Could not list target contents: ${error.message}`);
}
}
} else {
console.log(" 📊 Build failed before starting compilation");
if (errorOutput.trim()) {
console.log(" 🔍 Error details:");
errorOutput.split('\n').forEach(line => {
if (line.trim()) console.log(` ${line.trim()}`);
});
}
}
reject(new Error(`Real build test failed with code ${code}`)); reject(new Error(`Real build test failed with code ${code}`));
} }
}); });
@@ -1019,9 +1068,13 @@ class PakeTestRunner {
const dir = path.dirname(filePath); const dir = path.dirname(filePath);
const pattern = path.basename(filePath); const pattern = path.basename(filePath);
try { try {
if (!fs.existsSync(dir)) {
return false;
}
const files = fs.readdirSync(dir); const files = fs.readdirSync(dir);
const regex = new RegExp(pattern.replace(/\*/g, ".*")); const regex = new RegExp(pattern.replace(/\*/g, ".*"));
return files.some((file) => regex.test(file)); const matches = files.filter((file) => regex.test(file));
return matches.length > 0;
} catch { } catch {
return false; return false;
} }
@@ -1045,6 +1098,30 @@ class PakeTestRunner {
return filePath; return filePath;
} }
listTargetContents(targetDir, maxDepth = 3, currentDepth = 0) {
if (currentDepth >= maxDepth) return;
try {
const items = fs.readdirSync(targetDir);
items.forEach(item => {
const fullPath = path.join(targetDir, item);
const relativePath = path.relative(config.PROJECT_ROOT, fullPath);
const indent = " ".repeat(currentDepth + 1);
if (fs.statSync(fullPath).isDirectory()) {
console.log(`${indent}📁 ${relativePath}/`);
if (item === 'bundle' || item === 'release') {
this.listTargetContents(fullPath, maxDepth, currentDepth + 1);
}
} else {
console.log(`${indent}📄 ${relativePath}`);
}
});
} catch (error) {
console.log(` ⚠️ Could not list contents of ${targetDir}`);
}
}
trackTempFile(filepath) { trackTempFile(filepath) {
this.tempFiles.push(filepath); this.tempFiles.push(filepath);
} }
@@ -1055,10 +1132,10 @@ class PakeTestRunner {
cleanupTempIcons() { cleanupTempIcons() {
// Clean up temporary icon files generated during tests // Clean up temporary icon files generated during tests
const iconsDir = path.join(config.PROJECT_ROOT, 'src-tauri/icons'); const iconsDir = path.join(config.PROJECT_ROOT, "src-tauri/icons");
const testNames = ['urltest', 'githubapp', 'githubmultiarch']; const testNames = ["urltest", "githubapp", "githubmultiarch"];
testNames.forEach(name => { testNames.forEach((name) => {
const iconPath = path.join(iconsDir, `${name}.icns`); const iconPath = path.join(iconsDir, `${name}.icns`);
try { try {
if (fs.existsSync(iconPath)) { if (fs.existsSync(iconPath)) {
@@ -1074,7 +1151,7 @@ class PakeTestRunner {
cleanup() { cleanup() {
// Clean up temporary icon files generated during tests // Clean up temporary icon files generated during tests
this.cleanupTempIcons(); this.cleanupTempIcons();
// Clean up temporary files and directories // Clean up temporary files and directories
this.tempFiles.forEach((file) => { this.tempFiles.forEach((file) => {
try { try {