Testem
This page assumes the forwarder and the test helper change from Common setups, and that testem.js already launches holodeck as Server setup describes. Tested on testem 3.21.
Add the middleware
Testem's middleware option takes functions that receive its express app. Import the forwarder and mount it.
module.exports = async function () {
const holodeck = (await import('@warp-drive/holodeck')).default;
const { forwardToHolodeck } = await import('./forward-to-holodeck.mjs');
await holodeck.launchProgram({ port: 7358 });
process.on('beforeExit', async () => {
await holodeck.endProgram();
});
return {
middleware: [(app) => app.use(forwardToHolodeck())],
// ... the rest of your testem config
};
};Testem applies middleware before proxies, so a proxies entry for your real API under /api can stay: the forwarder takes the requests holodeck tagged and passes the rest on to it. proxies itself cannot reach holodeck, for the reason Common setups gives.
Run it
Run pnpm test. The suite passes with the mock server on testem's own origin. Nothing else about the run changes: testem still launches holodeck on 7358, still serves the test page on a port of its own, and fixtures still record and replay from .mock-cache.
Related
- Vite dev server does the same for the page at
/tests, with the same forwarder. - Server setup is where testem launches holodeck.