tools: test nginx, generated tile fixtures and the tile group (#24)
This commit is contained in:
@@ -61,23 +61,25 @@ async function waitForHealth(handle) {
|
||||
}
|
||||
|
||||
// Starts the server and waits for /healthz. Resolves to a handle; stopServer() tears it down.
|
||||
// `defines` selects a build variant (e.g. a -d:leakfault build), `env` extra environment for it.
|
||||
// `defines` selects a build variant (e.g. a -d:leakfault build), `env` extra environment for it,
|
||||
// `publicOrigin` overrides the configured origin (a test nginx in front of the server).
|
||||
export async function startServer(opts = {}) {
|
||||
const ownStateDir = opts.stateDir === undefined
|
||||
const stateDir = opts.stateDir ?? makeStateDir()
|
||||
const args = opts.args ?? []
|
||||
const bin = buildServer({ defines: opts.defines })
|
||||
const port = opts.port ?? await freePort()
|
||||
const publicOrigin = opts.publicOrigin ?? baseUrl(port)
|
||||
refuseLivePort(port)
|
||||
fs.mkdirSync(stateDir, { recursive: true })
|
||||
const logPath = path.join(stateDir, 'server.log')
|
||||
const logFd = fs.openSync(logPath, 'a')
|
||||
const child = spawn(bin, [`--port=${port}`, `--state-dir=${stateDir}`,
|
||||
`--public-origin=${baseUrl(port)}`, ...args],
|
||||
`--public-origin=${publicOrigin}`, ...args],
|
||||
{ cwd: projectRoot, stdio: ['ignore', logFd, logFd],
|
||||
env: { ...process.env, ...(opts.env ?? {}) } })
|
||||
const handle = {
|
||||
port, origin: baseUrl(port), stateDir, dbPath: path.join(stateDir, 'state.db'),
|
||||
port, origin: baseUrl(port), publicOrigin, stateDir, dbPath: path.join(stateDir, 'state.db'),
|
||||
logPath, child, log: () => fs.readFileSync(logPath, 'utf8'),
|
||||
}
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user