| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- /**
- * Temporary internal E2E probe (NOT committed; test-closure artifact only).
- * Reuses tests/e2e/helpers/auth.js loginAs for admin, then verifies the
- * authenticated /admin dashboard and the /frontend SPA render.
- * Credentials are injected from local machine.json via MACHINE_JSON_PATH;
- * nothing sensitive is printed.
- */
- const { chromium } = require('@playwright/test');
- const path = require('path');
- const BASE = process.env.PW_BASE_URL || 'http://cfc.iwintrue.com';
- const MACHINE_JSON = process.env.MACHINE_JSON_PATH;
- async function main() {
- const summary = { base: BASE, steps: {}, env: { machineJsonSet: !!MACHINE_JSON } };
- const launchOpts = { headless: true, args: ['--no-sandbox'] };
- if (process.env.CHROME_PATH) launchOpts.executablePath = process.env.CHROME_PATH;
- const browser = await chromium.launch(launchOpts);
- try {
- const auth = require(path.join(__dirname, 'tests', 'e2e', 'helpers', 'auth'));
- // loginAs reads MACHINE_JSON_PATH at require time (already set via env).
- // 1) Admin login
- const adminAuth = await auth.loginAs(browser, 'admin');
- summary.steps.adminLogin = {
- ok: !!(adminAuth && adminAuth.token),
- tokenLen: adminAuth && adminAuth.token ? adminAuth.token.length : 0,
- error: adminAuth && adminAuth.error ? String(adminAuth.error).slice(0, 120) : null
- };
- // 2) Authenticated /admin dashboard
- if (adminAuth && adminAuth.token) {
- const ctx = await browser.newContext();
- await ctx.addInitScript((t) => {
- try { localStorage.setItem('token', t); localStorage.setItem('access_token', t); } catch (e) {}
- }, adminAuth.token);
- const page = await ctx.newPage();
- const resp = await page.goto(BASE + '/admin', { waitUntil: 'domcontentloaded', timeout: 30000 });
- await page.waitForTimeout(2500);
- const title = await page.title();
- const hasSidebar = await page.locator('.sidebar-container, .el-menu, .el-aside, .el-container').count();
- summary.steps.adminDashboard = {
- ok: resp ? resp.status() < 500 : false,
- status: resp ? resp.status() : null,
- title: String(title).slice(0, 80),
- hasSidebar: hasSidebar > 0,
- url: page.url().slice(0, 100)
- };
- await ctx.close();
- } else {
- summary.steps.adminDashboard = { ok: false, note: 'skipped: no admin token' };
- }
- // 3) /frontend SPA
- const fctx = await browser.newContext();
- const fpage = await fctx.newPage();
- const fresp = await fpage.goto(BASE + '/frontend', { waitUntil: 'domcontentloaded', timeout: 30000 });
- await fpage.waitForTimeout(2500);
- const ftitle = await fpage.title();
- const fbody = (await fpage.content()).length;
- summary.steps.frontend = {
- ok: fresp ? fresp.status() < 500 : false,
- status: fresp ? fresp.status() : null,
- title: String(ftitle).slice(0, 80),
- bodyLen: fbody,
- url: fpage.url().slice(0, 100)
- };
- await fctx.close();
- } catch (e) {
- summary.fatal = String(e && e.message ? e.message : e).slice(0, 300);
- } finally {
- await browser.close();
- }
- require('fs').writeFileSync(path.join(__dirname, '_e2e_probe_result.json'),
- JSON.stringify(summary, null, 2));
- console.log(JSON.stringify(summary, null, 2));
- }
- main().then(() => process.exit(0)).catch((e) => { console.error(String(e).slice(0,300)); process.exit(1); });
|