* reinstate * start server manually * routing tests too * skip more * sleep more and fail if not 200 * use e2etest for content/ too * automatically start server for jest * does this work? * feedbacked * rename things * getting it to work * add dev dependency * install the right version * don't need to start that * fix package lock * update readme about it * feedbacked
36 lines
885 B
JavaScript
36 lines
885 B
JavaScript
import kill from 'kill-port'
|
|
import portUsed from 'port-used'
|
|
import got, { RequestError } from 'got'
|
|
|
|
export const PORT = 4000
|
|
|
|
// By default it's on
|
|
export const START_JEST_SERVER = Boolean(JSON.parse(process.env.START_JEST_SERVER || 1))
|
|
|
|
export async function isServerHealthy() {
|
|
try {
|
|
const res = await got.head(`http://localhost:${PORT}/healthz`, { retry: { limit: 0 } })
|
|
return res.statusCode === 200
|
|
} catch (err) {
|
|
// This exception is thrown if you can't even connect.
|
|
if (err instanceof RequestError) {
|
|
return false
|
|
}
|
|
throw err
|
|
}
|
|
}
|
|
|
|
export function killServer() {
|
|
kill(PORT, 'tcp')
|
|
.then(() => {
|
|
console.log(`Killed what was on :${PORT}`)
|
|
})
|
|
.catch((error) => {
|
|
console.log(`Unable to kill whatever was on :${PORT}:`, error)
|
|
})
|
|
}
|
|
|
|
export async function isPortRunning() {
|
|
return await portUsed.check(PORT)
|
|
}
|