-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathworker-handler.test.ts
More file actions
70 lines (52 loc) · 2.06 KB
/
worker-handler.test.ts
File metadata and controls
70 lines (52 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { Application } from "@mainsail/kernel";
import { describe } from "@mainsail/test-runner";
import { CommitHandler, SetPeerCountHandler, StartHandler } from "./handlers/index.js";
import { WorkerScriptHandler } from "./worker-handler";
describe<{
subject: WorkerScriptHandler;
handler: any;
resolve: any;
}>("WorkerScriptHandler", ({ beforeEach, it, spy, stub }) => {
beforeEach((context) => {
// WorkerScriptHandler owns a private `new Application()`; stub the prototype so the
// handler resolutions and lifecycle calls stay in-process.
context.handler = { handle: async () => {} };
context.resolve = stub(Application.prototype, "resolve").returnValue(context.handler);
context.subject = new WorkerScriptHandler();
});
it("boot bootstraps the app with the flags and boots it", async ({ subject }) => {
const bootstrap = stub(Application.prototype, "bootstrap").resolvedValue(undefined);
const boot = stub(Application.prototype, "boot").resolvedValue(undefined);
const flags = { network: "testnet" } as any;
await subject.boot(flags);
bootstrap.calledWith({ flags });
boot.calledOnce();
});
it("dispose terminates the app", async ({ subject }) => {
const terminate = stub(Application.prototype, "terminate").resolvedValue(undefined);
await subject.dispose();
terminate.calledOnce();
});
it("start resolves the StartHandler and forwards the height", async ({ subject, handler, resolve }) => {
const handle = spy(handler, "handle");
await subject.start(42);
resolve.calledWith(StartHandler);
handle.calledWith(42);
});
it("setPeerCount resolves the SetPeerCountHandler and forwards the count", async ({
subject,
handler,
resolve,
}) => {
const handle = spy(handler, "handle");
await subject.setPeerCount(5);
resolve.calledWith(SetPeerCountHandler);
handle.calledWith(5);
});
it("commit resolves the CommitHandler and forwards the height", async ({ subject, handler, resolve }) => {
const handle = spy(handler, "handle");
await subject.commit(99);
resolve.calledWith(CommitHandler);
handle.calledWith(99);
});
});