Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silly-toes-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

Add prompt to resource creation flow allowing for newly created resources to be remote.
23 changes: 14 additions & 9 deletions packages/wrangler/src/__tests__/__snapshots__/kv.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ To access your new KV Namespace in your Worker, add the following snippet to you
{
\\"kv_namespaces\\": [
{
\\"binding\\": \\"UnitTestNamespace\\",
\\"binding\\": \\"MY_NS\\",
\\"id\\": \\"some-namespace-id\\"
}
]
Expand All @@ -21,7 +21,7 @@ exports[`wrangler > kv namespace > create > wrangler.json > should create a name
\\"name\\": \\"worker\\",
\\"kv_namespaces\\": [
{
\\"binding\\": \\"UnitTestNamespace\\",
\\"binding\\": \\"MY_NS\\",
\\"id\\": \\"some-namespace-id\\"
}
]
Expand Down Expand Up @@ -52,8 +52,9 @@ exports[`wrangler > kv namespace > create > wrangler.json > should create a name
\\"name\\": \\"worker\\",
\\"kv_namespaces\\": [
{
\\"binding\\": \\"UnitTestNamespace\\",
\\"id\\": \\"some-namespace-id\\"
\\"binding\\": \\"HELLO\\",
\\"id\\": \\"some-namespace-id\\",
\\"remote\\": true
}
]
}
Expand All @@ -70,7 +71,8 @@ To access your new KV Namespace in your Worker, add the following snippet to you
\\"kv_namespaces\\": [
{
\\"binding\\": \\"UnitTestNamespace\\",
\\"id\\": \\"some-namespace-id\\"
\\"id\\": \\"some-namespace-id\\",
\\"remote\\": true
}
]
}"
Expand All @@ -82,8 +84,9 @@ exports[`wrangler > kv namespace > create > wrangler.json > should create a name
\\"name\\": \\"other-worker\\",
\\"kv_namespaces\\": [
{
\\"binding\\": \\"UnitTestNamespace\\",
\\"id\\": \\"some-namespace-id\\"
\\"binding\\": \\"HELLO\\",
\\"id\\": \\"some-namespace-id\\",
\\"remote\\": true
}
]
}"
Expand Down Expand Up @@ -111,7 +114,8 @@ exports[`wrangler > kv namespace > create > wrangler.json > should create a name
\\"kv_namespaces\\": [
{
\\"binding\\": \\"HELLO\\",
\\"id\\": \\"some-namespace-id\\"
\\"id\\": \\"some-namespace-id\\",
\\"remote\\": true
}
]
}"
Expand All @@ -138,7 +142,7 @@ exports[`wrangler > kv namespace > create > wrangler.toml > should create a name
✨ Success!
To access your new KV Namespace in your Worker, add the following snippet to your configuration file:
[[kv_namespaces]]
binding = \\"UnitTestNamespace\\"
binding = \\"MY_NS\\"
id = \\"some-namespace-id\\"
"
`;
Expand Down Expand Up @@ -177,6 +181,7 @@ To access your new KV Namespace in your Worker, add the following snippet to you
[[kv_namespaces]]
binding = \\"UnitTestNamespace\\"
id = \\"some-namespace-id\\"
remote = true
"
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To access your new R2 Bucket in your Worker, add the following snippet to your c
]
}
? Would you like Wrangler to add it on your behalf?
🤖 Using fallback value in non-interactive context: No"
🤖 Using fallback value in non-interactive context: no"
`;

exports[`r2 > bucket > create > wrangler.json > should create a bucket with the expected default storage class 1`] = `
Expand All @@ -29,7 +29,7 @@ To access your new R2 Bucket in your Worker, add the following snippet to your c
]
}
? Would you like Wrangler to add it on your behalf?
🤖 Using fallback value in non-interactive context: No"
🤖 Using fallback value in non-interactive context: no"
`;

exports[`r2 > bucket > create > wrangler.json > should create a bucket with the expected jurisdiction 1`] = `
Expand All @@ -45,7 +45,7 @@ To access your new R2 Bucket in your Worker, add the following snippet to your c
]
}
? Would you like Wrangler to add it on your behalf?
🤖 Using fallback value in non-interactive context: No"
🤖 Using fallback value in non-interactive context: no"
`;

exports[`r2 > bucket > create > wrangler.json > should create a bucket with the expected location hint 1`] = `
Expand All @@ -61,7 +61,7 @@ To access your new R2 Bucket in your Worker, add the following snippet to your c
]
}
? Would you like Wrangler to add it on your behalf?
🤖 Using fallback value in non-interactive context: No"
🤖 Using fallback value in non-interactive context: no"
`;

exports[`r2 > bucket > create > wrangler.toml > should create a bucket & check request inputs 1`] = `
Expand Down
8 changes: 3 additions & 5 deletions packages/wrangler/src/__tests__/d1/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("create", () => {
});
})
);
await runWrangler("d1 create test --location oc");
await runWrangler("d1 create test --location oc --binding MY_TEST_DB");
expect(std.out).toMatchInlineSnapshot(`
"✅ Successfully created DB 'test' in region OC
Created your new D1 database.
Expand All @@ -71,14 +71,12 @@ describe("create", () => {
{
\\"d1_databases\\": [
{
\\"binding\\": \\"test\\",
\\"binding\\": \\"MY_TEST_DB\\",
\\"database_name\\": \\"test\\",
\\"database_id\\": \\"51e7c314-456e-4167-b6c3-869ad188fc23\\"
}
]
}
? Would you like Wrangler to add it on your behalf?
🤖 Using fallback value in non-interactive context: No"
}"
`);
});
});
60 changes: 38 additions & 22 deletions packages/wrangler/src/__tests__/kv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { BATCH_MAX_ERRORS_WARNINGS } from "../kv/helpers";
import { endEventLoop } from "./helpers/end-event-loop";
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
import { mockConsoleMethods } from "./helpers/mock-console";
import {
clearDialogs,
mockConfirm,
mockPrompt,
mockSelect,
} from "./helpers/mock-dialogs";
import { clearDialogs, mockConfirm, mockPrompt } from "./helpers/mock-dialogs";
import { useMockIsTTY } from "./helpers/mock-istty";
import { mockProcess } from "./helpers/mock-process";
import { msw } from "./helpers/msw";
Expand Down Expand Up @@ -161,7 +156,10 @@ describe("wrangler", () => {
-v, --version Show version number [boolean]

OPTIONS
--preview Interact with a preview namespace [boolean]"
--preview Interact with a preview namespace [boolean]
--use-remote Use a remote binding when adding the newly created resource to your config [boolean]
--update-config Automatically update your config file with the newly added resource [boolean]
--binding The binding name of this resource in your Worker [string]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Not enough non-option arguments: got 0, need at least 1
Expand Down Expand Up @@ -194,7 +192,10 @@ describe("wrangler", () => {
-v, --version Show version number [boolean]

OPTIONS
--preview Interact with a preview namespace [boolean]"
--preview Interact with a preview namespace [boolean]
--use-remote Use a remote binding when adding the newly created resource to your config [boolean]
--update-config Automatically update your config file with the newly added resource [boolean]
--binding The binding name of this resource in your Worker [string]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Unknown arguments: def, ghi
Expand All @@ -207,13 +208,10 @@ describe("wrangler", () => {
it("should create a namespace", async () => {
writeWranglerConfig({ name: "worker" }, configPath);
mockCreateRequest("UnitTestNamespace");
if (configPath === "wrangler.json") {
mockSelect({
text: "Would you like Wrangler to add it on your behalf?",
result: "yes",
});
}
await runWrangler("kv namespace create UnitTestNamespace");

await runWrangler(
"kv namespace create UnitTestNamespace --binding MY_NS"
);
expect(std.out).toMatchSnapshot();
expect(await readFile(configPath, "utf8")).toMatchSnapshot();
});
Expand All @@ -222,14 +220,18 @@ describe("wrangler", () => {
writeWranglerConfig({ name: "worker" }, configPath);
mockCreateRequest("UnitTestNamespace");
if (configPath === "wrangler.json") {
mockSelect({
mockConfirm({
text: "Would you like Wrangler to add it on your behalf?",
result: "yes-but",
result: true,
});
mockPrompt({
text: "What binding name would you like to use?",
result: "HELLO",
});
mockConfirm({
text: "For local dev, do you want to connect to the remote resource instead of a local resource?",
result: true,
});
}
await runWrangler("kv namespace create UnitTestNamespace");
expect(std.out).toMatchSnapshot();
Expand All @@ -249,12 +251,18 @@ describe("wrangler", () => {

mockCreateRequest("UnitTestNamespace");
if (configPath === "wrangler.json") {
mockSelect({
mockConfirm({
text: "Would you like Wrangler to add it on your behalf?",
result: "yes",
result: true,
});
mockPrompt({
text: "What binding name would you like to use?",
result: "HELLO",
});
}
await runWrangler("kv namespace create UnitTestNamespace");
await runWrangler(
"kv namespace create UnitTestNamespace --use-remote"
);
expect(std.out).toMatchSnapshot();
expect(await readFile(configPath, "utf8")).toMatchSnapshot();
});
Expand All @@ -274,9 +282,17 @@ describe("wrangler", () => {

mockCreateRequest("customEnv-UnitTestNamespace");
if (configPath === "wrangler.json") {
mockSelect({
mockConfirm({
text: "Would you like Wrangler to add it on your behalf?",
result: "yes",
result: true,
});
mockPrompt({
text: "What binding name would you like to use?",
result: "HELLO",
});
mockConfirm({
text: "For local dev, do you want to connect to the remote resource instead of a local resource?",
result: true,
});
}
await runWrangler(
Expand Down
10 changes: 8 additions & 2 deletions packages/wrangler/src/__tests__/r2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ describe("r2", () => {
OPTIONS
--location The optional location hint that determines geographic placement of the R2 bucket [string] [choices: \\"weur\\", \\"eeur\\", \\"apac\\", \\"wnam\\", \\"enam\\", \\"oc\\"]
-s, --storage-class The default storage class for objects uploaded to this bucket [string]
-J, --jurisdiction The jurisdiction where the new bucket will be created [string]"
-J, --jurisdiction The jurisdiction where the new bucket will be created [string]
--use-remote Use a remote binding when adding the newly created resource to your config [boolean]
--update-config Automatically update your config file with the newly added resource [boolean]
--binding The binding name of this resource in your Worker [string]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Not enough non-option arguments: got 0, need at least 1
Expand Down Expand Up @@ -366,7 +369,10 @@ describe("r2", () => {
OPTIONS
--location The optional location hint that determines geographic placement of the R2 bucket [string] [choices: \\"weur\\", \\"eeur\\", \\"apac\\", \\"wnam\\", \\"enam\\", \\"oc\\"]
-s, --storage-class The default storage class for objects uploaded to this bucket [string]
-J, --jurisdiction The jurisdiction where the new bucket will be created [string]"
-J, --jurisdiction The jurisdiction where the new bucket will be created [string]
--use-remote Use a remote binding when adding the newly created resource to your config [boolean]
--update-config Automatically update your config file with the newly added resource [boolean]
--binding The binding name of this resource in your Worker [string]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Unknown arguments: def, ghi
Expand Down
Loading
Loading