This commit is contained in:
xsl
2026-10-10 14:23:43 +08:00
parent 658b232a39
commit 2a7593b736
11 changed files with 528 additions and 149 deletions
+10 -5
View File
@@ -8,9 +8,14 @@
*/
import { execSync } from 'node:child_process';
import { pathToFileURL } from 'node:url';
import path from 'node:path';
import os from 'node:os';
import fs from 'node:fs';
const pwRoot = execSync('npm root -g', { encoding: 'utf8' }).trim();
const { chromium } = await import(pathToFileURL(pwRoot + '/playwright/index.mjs').href);
const pwModule = process.env.PLAYWRIGHT_MODULE || path.join(execSync('npm root -g', { encoding: 'utf8' }).trim(), 'playwright/index.mjs');
const { chromium } = await import(pathToFileURL(pwModule).href);
const outputDir = process.env.E2E_OUTPUT_DIR || os.tmpdir();
fs.mkdirSync(outputDir, { recursive: true });
const BASE = process.env.BASE_URL || 'http://127.0.0.1:8080';
const EXPECTED = [
@@ -176,12 +181,12 @@ try {
check('流程语音无截断', cut.length === 0, cut.map((v) => `${v.id}@${v.cutAt}/${v.dur}`).join(','));
check('页面无脚本异常', pageErrors.length === 0, pageErrors.join(' | '));
await page.screenshot({ path: '/tmp/juzi-e2e-report.png', fullPage: true });
console.log('截图 /tmp/juzi-e2e-report.png');
await page.screenshot({ path: path.join(outputDir, 'juzi-e2e-report.png'), fullPage: true });
console.log('截图 ' + path.join(outputDir, 'juzi-e2e-report.png'));
} catch (err) {
console.error('RUN ERROR', err);
fails.push(String(err && err.message || err));
try { await page.screenshot({ path: '/tmp/juzi-e2e-fail.png', fullPage: true }); } catch (e) {}
try { await page.screenshot({ path: path.join(outputDir, 'juzi-e2e-fail.png'), fullPage: true }); } catch (e) {}
} finally {
await browser.close();
}