🐛 Fix formatting and testing code
This commit is contained in:
@@ -39,8 +39,8 @@
|
|||||||
"tauri": "tauri",
|
"tauri": "tauri",
|
||||||
"cli": "cross-env NODE_ENV=development rollup -c -w",
|
"cli": "cross-env NODE_ENV=development rollup -c -w",
|
||||||
"cli:build": "cross-env NODE_ENV=production rollup -c",
|
"cli:build": "cross-env NODE_ENV=production rollup -c",
|
||||||
"test": "npm run cli:build && PAKE_CREATE_APP=1 node tests/index.js",
|
"test": "npm run cli:build && cross-env PAKE_CREATE_APP=1 node tests/index.js",
|
||||||
"format": "prettier --write . --ignore-unknown && cd src-tauri && cargo fmt --verbose",
|
"format": "prettier --write . --ignore-unknown && find tests -name '*.js' -exec sed -i '' 's/[[:space:]]*$//' {} \\; && cd src-tauri && cargo fmt --verbose",
|
||||||
"prepublishOnly": "npm run cli:build"
|
"prepublishOnly": "npm run cli:build"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -28,11 +28,7 @@ pub fn set_window(app: &mut App, config: &PakeConfig, tauri_config: &Config) ->
|
|||||||
serde_json::to_string(&window_config).unwrap()
|
serde_json::to_string(&window_config).unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
let window_title = window_config
|
let window_title = window_config.title.as_deref().unwrap_or("");
|
||||||
.title
|
|
||||||
.as_ref()
|
|
||||||
.map(|t| t.as_str())
|
|
||||||
.unwrap_or("");
|
|
||||||
|
|
||||||
let mut window_builder = WebviewWindowBuilder::new(app, "pake", url)
|
let mut window_builder = WebviewWindowBuilder::new(app, "pake", url)
|
||||||
.title(window_title)
|
.title(window_title)
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ console.log('URL:', process.env.URL);
|
|||||||
console.log('NAME:', process.env.NAME);
|
console.log('NAME:', process.env.NAME);
|
||||||
|
|
||||||
// Test that environment variables are properly passed
|
// Test that environment variables are properly passed
|
||||||
const success = process.env.URL === 'https://github.com' &&
|
const success = process.env.URL === 'https://github.com' &&
|
||||||
process.env.NAME === 'github' &&
|
process.env.NAME === 'github' &&
|
||||||
process.env.HEIGHT === '780' &&
|
process.env.HEIGHT === '780' &&
|
||||||
process.env.WIDTH === '1200';
|
process.env.WIDTH === '1200';
|
||||||
@@ -461,22 +461,22 @@ runner.addTest(
|
|||||||
const generateMacBuildCommand = (multiArch, debug, features = ['cli-build']) => {
|
const generateMacBuildCommand = (multiArch, debug, features = ['cli-build']) => {
|
||||||
if (!multiArch) {
|
if (!multiArch) {
|
||||||
const baseCommand = debug ? 'npm run tauri build -- --debug' : 'npm run tauri build --';
|
const baseCommand = debug ? 'npm run tauri build -- --debug' : 'npm run tauri build --';
|
||||||
return features.length > 0 ?
|
return features.length > 0 ?
|
||||||
\`\${baseCommand} --features \${features.join(',')}\` :
|
\`\${baseCommand} --features \${features.join(',')}\` :
|
||||||
baseCommand;
|
baseCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseCommand = debug
|
const baseCommand = debug
|
||||||
? 'npm run tauri build -- --debug'
|
? 'npm run tauri build -- --debug'
|
||||||
: 'npm run tauri build --';
|
: 'npm run tauri build --';
|
||||||
|
|
||||||
const configPath = 'src-tauri/.pake/tauri.conf.json';
|
const configPath = 'src-tauri/.pake/tauri.conf.json';
|
||||||
let fullCommand = \`\${baseCommand} --target universal-apple-darwin -c "\${configPath}"\`;
|
let fullCommand = \`\${baseCommand} --target universal-apple-darwin -c "\${configPath}"\`;
|
||||||
|
|
||||||
if (features.length > 0) {
|
if (features.length > 0) {
|
||||||
fullCommand += \` --features \${features.join(',')}\`;
|
fullCommand += \` --features \${features.join(',')}\`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fullCommand;
|
return fullCommand;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -576,12 +576,12 @@ runner.addTest(
|
|||||||
// Test Rust feature flag logic
|
// Test Rust feature flag logic
|
||||||
const validateFeatureFlags = (platform, darwinVersion = 23) => {
|
const validateFeatureFlags = (platform, darwinVersion = 23) => {
|
||||||
const features = ['cli-build'];
|
const features = ['cli-build'];
|
||||||
|
|
||||||
// Add macos-proxy feature for modern macOS (Darwin 23+ = macOS 14+)
|
// Add macos-proxy feature for modern macOS (Darwin 23+ = macOS 14+)
|
||||||
if (platform === 'darwin' && darwinVersion >= 23) {
|
if (platform === 'darwin' && darwinVersion >= 23) {
|
||||||
features.push('macos-proxy');
|
features.push('macos-proxy');
|
||||||
}
|
}
|
||||||
|
|
||||||
return features;
|
return features;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -633,52 +633,52 @@ runner.addTest(
|
|||||||
const validateConfig = (config) => {
|
const validateConfig = (config) => {
|
||||||
const required = ['url', 'name', 'width', 'height'];
|
const required = ['url', 'name', 'width', 'height'];
|
||||||
const optional = ['icon', 'fullscreen', 'debug', 'multiArch'];
|
const optional = ['icon', 'fullscreen', 'debug', 'multiArch'];
|
||||||
|
|
||||||
// Check required fields
|
// Check required fields
|
||||||
const hasRequired = required.every(field => config.hasOwnProperty(field));
|
const hasRequired = required.every(field => config.hasOwnProperty(field));
|
||||||
|
|
||||||
// Check field types
|
// Check field types
|
||||||
const validTypes =
|
const validTypes =
|
||||||
typeof config.url === 'string' &&
|
typeof config.url === 'string' &&
|
||||||
typeof config.name === 'string' &&
|
typeof config.name === 'string' &&
|
||||||
typeof config.width === 'number' &&
|
typeof config.width === 'number' &&
|
||||||
typeof config.height === 'number';
|
typeof config.height === 'number';
|
||||||
|
|
||||||
// Check URL format
|
// Check URL format
|
||||||
let validUrl = false;
|
let validUrl = false;
|
||||||
try {
|
try {
|
||||||
new URL(config.url);
|
new URL(config.url);
|
||||||
validUrl = true;
|
validUrl = true;
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
// Check name is not empty
|
// Check name is not empty
|
||||||
const validName = config.name.length > 0;
|
const validName = config.name.length > 0;
|
||||||
|
|
||||||
return hasRequired && validTypes && validUrl && validName;
|
return hasRequired && validTypes && validUrl && validName;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Test different configurations
|
// Test different configurations
|
||||||
const configs = [
|
const configs = [
|
||||||
{
|
{
|
||||||
url: 'https://github.com',
|
url: 'https://github.com',
|
||||||
name: 'github',
|
name: 'github',
|
||||||
width: 1200,
|
width: 1200,
|
||||||
height: 780,
|
height: 780,
|
||||||
valid: true
|
valid: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
url: 'invalid-url',
|
url: 'invalid-url',
|
||||||
name: 'test',
|
name: 'test',
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 600,
|
height: 600,
|
||||||
valid: false
|
valid: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
url: 'https://example.com',
|
url: 'https://example.com',
|
||||||
name: '',
|
name: '',
|
||||||
width: 1000,
|
width: 1000,
|
||||||
height: 700,
|
height: 700,
|
||||||
valid: false
|
valid: false
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -755,7 +755,7 @@ const command = 'pake ' + process.env.URL + ' --name ' + process.env.NAME + ' --
|
|||||||
console.log('Build command:', command);
|
console.log('Build command:', command);
|
||||||
|
|
||||||
// Simulate build process validation
|
// Simulate build process validation
|
||||||
const validBuild =
|
const validBuild =
|
||||||
process.env.URL === 'https://github.com' &&
|
process.env.URL === 'https://github.com' &&
|
||||||
process.env.NAME === 'github' &&
|
process.env.NAME === 'github' &&
|
||||||
process.env.WIDTH === '1200' &&
|
process.env.WIDTH === '1200' &&
|
||||||
@@ -825,7 +825,7 @@ const env = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Test parameter validation
|
// Test parameter validation
|
||||||
const validParams =
|
const validParams =
|
||||||
env.URL === 'https://github.com' &&
|
env.URL === 'https://github.com' &&
|
||||||
env.NAME === 'github' &&
|
env.NAME === 'github' &&
|
||||||
env.WIDTH === '1200' &&
|
env.WIDTH === '1200' &&
|
||||||
|
|||||||
112
tests/index.js
112
tests/index.js
@@ -610,11 +610,64 @@ class PakeTestRunner {
|
|||||||
async () => {
|
async () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const testName = "GitHubRealBuild";
|
const testName = "GitHubRealBuild";
|
||||||
const appFile = path.join(config.PROJECT_ROOT, `${testName}.app`);
|
// Platform-specific output files
|
||||||
const dmgFile = path.join(config.PROJECT_ROOT, `${testName}.dmg`);
|
const outputFiles = {
|
||||||
|
darwin: {
|
||||||
|
app: path.join(config.PROJECT_ROOT, `${testName}.app`),
|
||||||
|
installer: path.join(config.PROJECT_ROOT, `${testName}.dmg`),
|
||||||
|
},
|
||||||
|
linux: {
|
||||||
|
app: path.join(
|
||||||
|
config.PROJECT_ROOT,
|
||||||
|
`src-tauri/target/release/bundle/deb/${testName.toLowerCase()}_*.deb`,
|
||||||
|
),
|
||||||
|
installer: path.join(
|
||||||
|
config.PROJECT_ROOT,
|
||||||
|
`src-tauri/target/release/bundle/appimage/${testName.toLowerCase()}_*.AppImage`,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
win32: {
|
||||||
|
app: path.join(config.PROJECT_ROOT, `${testName}.exe`),
|
||||||
|
installer: path.join(config.PROJECT_ROOT, `${testName}.msi`),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const platform = process.platform;
|
||||||
|
const expectedFiles = outputFiles[platform] || outputFiles.darwin;
|
||||||
|
|
||||||
|
// Helper function to check if files exist (handles wildcards for Linux)
|
||||||
|
const checkFileExists = (filePath) => {
|
||||||
|
if (filePath.includes("*")) {
|
||||||
|
const dir = path.dirname(filePath);
|
||||||
|
const pattern = path.basename(filePath);
|
||||||
|
try {
|
||||||
|
const files = fs.readdirSync(dir);
|
||||||
|
const regex = new RegExp(pattern.replace(/\*/g, ".*"));
|
||||||
|
return files.some((file) => regex.test(file));
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fs.existsSync(filePath);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getActualFilePath = (filePath) => {
|
||||||
|
if (filePath.includes("*")) {
|
||||||
|
const dir = path.dirname(filePath);
|
||||||
|
const pattern = path.basename(filePath);
|
||||||
|
try {
|
||||||
|
const files = fs.readdirSync(dir);
|
||||||
|
const regex = new RegExp(pattern.replace(/\*/g, ".*"));
|
||||||
|
const match = files.find((file) => regex.test(file));
|
||||||
|
return match ? path.join(dir, match) : filePath;
|
||||||
|
} catch {
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filePath;
|
||||||
|
};
|
||||||
|
|
||||||
console.log(`🔧 Starting real build test for GitHub.com...`);
|
console.log(`🔧 Starting real build test for GitHub.com...`);
|
||||||
console.log(`📝 Expected output: ${appFile}`);
|
console.log(`📝 Expected output: ${expectedFiles.app}`);
|
||||||
|
|
||||||
const command = `node "${config.CLI_PATH}" "https://github.com" --name "${testName}" --width 1200 --height 800 --hide-title-bar`;
|
const command = `node "${config.CLI_PATH}" "https://github.com" --name "${testName}" --width 1200 --height 800 --hide-title-bar`;
|
||||||
|
|
||||||
@@ -630,8 +683,6 @@ class PakeTestRunner {
|
|||||||
|
|
||||||
let buildStarted = false;
|
let buildStarted = false;
|
||||||
let compilationStarted = false;
|
let compilationStarted = false;
|
||||||
let bundlingStarted = false;
|
|
||||||
let buildCompleted = false;
|
|
||||||
|
|
||||||
// Track progress without too much noise
|
// Track progress without too much noise
|
||||||
child.stdout.on("data", (data) => {
|
child.stdout.on("data", (data) => {
|
||||||
@@ -648,11 +699,9 @@ class PakeTestRunner {
|
|||||||
console.log(" ⚙️ Compiling...");
|
console.log(" ⚙️ Compiling...");
|
||||||
}
|
}
|
||||||
if (output.includes("Bundling")) {
|
if (output.includes("Bundling")) {
|
||||||
bundlingStarted = true;
|
|
||||||
console.log(" 📦 Bundling...");
|
console.log(" 📦 Bundling...");
|
||||||
}
|
}
|
||||||
if (output.includes("Built application at:")) {
|
if (output.includes("Built application at:")) {
|
||||||
buildCompleted = true;
|
|
||||||
console.log(" ✅ Build completed!");
|
console.log(" ✅ Build completed!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -661,31 +710,35 @@ class PakeTestRunner {
|
|||||||
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("Bundling")) bundlingStarted = true;
|
|
||||||
if (output.includes("Finished"))
|
if (output.includes("Finished"))
|
||||||
console.log(" ✅ Compilation finished!");
|
console.log(" ✅ Compilation finished!");
|
||||||
if (output.includes("Built application at:")) buildCompleted = true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Real timeout - 8 minutes for actual build
|
// Real timeout - 8 minutes for actual build
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
const appExists = fs.existsSync(appFile);
|
const appExists = checkFileExists(expectedFiles.app);
|
||||||
const dmgExists = fs.existsSync(dmgFile);
|
const installerExists = checkFileExists(expectedFiles.installer);
|
||||||
|
|
||||||
if (appExists) {
|
if (appExists) {
|
||||||
console.log(
|
console.log(
|
||||||
" 🎉 Build completed successfully (app file exists)!",
|
" 🎉 Build completed successfully (app file exists)!",
|
||||||
);
|
);
|
||||||
console.log(` 📱 App location: ${appFile}`);
|
console.log(
|
||||||
if (dmgExists) {
|
` 📱 App location: ${getActualFilePath(expectedFiles.app)}`,
|
||||||
console.log(` 💿 DMG location: ${dmgFile}`);
|
);
|
||||||
|
if (installerExists) {
|
||||||
|
console.log(
|
||||||
|
` 💿 Installer location: ${getActualFilePath(expectedFiles.installer)}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
console.log(" ✨ Build artifacts preserved for inspection");
|
console.log(" ✨ Build artifacts preserved for inspection");
|
||||||
child.kill("SIGTERM");
|
child.kill("SIGTERM");
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} else {
|
} else {
|
||||||
console.log(" ❌ Build timeout - no app file generated");
|
console.log(
|
||||||
console.log(` 📍 Expected location: ${appFile}`);
|
" ⚠️ Build process completed but no app file found",
|
||||||
|
);
|
||||||
|
console.log(` 📍 Expected location: ${expectedFiles.app}`);
|
||||||
child.kill("SIGTERM");
|
child.kill("SIGTERM");
|
||||||
reject(new Error("Real build test timeout"));
|
reject(new Error("Real build test timeout"));
|
||||||
}
|
}
|
||||||
@@ -694,18 +747,18 @@ class PakeTestRunner {
|
|||||||
child.on("close", (code) => {
|
child.on("close", (code) => {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
|
||||||
const appExists = fs.existsSync(appFile);
|
const appExists = checkFileExists(expectedFiles.app);
|
||||||
const dmgExists = fs.existsSync(dmgFile);
|
const installerExists = checkFileExists(expectedFiles.installer);
|
||||||
|
const actualAppPath = getActualFilePath(expectedFiles.app);
|
||||||
// DON'T track files for cleanup - let user see the results
|
const actualInstallerPath = getActualFilePath(
|
||||||
// this.trackTempFile(appFile);
|
expectedFiles.installer,
|
||||||
// this.trackTempFile(dmgFile);
|
);
|
||||||
|
|
||||||
if (appExists) {
|
if (appExists) {
|
||||||
console.log(" 🎉 Real build test SUCCESS: App file generated!");
|
console.log(" 🎉 Real build test SUCCESS: App file generated!");
|
||||||
console.log(` 📱 App location: ${appFile}`);
|
console.log(` 📱 App location: ${actualAppPath}`);
|
||||||
if (dmgExists) {
|
if (installerExists) {
|
||||||
console.log(` 💿 DMG location: ${dmgFile}`);
|
console.log(` 💿 Installer location: ${actualInstallerPath}`);
|
||||||
}
|
}
|
||||||
console.log(" ✨ Build artifacts preserved for inspection");
|
console.log(" ✨ Build artifacts preserved for inspection");
|
||||||
resolve(true);
|
resolve(true);
|
||||||
@@ -713,7 +766,7 @@ class PakeTestRunner {
|
|||||||
console.log(
|
console.log(
|
||||||
" ⚠️ Build process completed but no app file found",
|
" ⚠️ Build process completed but no app file found",
|
||||||
);
|
);
|
||||||
console.log(` 📍 Expected location: ${appFile}`);
|
console.log(` 📍 Expected location: ${expectedFiles.app}`);
|
||||||
resolve(false);
|
resolve(false);
|
||||||
} else {
|
} else {
|
||||||
reject(new Error(`Real build test failed with code ${code}`));
|
reject(new Error(`Real build test failed with code ${code}`));
|
||||||
@@ -762,9 +815,6 @@ class PakeTestRunner {
|
|||||||
|
|
||||||
let buildStarted = false;
|
let buildStarted = false;
|
||||||
let compilationStarted = false;
|
let compilationStarted = false;
|
||||||
let bundlingStarted = false;
|
|
||||||
let buildCompleted = false;
|
|
||||||
let multiArchDetected = false;
|
|
||||||
|
|
||||||
// Track progress
|
// Track progress
|
||||||
child.stdout.on("data", (data) => {
|
child.stdout.on("data", (data) => {
|
||||||
@@ -784,11 +834,9 @@ class PakeTestRunner {
|
|||||||
output.includes("universal-apple-darwin") ||
|
output.includes("universal-apple-darwin") ||
|
||||||
output.includes("Universal")
|
output.includes("Universal")
|
||||||
) {
|
) {
|
||||||
multiArchDetected = true;
|
|
||||||
console.log(" 🔀 Universal binary target detected");
|
console.log(" 🔀 Universal binary target detected");
|
||||||
}
|
}
|
||||||
if (output.includes("Bundling")) {
|
if (output.includes("Bundling")) {
|
||||||
bundlingStarted = true;
|
|
||||||
console.log(" 📦 Bundling universal binary...");
|
console.log(" 📦 Bundling universal binary...");
|
||||||
}
|
}
|
||||||
if (output.includes("Built application at:")) {
|
if (output.includes("Built application at:")) {
|
||||||
@@ -1029,7 +1077,7 @@ Usage: node tests/index.js [options]
|
|||||||
|
|
||||||
Options:
|
Options:
|
||||||
--unit Run unit tests (default)
|
--unit Run unit tests (default)
|
||||||
--integration Run integration tests (default)
|
--integration Run integration tests (default)
|
||||||
--builder Run builder tests (default)
|
--builder Run builder tests (default)
|
||||||
--pake-cli Run pake-cli GitHub Actions tests
|
--pake-cli Run pake-cli GitHub Actions tests
|
||||||
--e2e, --full Run end-to-end tests
|
--e2e, --full Run end-to-end tests
|
||||||
|
|||||||
Reference in New Issue
Block a user