Set Up Holodeck
Use this skill when a test suite needs to mock HTTP and nothing is wired up yet. Holodeck is a real HTTPS mock server rather than an in-page interceptor, so it needs a certificate, a port, and two configuration calls before any mock works.
Steps
Install
mkcert, then install the package pinned to an exact canary version.@warp-drive/coreis a required peer.shbrew install mkcert # or the platform equivalent pnpm add -E @warp-drive/holodeck@canaryIssue and trust a certificate once per machine, then restart the terminal so the exported variables take effect.
shpnpm dlx @warp-drive/holodeck ensure-certThe command stops with install instructions if
mkcertis missing. Otherwise it issues the certificate into the home directory, then writesHOLODECK_SSL_CERT_PATHandHOLODECK_SSL_KEY_PATHinto the profile of the shell named by$SHELL(bash,zsh, orfish). On any other shell it prints the two lines to add yourself and exits normally. The home-directory paths are also holodeck's defaults, so the certificate works without them.Start the server from the script that starts the test server, on the test server's port plus one. Run that script from the test app's own directory, because
launchProgramreadspackage.jsonfrom the working directory and writes.mock-cachethere.jsawait launch({ async setup(options) { await holodeck.launchProgram({ port: options.port + 1 }); }, async cleanup() { await holodeck.endProgram(); }, entry: './dist-test/index.html', });Point the app at the server in the test suite's boot file. Both calls are required and they do different jobs.
tsconst MockHost = `https://${window.location.hostname}:${Number(window.location.port) + 1}`; setBuildURLConfig({ host: MockHost, namespace: '' }); // aims the app's real requests setConfig({ host: MockHost }); // aims only the recording requestSetting
setConfigalone records fixtures that no request will ever read.Register the test id per test, against the test context object itself.
tssetupGlobalHooks((hooks) => { hooks.beforeEach(function (assert) { setTestId(this, assert.test.testId); }); hooks.afterEach(function () { setTestId(this, null); }); });Put
MockServerHandlerahead ofFetchin the request chain, constructed with that same test context. Usehandlers: [new MockServerHandler(this)]on a store, ormanager.use([new MockServerHandler(this), Fetch])on a bareRequestManager.
Notes
- Holodeck identifies a test by object identity, not by name. The object passed to
setTestId, tonew MockServerHandler(), and to every mock helper must be the same one. Usefunctiontest bodies sothisis the test context. - The
+ 1port convention is hardcoded twice, in the launcher and in the browser. Holodeck binds exactly the port it is given and never renegotiates, so both halves must agree. - There is no plaintext mode and no way to skip the certificate.
Related
- Full guide: Server Setup, Client Setup, and Test Framework Integration
- Related skills: Mock HTTP Requests in Tests for declaring mocks once the server runs