|
1 | 1 | import { resolve } from "node:path"; |
2 | 2 | import { fetch } from "undici"; |
3 | | -import { describe, it, test } from "vitest"; |
| 3 | +import { afterAll, beforeAll, describe, it, test } from "vitest"; |
4 | 4 | import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived"; |
5 | 5 |
|
6 | 6 | describe("nodejs compat", () => { |
| 7 | + let wrangler: Awaited<ReturnType<typeof runWranglerDev>>; |
| 8 | + |
| 9 | + beforeAll(async () => { |
| 10 | + wrangler = await runWranglerDev(resolve(__dirname, "../src"), [ |
| 11 | + "--port=0", |
| 12 | + "--inspector-port=0", |
| 13 | + ]); |
| 14 | + }); |
| 15 | + |
| 16 | + afterAll(async () => { |
| 17 | + await wrangler.stop(); |
| 18 | + }); |
7 | 19 | it("should work when running code requiring polyfills", async ({ |
8 | 20 | expect, |
9 | 21 | }) => { |
10 | | - const { ip, port, stop } = await runWranglerDev( |
11 | | - resolve(__dirname, "../src"), |
12 | | - ["--port=0", "--inspector-port=0"] |
13 | | - ); |
14 | | - try { |
15 | | - const response = await fetch(`http://${ip}:${port}/test-process`); |
16 | | - const body = await response.text(); |
17 | | - expect(body).toMatchInlineSnapshot(`"OK!"`); |
| 22 | + const { ip, port } = wrangler; |
| 23 | + const response = await fetch(`http://${ip}:${port}/test-process`); |
| 24 | + const body = await response.text(); |
| 25 | + expect(body).toMatchInlineSnapshot(`"OK!"`); |
18 | 26 |
|
19 | | - // Disabling actually querying the database since we are getting this error: |
20 | | - // > too many connections for role 'reader' |
21 | | - // const response = await fetch(`http://${ip}:${port}/query`); |
22 | | - // const body = await response.text(); |
23 | | - // console.log(body); |
24 | | - // const result = JSON.parse(body) as { id: string }; |
25 | | - // expect(result.id).toEqual("1"); |
26 | | - } finally { |
27 | | - await stop(); |
28 | | - } |
| 27 | + // Disabling actually querying the database since we are getting this error: |
| 28 | + // > too many connections for role 'reader' |
| 29 | + // const response = await fetch(`http://${ip}:${port}/query`); |
| 30 | + // const body = await response.text(); |
| 31 | + // console.log(body); |
| 32 | + // const result = JSON.parse(body) as { id: string }; |
| 33 | + // expect(result.id).toEqual("1"); |
29 | 34 | }); |
30 | 35 |
|
31 | 36 | it("should be able to call `getRandomValues()` bound to any object", async ({ |
32 | 37 | expect, |
33 | 38 | }) => { |
34 | | - const { ip, port, stop } = await runWranglerDev( |
35 | | - resolve(__dirname, "../src"), |
36 | | - ["--port=0", "--inspector-port=0"] |
37 | | - ); |
38 | | - try { |
39 | | - const response = await fetch(`http://${ip}:${port}/test-random`); |
40 | | - const body = await response.json(); |
41 | | - expect(body).toEqual([ |
42 | | - expect.any(String), |
43 | | - expect.any(String), |
44 | | - expect.any(String), |
45 | | - expect.any(String), |
46 | | - ]); |
47 | | - } finally { |
48 | | - await stop(); |
49 | | - } |
| 39 | + const { ip, port } = wrangler; |
| 40 | + const response = await fetch(`http://${ip}:${port}/test-random`); |
| 41 | + const body = await response.json(); |
| 42 | + expect(body).toEqual([ |
| 43 | + expect.any(String), |
| 44 | + expect.any(String), |
| 45 | + expect.any(String), |
| 46 | + expect.any(String), |
| 47 | + ]); |
50 | 48 | }); |
51 | 49 |
|
52 | 50 | test("crypto.X509Certificate is implemented", async ({ expect }) => { |
53 | | - const { ip, port, stop } = await runWranglerDev( |
54 | | - resolve(__dirname, "../src"), |
55 | | - ["--port=0", "--inspector-port=0"] |
56 | | - ); |
57 | | - try { |
58 | | - const response = await fetch( |
59 | | - `http://${ip}:${port}/test-x509-certificate` |
60 | | - ); |
61 | | - await expect(response.text()).resolves.toBe(`"OK!"`); |
62 | | - } finally { |
63 | | - await stop(); |
64 | | - } |
| 51 | + const { ip, port } = wrangler; |
| 52 | + const response = await fetch(`http://${ip}:${port}/test-x509-certificate`); |
| 53 | + await expect(response.text()).resolves.toBe(`"OK!"`); |
65 | 54 | }); |
66 | 55 |
|
67 | 56 | test("import unenv aliased packages", async ({ expect }) => { |
68 | | - const { ip, port, stop } = await runWranglerDev( |
69 | | - resolve(__dirname, "../src"), |
70 | | - ["--port=0", "--inspector-port=0"] |
71 | | - ); |
72 | | - try { |
73 | | - const response = await fetch(`http://${ip}:${port}/test-require-alias`); |
74 | | - await expect(response.text()).resolves.toBe(`"OK!"`); |
75 | | - } finally { |
76 | | - await stop(); |
77 | | - } |
| 57 | + const { ip, port } = wrangler; |
| 58 | + const response = await fetch(`http://${ip}:${port}/test-require-alias`); |
| 59 | + await expect(response.text()).resolves.toBe(`"OK!"`); |
78 | 60 | }); |
79 | 61 |
|
80 | 62 | test("unenv preset", async ({ expect }) => { |
81 | | - const { ip, port, stop } = await runWranglerDev( |
82 | | - resolve(__dirname, "../src"), |
83 | | - ["--port=0", "--inspector-port=0"] |
84 | | - ); |
85 | | - try { |
86 | | - const response = await fetch(`http://${ip}:${port}/test-unenv-preset`); |
87 | | - await expect(response.text()).resolves.toBe("OK!"); |
88 | | - } finally { |
89 | | - await stop(); |
90 | | - } |
| 63 | + const { ip, port } = wrangler; |
| 64 | + const response = await fetch(`http://${ip}:${port}/test-unenv-preset`); |
| 65 | + await expect(response.text()).resolves.toBe("OK!"); |
91 | 66 | }); |
92 | 67 | }); |
0 commit comments