Skip to content

Commit

Permalink
Fixed versions upload printing duplicate bindings (#6530)
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed Aug 20, 2024
1 parent c3441c5 commit d0ecc6a
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-rocks-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: fixed `wrangler versions upload` printing bindings twice
103 changes: 103 additions & 0 deletions packages/wrangler/src/__tests__/versions/versions.upload.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import * as fs from "node:fs";
import { http, HttpResponse } from "msw";
import { mockAccountId, mockApiToken } from "../helpers/mock-account-id";
import { mockConsoleMethods } from "../helpers/mock-console";
import { useMockIsTTY } from "../helpers/mock-istty";
import { mockSubDomainRequest } from "../helpers/mock-workers-subdomain";
import { msw } from "../helpers/msw";
import { runWrangler } from "../helpers/run-wrangler";
import { writeWorkerSource } from "../helpers/write-worker-source";
import { writeWranglerToml } from "../helpers/write-wrangler-toml";

describe("versions upload", () => {
mockAccountId();
mockApiToken();
const { setIsTTY } = useMockIsTTY();
const std = mockConsoleMethods();

test("should print bindings & startup time on versions upload", async () => {
msw.use(
http.get(
`*/accounts/:accountId/workers/services/:scriptName`,
({ params }) => {
expect(params.scriptName).toEqual("test-worker");

return HttpResponse.json(
{
success: true,
errors: [],
messages: [],
result: {
default_environment: {
script: {
last_deployed_from: "wrangler",
},
},
},
},
{ status: 200 }
);
},
{ once: true }
),
http.post(
`*/accounts/:accountId/workers/scripts/:scriptName/versions`,
({ params }) => {
expect(params.scriptName).toEqual("test-worker");

return HttpResponse.json(
{
success: true,
errors: [],
messages: [],
result: {
id: "51e4886e-2db7-4900-8d38-fbfecfeab993",
startup_time_ms: 500,
},
},
{ status: 200 }
);
},
{ once: true }
)
);
mockSubDomainRequest();

// Setup
fs.mkdirSync("./versions-upload-test-worker", { recursive: true });
writeWranglerToml({
name: "test-worker",
main: "./index.js",
vars: {
TEST: "test-string",
JSON: {
abc: "def",
bool: true,
},
},
kv_namespaces: [{ binding: "KV", id: "xxxx-xxxx-xxxx-xxxx" }],
});
writeWorkerSource();
setIsTTY(false);

const result = runWrangler("versions upload --x-versions");

await expect(result).resolves.toBeUndefined();

expect(std.out).toMatchInlineSnapshot(`
"Total Upload: xx KiB / gzip: xx KiB
Worker Startup Time: 500 ms
Your worker has access to the following bindings:
- KV Namespaces:
- KV: xxxx-xxxx-xxxx-xxxx
- Vars:
- TEST: \\"test-string\\"
- JSON: {
\\"abc\\": \\"def\\",
\\"bool\\": true
}
Worker Version ID: 51e4886e-2db7-4900-8d38-fbfecfeab993
Uploaded test-worker (TIMINGS)"
`);
});
});
2 changes: 0 additions & 2 deletions packages/wrangler/src/versions/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,6 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
}
}

printBindings({ ...withoutStaticAssets, vars: maskedVars });

if (props.dryRun) {
printBindings({ ...withoutStaticAssets, vars: maskedVars });
} else {
Expand Down

0 comments on commit d0ecc6a

Please sign in to comment.