AtlatestRepositorysigil-websocket
sigil-websocket / tree / test / integrationtest-native-websocket-connect-timeout.mjs
1
import path from "node:path";2
import { fileURLToPath } from "node:url";3
import { spawn } from "node:child_process";5
const here = path.dirname(fileURLToPath(import.meta.url));6
const repo = path.resolve(here, "../..");7
const dependencyRoots = [8
"sigil-stdlib", "sigil-socket", "sigil-tls", "sigil-crypto",9
].map((name) => path.join(repo, ".sigil", "deps", name, "src"));10
const args = [11
"-L", path.join(repo, "build/dev/lib"),12
...dependencyRoots.flatMap((root) => ["-L", root]),13
path.join(here, "native-connect-timeout-client.sgl"),14
];15
const child = spawn("sigil", args, {16
cwd: repo, env: process.env, stdio: ["ignore", "pipe", "pipe"],17
});18
let stdout = "";19
let stderr = "";20
child.stdout.on("data", (chunk) => { stdout += chunk; });21
child.stderr.on("data", (chunk) => { stderr += chunk; });22
const watchdog = setTimeout(() => child.kill("SIGKILL"), 3000);23
const status = await new Promise((resolve) => child.on("close", resolve));24
clearTimeout(watchdog);26
if (status !== 0 || !stdout.includes("native-websocket-connect-timeout-ok")) {27
throw new Error(`native timeout client failed (${status})\nstdout:\n${stdout}\nstderr:\n${stderr}`);28
}29
console.log("native-websocket-connect-timeout-integration-ok");