验证样例文章验收冒烟流程

This commit is contained in:
czj
2026-07-01 15:12:13 +08:00
parent 762380c937
commit 66fee182f5
3 changed files with 27 additions and 4 deletions
+12 -3
View File
@@ -46,7 +46,7 @@ export async function main(rawArgs = process.argv.slice(2)) {
mkdirSync(reportDir, { recursive: true });
const port = args.port ? Number(args.port) : await findAvailablePort(3000);
const baseURL = args.baseURL || `http://127.0.0.1:${port}`;
const baseURL = args.baseURL || baseURLForPort(port);
const appDataDir = join(reportDir, "app-data");
mkdirSync(appDataDir, { recursive: true });
@@ -70,7 +70,7 @@ export async function main(rawArgs = process.argv.slice(2)) {
stdio: ["ignore", "pipe", "pipe"],
});
captureServerLogs(serverProcess, reportDir, runEnv);
await waitForServer(baseURL, 120000);
await waitForServer(baseURL, 120000, serverProcess);
}
status = await runPlaywright(runEnv, Boolean(args.headed));
@@ -108,6 +108,10 @@ export function parseArgs(rawArgs) {
return parsed;
}
export function baseURLForPort(port) {
return `http://localhost:${port}`;
}
export function parseEnvFile(content) {
const values = {};
for (const line of content.split(/\r?\n/)) {
@@ -177,9 +181,14 @@ export function redact(text, secrets) {
return next;
}
async function waitForServer(baseURL, timeoutMs) {
export async function waitForServer(baseURL, timeoutMs, serverProcess = null) {
const started = Date.now();
while (Date.now() - started < timeoutMs) {
if (serverProcess?.exitCode !== null) {
throw new Error(
`dev server exited before ${baseURL} became ready; see server.log in the report directory`,
);
}
try {
const response = await fetch(baseURL, { method: "HEAD" });
if (response.ok) return;