forked from wangziqi/gongxue-base
chore: harden h5 launch evidence gate
This commit is contained in:
@@ -24,6 +24,12 @@ const portals = [
|
||||
},
|
||||
];
|
||||
|
||||
function parseArgs(argv) {
|
||||
return {
|
||||
json: argv.includes('--json'),
|
||||
};
|
||||
}
|
||||
|
||||
const allowedRuntimeConfigKeys = new Set([
|
||||
'portal',
|
||||
'apiBaseUrl',
|
||||
@@ -363,6 +369,7 @@ function summarize(results) {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const options = parseArgs(process.argv.slice(2));
|
||||
const api = await createMockApiServer();
|
||||
try {
|
||||
const results = [];
|
||||
@@ -370,21 +377,47 @@ async function main() {
|
||||
results.push(await smokePortal(portal, api));
|
||||
}
|
||||
const summary = summarize(results);
|
||||
console.log(`Taro H5 static smoke: ${summary.fail} fail(s), ${summary.pass} pass(es)`);
|
||||
for (const result of results) {
|
||||
console.log(`[PORTAL] ${result.portal} ${result.staticBaseUrl} -> ${result.landingPath}`);
|
||||
for (const check of result.checks) {
|
||||
console.log(`[${check.ok ? 'PASS' : 'FAIL'}] ${check.id}: ${check.detail}`);
|
||||
}
|
||||
}
|
||||
const resolveRequests = api.requests.filter(item => item.path === '/api/tenant/resolve');
|
||||
console.log(`[MOCK API] tenant resolve requests=${resolveRequests.length}`);
|
||||
const payload = {
|
||||
summary: {
|
||||
fail: summary.fail + (resolveRequests.length === portals.length ? 0 : 1),
|
||||
pass: summary.pass + (resolveRequests.length === portals.length ? 1 : 0),
|
||||
portals: portals.length,
|
||||
tenantResolveRequests: resolveRequests.length,
|
||||
},
|
||||
portals: results,
|
||||
checks: [
|
||||
...summary.checks.map(item => ({
|
||||
status: item.ok ? 'pass' : 'fail',
|
||||
id: item.id,
|
||||
detail: item.detail,
|
||||
})),
|
||||
{
|
||||
status: resolveRequests.length === portals.length ? 'pass' : 'fail',
|
||||
id: 'mock_api.tenant_resolve_count',
|
||||
detail: `expected=${portals.length} actual=${resolveRequests.length}`,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
if (options.json) {
|
||||
console.log(JSON.stringify(payload, null, 2));
|
||||
} else {
|
||||
console.log(`Taro H5 static smoke: ${payload.summary.fail} fail(s), ${payload.summary.pass} pass(es)`);
|
||||
for (const result of results) {
|
||||
console.log(`[PORTAL] ${result.portal} ${result.staticBaseUrl} -> ${result.landingPath}`);
|
||||
for (const check of result.checks) {
|
||||
console.log(`[${check.ok ? 'PASS' : 'FAIL'}] ${check.id}: ${check.detail}`);
|
||||
}
|
||||
}
|
||||
console.log(`[MOCK API] tenant resolve requests=${resolveRequests.length}`);
|
||||
}
|
||||
if (resolveRequests.length !== portals.length) {
|
||||
console.log(`[FAIL] mock_api.tenant_resolve_count: expected ${portals.length}, got ${resolveRequests.length}`);
|
||||
if (!options.json) console.log(`[FAIL] mock_api.tenant_resolve_count: expected ${portals.length}, got ${resolveRequests.length}`);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
if (summary.fail > 0) process.exitCode = 1;
|
||||
if (payload.summary.fail > 0) process.exitCode = 1;
|
||||
} finally {
|
||||
await api.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user