Files
upstream-hocuspocus/tests/utils/newHocuspocus.ts
upstream-mirror e0c588ca1c
Some checks failed
build / lint (22) (push) Failing after 17s
build / test (22) (push) Failing after 8s
build / lint (23) (push) Failing after 2s
build / build (22) (push) Has been skipped
build / build (23) (push) Has been skipped
build / test (23) (push) Failing after 4s
docsearch / docsearch (push) Failing after 1s
snapshot of https://github.com/ueberdosis/hocuspocus.git @ cf3cfa355b4d3bb61c6b6c80071f71783e32470e (2026-09-15)
2026-09-15 17:21:35 +05:00

36 lines
1.2 KiB
TypeScript

import type { ExecutionContext } from "ava";
import type { ServerConfiguration } from "@hocuspocus/server";
import { Server } from "@hocuspocus/server";
export const newHocuspocus = (
t: ExecutionContext,
options?: Partial<ServerConfiguration>,
) => {
const server = new Server({
// We don't need the logging in testing.
quiet: true,
// Binding something port 0 will end up on a random free port.
// That's helpful to run tests concurrently.
port: 0,
// Ava 6+ considers process.exit() in workers an error.
// Disable signal handlers to prevent that.
stopOnSignals: false,
// Add or overwrite settings, depending on the test case.
...options,
});
t.teardown(() => {
// Close WebSocket connections and shut down the HTTP server.
// We avoid calling server.destroy() because it triggers lifecycle
// hooks (onDestroy, afterUnloadDocument) which could run assertions
// after the test has finished (Ava 6+ treats this as an error).
// The _force-exit completion handler ensures the process exits
// even if some handles remain open.
server.hocuspocus.closeConnections();
server.httpServer.closeAllConnections();
server.httpServer.close();
});
return server.listen();
};