feat(server): healthz, testable app, local dev script (P0-3)
This commit is contained in:
23
server/test/helpers.js
Normal file
23
server/test/helpers.js
Normal file
@@ -0,0 +1,23 @@
|
||||
/* Test helpers: start the real server on a random port with an in-memory database. */
|
||||
'use strict';
|
||||
process.env.NODE_ENV = 'test';
|
||||
process.env.DB_FILE = ':memory:';
|
||||
delete process.env.JWT_SECRET;
|
||||
|
||||
const { listen } = require('../app');
|
||||
|
||||
async function startServer() {
|
||||
const srv = await listen(0);
|
||||
const base = 'http://127.0.0.1:' + srv.address().port;
|
||||
const json = async (method, path, body, token) => {
|
||||
const res = await fetch(base + path, {
|
||||
method,
|
||||
headers: Object.assign({ 'Content-Type': 'application/json' }, token ? { Authorization: 'Bearer ' + token } : {}),
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
});
|
||||
return { status: res.status, body: await res.json().catch(() => null) };
|
||||
};
|
||||
return { base, json, close: () => new Promise(r => { srv.closeAllConnections(); srv.close(r); }) };
|
||||
}
|
||||
|
||||
module.exports = { startServer };
|
||||
Reference in New Issue
Block a user