From bac79fb7379941cd70d3a99d0d2cdb23e2409e50 Mon Sep 17 00:00:00 2001 From: dbenCF <125887610+dbenCF@users.noreply.github.com> Date: Wed, 5 Jun 2024 12:17:59 +0100 Subject: [PATCH] Update create KV namespace message and test (#5934) * Update create KV namespace message and test * Fix failing tests in `./tools` (#5935) Co-authored-by: Carmen Popoviciu * Update create KV namespace message and test * Run prettify * Run prettify again after update * Update kv tests to match new message * Fix create KV namespace output * Update snapshot for KV tests --------- Co-authored-by: Carmen Popoviciu Co-authored-by: Carmen Popoviciu --- .changeset/green-turtles-care.md | 5 +++ packages/wrangler/src/__tests__/kv.test.ts | 48 +++++++++++++--------- packages/wrangler/src/kv/index.ts | 9 ++-- 3 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 .changeset/green-turtles-care.md diff --git a/.changeset/green-turtles-care.md b/.changeset/green-turtles-care.md new file mode 100644 index 000000000000..00fe95decc71 --- /dev/null +++ b/.changeset/green-turtles-care.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +fix: Update create KV namespace binding details message for easier implementation diff --git a/packages/wrangler/src/__tests__/kv.test.ts b/packages/wrangler/src/__tests__/kv.test.ts index dda7d005ddf6..92e7cf871423 100644 --- a/packages/wrangler/src/__tests__/kv.test.ts +++ b/packages/wrangler/src/__tests__/kv.test.ts @@ -118,22 +118,26 @@ describe("wrangler", () => { mockCreateRequest("worker-UnitTestNamespace"); await runWrangler("kv:namespace create UnitTestNamespace"); expect(std.out).toMatchInlineSnapshot(` - "🌀 Creating namespace with title \\"worker-UnitTestNamespace\\" - ✨ Success! - Add the following to your configuration file in your kv_namespaces array: - { binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }" - `); + "🌀 Creating namespace with title \\"worker-UnitTestNamespace\\" + ✨ Success! + Add the following to your configuration file in your kv_namespaces array: + [[kv_namespaces]] + binding = \\"UnitTestNamespace\\" + id = \\"some-namespace-id\\"" + `); }); it("should create a preview namespace if configured to do so", async () => { mockCreateRequest("worker-UnitTestNamespace_preview"); await runWrangler("kv:namespace create UnitTestNamespace --preview"); expect(std.out).toMatchInlineSnapshot(` - "🌀 Creating namespace with title \\"worker-UnitTestNamespace_preview\\" - ✨ Success! - Add the following to your configuration file in your kv_namespaces array: - { binding = \\"UnitTestNamespace\\", preview_id = \\"some-namespace-id\\" }" - `); + "🌀 Creating namespace with title \\"worker-UnitTestNamespace_preview\\" + ✨ Success! + Add the following to your configuration file in your kv_namespaces array: + [[kv_namespaces]] + binding = \\"UnitTestNamespace\\" + preview_id = \\"some-namespace-id\\"" + `); }); it("should create a namespace using configured worker name", async () => { @@ -141,11 +145,13 @@ describe("wrangler", () => { mockCreateRequest("other-worker-UnitTestNamespace"); await runWrangler("kv:namespace create UnitTestNamespace"); expect(std.out).toMatchInlineSnapshot(` - "🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\" - ✨ Success! - Add the following to your configuration file in your kv_namespaces array: - { binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }" - `); + "🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\" + ✨ Success! + Add the following to your configuration file in your kv_namespaces array: + [[kv_namespaces]] + binding = \\"UnitTestNamespace\\" + id = \\"some-namespace-id\\"" + `); }); it("should create a namespace in an environment if configured to do so", async () => { @@ -154,11 +160,13 @@ describe("wrangler", () => { "kv:namespace create UnitTestNamespace --env customEnv" ); expect(std.out).toMatchInlineSnapshot(` - "🌀 Creating namespace with title \\"worker-customEnv-UnitTestNamespace\\" - ✨ Success! - Add the following to your configuration file in your kv_namespaces array under [env.customEnv]: - { binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }" - `); + "🌀 Creating namespace with title \\"worker-customEnv-UnitTestNamespace\\" + ✨ Success! + Add the following to your configuration file in your kv_namespaces array under [env.customEnv]: + [[kv_namespaces]] + binding = \\"UnitTestNamespace\\" + id = \\"some-namespace-id\\"" + `); }); }); diff --git a/packages/wrangler/src/kv/index.ts b/packages/wrangler/src/kv/index.ts index bb2388714a00..aa2df628a320 100644 --- a/packages/wrangler/src/kv/index.ts +++ b/packages/wrangler/src/kv/index.ts @@ -81,12 +81,9 @@ export function kvNamespace(kvYargs: CommonYargsArgv) { logger.log( `Add the following to your configuration file in your kv_namespaces array${envString}:` ); - logger.log( - `{ binding = "${getValidBindingName( - args.namespace, - "KV" - )}", ${previewString}id = "${namespaceId}" }` - ); + logger.log(`[[kv_namespaces]]`); + logger.log(`binding = "${getValidBindingName(args.namespace, "KV")}"`); + logger.log(`${previewString}id = "${namespaceId}"`); // TODO: automatically write this block to the wrangler.toml config file?? }