forked from cloudflare/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
/
unstableDev.test.ts
62 lines (55 loc) · 1.48 KB
/
unstableDev.test.ts
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
import { fetch } from "undici";
import { vi } from "vitest";
import {
registerWorker,
startWorkerRegistry,
stopWorkerRegistry,
} from "../dev-registry";
vi.unmock("undici");
/**
* Sometimes the devRegistry killed by some reason, the register worker will to restart it.
*/
describe("unstable devRegistry testing", () => {
afterAll(async () => {
await stopWorkerRegistry();
});
it("should start the devRegistry if the devRegistry not start", async () => {
await registerWorker("test", {
port: 6789,
protocol: "http",
host: "localhost",
mode: "local",
durableObjects: [{ name: "testing", className: "testing" }],
});
const resp = await fetch("http://127.0.0.1:6284/workers");
if (resp) {
const parsedResp = (await resp.json()) as {
test: unknown;
};
expect(parsedResp.test).toBeTruthy();
}
});
it("should not restart the devRegistry if the devRegistry already start", async () => {
await startWorkerRegistry();
await fetch("http://127.0.0.1:6284/workers/init", {
method: "POST",
body: JSON.stringify({}),
});
await registerWorker("test", {
port: 6789,
protocol: "http",
host: "localhost",
mode: "local",
durableObjects: [{ name: "testing", className: "testing" }],
});
const resp = await fetch("http://127.0.0.1:6284/workers");
if (resp) {
const parsedResp = (await resp.json()) as {
test: unknown;
init: unknown;
};
expect(parsedResp.init).toBeTruthy();
expect(parsedResp.test).toBeTruthy();
}
});
});