From 31d12d8cc8d323c9eb835789054955e77d802a58 Mon Sep 17 00:00:00 2001 From: lucaronin Date: Sat, 25 Apr 2026 19:51:41 +0200 Subject: [PATCH] test: stabilize smoke web server --- playwright.smoke.config.ts | 2 +- scripts/playwright-smoke-server.mjs | 32 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 scripts/playwright-smoke-server.mjs diff --git a/playwright.smoke.config.ts b/playwright.smoke.config.ts index cc250cef..c11fc6ef 100644 --- a/playwright.smoke.config.ts +++ b/playwright.smoke.config.ts @@ -30,7 +30,7 @@ export default defineConfig({ }, projects: [{ name: 'chromium', use: { browserName: 'chromium' } }], webServer: { - command: `pnpm dev --host 127.0.0.1 --port ${port} --strictPort`, + command: `node scripts/playwright-smoke-server.mjs ${port}`, url: baseURL, reuseExistingServer, timeout: 30_000, diff --git a/scripts/playwright-smoke-server.mjs b/scripts/playwright-smoke-server.mjs new file mode 100644 index 00000000..be2d83fd --- /dev/null +++ b/scripts/playwright-smoke-server.mjs @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +import { spawn } from 'node:child_process' + +const port = process.argv[2] ?? process.env.PORT ?? '41741' + +const child = spawn( + 'pnpm', + ['dev', '--host', '127.0.0.1', '--port', port, '--strictPort'], + { + cwd: process.cwd(), + env: process.env, + stdio: ['pipe', 'inherit', 'inherit'], + }, +) + +function forwardSignal(signal) { + if (child.killed) return + child.kill(signal) +} + +process.on('SIGINT', () => forwardSignal('SIGINT')) +process.on('SIGTERM', () => forwardSignal('SIGTERM')) + +child.on('exit', (code, signal) => { + if (signal) { + process.kill(process.pid, signal) + return + } + + process.exit(code ?? 1) +})