Initial clean project import
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
const { _electron: electron } = require('playwright');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const projectRoot = path.resolve(__dirname, '..', '..');
|
||||
const electronExe = path.join(projectRoot, 'node_modules', 'electron', 'dist', 'electron.exe');
|
||||
const mainScript = path.join(projectRoot, 'tools', 'oem-batch-builder', 'main.cjs');
|
||||
const assetsDir = path.join(projectRoot, 'oem-assets');
|
||||
const smokeUserDataDir = path.join(projectRoot, 'tools', 'oem-batch-builder', 'runs', 'ui-smoke-user-data');
|
||||
|
||||
function asset(name) {
|
||||
const filePath = path.join(assetsDir, name);
|
||||
if (!fs.existsSync(filePath)) throw new Error(`Missing test asset: ${filePath}`);
|
||||
return filePath;
|
||||
}
|
||||
|
||||
async function runCase(label, buildCommand, waitMs) {
|
||||
const app = await electron.launch({
|
||||
executablePath: electronExe,
|
||||
args: [`--user-data-dir=${smokeUserDataDir}`, mainScript],
|
||||
cwd: projectRoot,
|
||||
env: {
|
||||
...process.env,
|
||||
ELECTRON_ENABLE_LOGGING: '1',
|
||||
},
|
||||
});
|
||||
|
||||
const page = await app.firstWindow();
|
||||
await page.waitForSelector('#runBtn', { timeout: 15000 });
|
||||
|
||||
const job = {
|
||||
id: `ui-smoke-${Date.now()}`,
|
||||
enabled: true,
|
||||
brandName: 'UI Smoke Test',
|
||||
brandSlogan: 'Smoke',
|
||||
brandShortName: 'UISmokeTest',
|
||||
brandDisplayName: 'UI Smoke Test',
|
||||
apiBaseUrl: 'http://152.136.232.83:3002/api',
|
||||
version: '4.9.9',
|
||||
buildCommand,
|
||||
assets: {
|
||||
qrcodePath: asset('qrcode.png'),
|
||||
logoPath: asset('logo.png'),
|
||||
iconPath: asset('icon.png'),
|
||||
loginBgPath: asset('login-bg.png'),
|
||||
},
|
||||
status: 'idle',
|
||||
message: '',
|
||||
};
|
||||
|
||||
await page.evaluate((payload) => {
|
||||
localStorage.setItem('oem-batch-builder-jobs-v3', JSON.stringify([payload]));
|
||||
location.reload();
|
||||
}, job);
|
||||
|
||||
await page.waitForSelector('#runBtn', { timeout: 15000 });
|
||||
await page.click('#runBtn');
|
||||
await page.waitForTimeout(waitMs);
|
||||
|
||||
const processAlive = !app.process().killed;
|
||||
const windows = app.windows().filter(win => !win.isClosed());
|
||||
const logText = await page.locator('#logBox').textContent().catch(() => '');
|
||||
const statusText = await page.locator('.status').first().textContent().catch(() => '');
|
||||
|
||||
console.log(JSON.stringify({
|
||||
label,
|
||||
processAlive,
|
||||
windowCount: windows.length,
|
||||
statusText,
|
||||
logTail: String(logText || '').slice(-1000),
|
||||
}, null, 2));
|
||||
|
||||
if (!processAlive || windows.length === 0) {
|
||||
throw new Error(`${label}: OEM tool exited or window closed`);
|
||||
}
|
||||
|
||||
await app.close();
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await runCase('short-command', 'node -e "console.log(123)"', 5000);
|
||||
await runCase('npm-build-start', 'npm run build', 45000);
|
||||
})().catch(error => {
|
||||
console.error(error && error.stack ? error.stack : error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user