Skip to content

Commit d02d25f

Browse files
committed
update tests and also don't build on a dry run
1 parent fd2fcc5 commit d02d25f

3 files changed

Lines changed: 57 additions & 15 deletions

File tree

packages/wrangler/src/__tests__/containers/config.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,9 @@ describe("getNormalizedContainerOptions", () => {
720720
expect(result[0].rollout_step_percentage).toBe(100);
721721
});
722722

723-
it("should set rollout_kind to none when containersRollout is none", async () => {
723+
it("should set rollout_kind to none when containersRollout is none", async ({
724+
expect,
725+
}) => {
724726
const config: Config = {
725727
name: "test-worker",
726728
configPath: "/test/wrangler.toml",

packages/wrangler/src/__tests__/containers/deploy.test.ts

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,9 @@ describe("wrangler deploy with containers", () => {
11321132
});
11331133
});
11341134

1135-
it("should skip Docker check and container deploy when --containers-rollout=none", async () => {
1135+
it("should skip Docker check and container deploy when --containers-rollout=none", async ({
1136+
expect,
1137+
}) => {
11361138
vi.stubEnv("WRANGLER_DOCKER_BIN", "/usr/bin/bad-docker-path");
11371139
writeWranglerConfig({
11381140
...DEFAULT_DURABLE_OBJECTS,
@@ -1143,7 +1145,7 @@ describe("wrangler deploy with containers", () => {
11431145

11441146
mockGetVersion("Galaxy-Class");
11451147
mockGetApplications([]);
1146-
mockCreateApplication();
1148+
mockCreateApplication(expect);
11471149

11481150
fs.writeFileSync(
11491151
"index.js",
@@ -1154,16 +1156,10 @@ describe("wrangler deploy with containers", () => {
11541156
// With the flag, it should skip Docker verification entirely and proceed
11551157
// to deploy the Worker (the deploy itself may fail for unrelated mock reasons,
11561158
// but the key assertion is that no Docker error is thrown).
1157-
let thrownError: Error | undefined;
1158-
try {
1159-
await runWrangler("deploy index.js --containers-rollout=none");
1160-
} catch (e) {
1161-
thrownError = e as Error;
1162-
}
11631159

1164-
expect(thrownError?.message ?? "").not.toContain(
1165-
"The Docker CLI could not be launched"
1166-
);
1160+
await expect(
1161+
runWrangler("deploy index.js --containers-rollout=none")
1162+
).resolves.not.toThrow();
11671163
});
11681164

11691165
describe("observability config resolution", () => {
@@ -2426,7 +2422,9 @@ describe("wrangler deploy with containers dry run", () => {
24262422
vi.unstubAllEnvs();
24272423
});
24282424

2429-
it("builds the image without pushing", async ({ expect }) => {
2425+
it("builds the image without pushing when given a dockerfile", async ({
2426+
expect,
2427+
}) => {
24302428
// Reduced mock chain for dry run (no delete, push)
24312429
vi.mocked(spawn)
24322430
.mockImplementationOnce(mockDockerInfo(expect))
@@ -2469,7 +2467,49 @@ describe("wrangler deploy with containers dry run", () => {
24692467
expect(cliStd.stdout).toMatchInlineSnapshot(`""`);
24702468
});
24712469

2472-
it("builds the image without pushing", async ({ expect }) => {
2470+
it("does not build when --containers-rollout=none", async ({ expect }) => {
2471+
// Reduced mock chain for dry run (no delete, push)
2472+
vi.mocked(spawn)
2473+
.mockImplementationOnce(mockDockerInfo(expect))
2474+
.mockImplementationOnce(
2475+
mockDockerBuild(
2476+
expect,
2477+
"my-container",
2478+
"worker",
2479+
"FROM scratch",
2480+
process.cwd()
2481+
)
2482+
);
2483+
vi.stubEnv("WRANGLER_DOCKER_BIN", "/usr/bin/docker");
2484+
fs.writeFileSync("./Dockerfile", "FROM scratch");
2485+
fs.writeFileSync(
2486+
"index.js",
2487+
`export class ExampleDurableObject {}; export default{};`
2488+
);
2489+
writeWranglerConfig({
2490+
...DEFAULT_DURABLE_OBJECTS,
2491+
containers: [DEFAULT_CONTAINER_FROM_DOCKERFILE],
2492+
});
2493+
2494+
await runWrangler("deploy --dry-run --containers-rollout=none index.js");
2495+
expect(std.out).toMatchInlineSnapshot(`
2496+
"
2497+
⛅️ wrangler x.x.x
2498+
──────────────────
2499+
Total Upload: xx KiB / gzip: xx KiB
2500+
Your Worker has access to the following bindings:
2501+
Binding Resource
2502+
env.EXAMPLE_DO_BINDING (ExampleDurableObject) Durable Object
2503+
2504+
The following containers are available:
2505+
- my-container (<cwd>/Dockerfile)
2506+
2507+
--dry-run: exiting now."
2508+
`);
2509+
expect(cliStd.stdout).toMatchInlineSnapshot(`""`);
2510+
});
2511+
2512+
it("does not push when given a registry link", async ({ expect }) => {
24732513
// No docker mocks at all
24742514

24752515
fs.writeFileSync(

packages/wrangler/src/deploy/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
961961
if (props.dryRun) {
962962
if (normalisedContainerConfig.length) {
963963
for (const container of normalisedContainerConfig) {
964-
if ("dockerfile" in container) {
964+
if ("dockerfile" in container && props.containersRollout !== "none") {
965965
await buildContainer(
966966
container,
967967
workerTag ?? "worker-tag",

0 commit comments

Comments
 (0)