Simplify port-from handling and typing

This commit is contained in:
Chris Wanstrath 2026-03-12 14:22:35 -07:00
parent d22b5fbcea
commit c71a34cc85

View File

@ -94,14 +94,14 @@ program
const start = performance.now()
const results: TestResult[] = []
const cwd = process.cwd()
const portFrom = opts.portFrom ? parseInt(opts.portFrom, 10) : undefined
if (portFrom !== undefined && Number.isNaN(portFrom)) {
const portFrom = parseInt(opts.portFrom, 10)
if (Number.isNaN(portFrom)) {
console.error("--port-from must be an integer")
process.exit(1)
}
let nextPort = portFrom
const runOne = async (filePath: string, port: number | undefined) => {
const runOne = async (filePath: string, port: number) => {
const content = await readFile(filePath, "utf-8")
const parsed = parse(relative(cwd, filePath), content)
@ -125,7 +125,7 @@ program
}
}
Object.assign(envVars, setupEnvVars, userEnvVars)
if (port !== undefined && !("PORT" in userEnvVars) && !("PORT" in setupEnvVars)) {
if (!("PORT" in userEnvVars) && !("PORT" in setupEnvVars)) {
envVars["PORT"] = String(port)
}
const merged: ShoutFile = { ...parsed, commands: [...setupCommands, ...parsed.commands] }
@ -203,7 +203,7 @@ program
}
if (opts.parallel) {
const all = await Promise.all(files.map(f => runOne(f, nextPort !== undefined ? nextPort++ : undefined)))
const all = await Promise.all(files.map(f => runOne(f, nextPort++)))
for (const r of all) {
printDots(r)
results.push(r)
@ -211,7 +211,7 @@ program
process.stdout.write("\n")
} else {
for (const filePath of files) {
const r = await runOne(filePath, nextPort !== undefined ? nextPort++ : undefined)
const r = await runOne(filePath, nextPort++)
printDots(r)
results.push(r)
}