|
1 | 1 | import { resolve } from "node:path"; |
2 | | -import dedent from "ts-dedent"; |
3 | | -import { afterAll, beforeAll, describe, it } from "vitest"; |
| 2 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
4 | 3 | import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived"; |
5 | 4 |
|
6 | | -describe("Containers local dev", () => { |
7 | | - let stop: (() => Promise<unknown>) | undefined, getOutput: () => string; |
| 5 | +// TODO: we'll want to run this on all OSes but that will require some setup because docker is not installed by default on macos and windows |
| 6 | +describe.skipIf(process.platform !== "linux" && process.env.CI === "true")( |
| 7 | + "Containers local dev", |
| 8 | + () => { |
| 9 | + it("starts up container service if containers are in config", async () => { |
| 10 | + const { stop, getOutput } = await runWranglerDev( |
| 11 | + resolve(__dirname, ".."), |
| 12 | + ["--port=0", "--inspector-port=0"] |
| 13 | + ); |
| 14 | + expect(getOutput()).toContain(`Hello from ContainerController!`); |
| 15 | + await stop?.(); |
| 16 | + }); |
8 | 17 |
|
9 | | - beforeAll(async () => { |
10 | | - ({ stop, getOutput } = await runWranglerDev(resolve(__dirname, ".."), [ |
11 | | - "--port=0", |
12 | | - "--inspector-port=0", |
13 | | - ])); |
14 | | - }); |
| 18 | + it("doesn't start up container service if no containers are present", async () => { |
| 19 | + const { stop, getOutput } = await runWranglerDev( |
| 20 | + resolve(__dirname, ".."), |
| 21 | + ["--port=0", "--inspector-port=0", "-c=wrangler.no-containers.jsonc"] |
| 22 | + ); |
| 23 | + const output = getOutput(); |
| 24 | + expect(output).not.toContain("Hello from ContainerController!"); |
| 25 | + await stop?.(); |
| 26 | + }); |
15 | 27 |
|
16 | | - afterAll(async () => { |
17 | | - await stop?.(); |
18 | | - }); |
| 28 | + it("doesn't start up container service if enable_containers is set to false via config", async () => { |
| 29 | + const { stop, getOutput } = await runWranglerDev( |
| 30 | + resolve(__dirname, ".."), |
| 31 | + [ |
| 32 | + "--port=0", |
| 33 | + "--inspector-port=0", |
| 34 | + "-c=wrangler.enable-containers.jsonc", |
| 35 | + ] |
| 36 | + ); |
| 37 | + const output = getOutput(); |
| 38 | + expect(output).not.toContain("Hello from ContainerController!"); |
| 39 | + await stop?.(); |
| 40 | + }); |
19 | 41 |
|
20 | | - it("starts up container service if containers are in config", async ({ |
21 | | - expect, |
22 | | - }) => { |
23 | | - expect(getOutput()).toContain(dedent` |
24 | | - Hello from ContainerService! |
25 | | - Container Options: { |
26 | | - "Container": { |
27 | | - "image": "./Dockerfile", |
28 | | - "maxInstances": 2 |
29 | | - } |
30 | | - } |
31 | | - `); |
32 | | - }); |
| 42 | + it("doesn't start up container service if --enable-containers is set to false via CLI", async () => { |
| 43 | + const { stop, getOutput } = await runWranglerDev( |
| 44 | + resolve(__dirname, ".."), |
| 45 | + ["--port=0", "--inspector-port=0", "--enable-containers=false"] |
| 46 | + ); |
| 47 | + expect(getOutput()).not.toContain(`Hello from ContainerController!`); |
| 48 | + await stop?.(); |
| 49 | + }); |
33 | 50 |
|
34 | | - it("doesn't start up container service if no containers are present", async ({ |
35 | | - expect, |
36 | | - }) => { |
37 | | - await stop?.(); |
38 | | - ({ stop, getOutput } = await runWranglerDev(resolve(__dirname, ".."), [ |
39 | | - "--port=0", |
40 | | - "--inspector-port=0", |
41 | | - "-c=wrangler.no-containers.jsonc", |
42 | | - ])); |
43 | | - expect(getOutput()).not.toContain(`Hello from ContainerService!`); |
44 | | - expect(getOutput()).toContain("Ready on"); |
45 | | - }); |
46 | | -}); |
| 51 | + // TODO: not entirely sure how to make this test work without logging random stuff |
| 52 | + it("gets docker path from env var", async () => { |
| 53 | + vi.stubEnv("WRANGLER_CONTAINERS_DOCKER_PATH", "blah/docker"); |
| 54 | + const { stop, getOutput } = await runWranglerDev( |
| 55 | + resolve(__dirname, ".."), |
| 56 | + ["--port=0", "--inspector-port=0"] |
| 57 | + ); |
| 58 | + expect(getOutput()).toContain("blah/docker"); |
| 59 | + await stop?.(); |
| 60 | + }); |
| 61 | + } |
| 62 | +); |
0 commit comments