You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add warning about env not specified to potentially risky wrangler commands (#9344)
* add warning about env not specified to potentially risky wrangler commands
* Apply suggestions from code review
Co-authored-by: Pete Bacon Darwin <[email protected]>
* remove skip committed by mistake
* remove extra debugging logs
* use configPath instead
* remove unused import
* remove unnecessary displayName meta property
* [wrangler] allow passing an empty string to the `-e|--env` flag to target the top-level environment
* Update packages/wrangler/src/__tests__/deploy.test.ts
Co-authored-by: Pete Bacon Darwin <[email protected]>
* revert silly change
* fix incorrect code change
---------
Co-authored-by: Pete Bacon Darwin <[email protected]>
Copy file name to clipboardExpand all lines: packages/wrangler/src/__tests__/deploy.test.ts
+59Lines changed: 59 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -13006,6 +13006,65 @@ export default{
13006
13006
awaitrunWrangler("deploy ./index.js");
13007
13007
});
13008
13008
});
13009
+
13010
+
describe("multi-env warning",()=>{
13011
+
it("should warn if the wrangler config contains environments but none was specified in the command",async()=>{
13012
+
writeWorkerSource();
13013
+
writeWranglerConfig({
13014
+
main: "./index.js",
13015
+
env: {
13016
+
test: {},
13017
+
},
13018
+
});
13019
+
mockSubDomainRequest();
13020
+
mockUploadWorkerRequest();
13021
+
13022
+
awaitrunWrangler("deploy");
13023
+
13024
+
expect(std.warn).toMatchInlineSnapshot(`
13025
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mMultiple environments are defined in the Wrangler configuration file, but no target environment was specified for the deploy command.[0m
13026
+
13027
+
To avoid unintentional changes to the wrong environment, it is recommended to explicitly specify
13028
+
the target environment using the \`-e|--env\` flag.
13029
+
If your intention is to use the top-level environment of your configuration simply pass an empty
13030
+
string to the flag to target such environment. For example \`--env=\\"\\"\`.
13031
+
13032
+
"
13033
+
`);
13034
+
});
13035
+
13036
+
it("should not warn if the wrangler config contains environments and one was specified in the command",async()=>{
13037
+
writeWorkerSource();
13038
+
writeWranglerConfig({
13039
+
main: "./index.js",
13040
+
env: {
13041
+
test: {},
13042
+
},
13043
+
});
13044
+
mockSubDomainRequest();
13045
+
mockUploadWorkerRequest({
13046
+
env: "test",
13047
+
legacyEnv: true,
13048
+
});
13049
+
13050
+
awaitrunWrangler("deploy -e test");
13051
+
13052
+
expect(std.warn).toMatchInlineSnapshot(`""`);
13053
+
});
13054
+
13055
+
it("should not warn if the wrangler config doesn't contain environments and none was specified in the command",async()=>{
13056
+
writeWorkerSource();
13057
+
writeWranglerConfig({
13058
+
main: "./index.js",
13059
+
});
13060
+
mockSubDomainRequest();
13061
+
mockUploadWorkerRequest();
13062
+
13063
+
awaitrunWrangler("deploy");
13064
+
13065
+
expect(std.warn).toMatchInlineSnapshot(`""`);
13066
+
});
13067
+
});
13009
13068
});
13010
13069
13011
13070
/** Write mock assets to the file system so they can be uploaded. */
awaitrunWrangler("secret put the-key --name script-name");
473
+
expect(std.warn).toMatchInlineSnapshot(`
474
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mMultiple environments are defined in the Wrangler configuration file, but no target environment was specified for the secret put command.[0m
475
+
476
+
To avoid unintentional changes to the wrong environment, it is recommended to explicitly specify
477
+
the target environment using the \`-e|--env\` flag.
478
+
If your intention is to use the top-level environment of your configuration simply pass an empty
479
+
string to the flag to target such environment. For example \`--env=\\"\\"\`.
480
+
481
+
"
482
+
`);
483
+
});
484
+
485
+
it("should not warn if the wrangler config contains environments and one was specified in the command",async()=>{
`[Error: Required Worker name missing. Please specify the Worker name in your Wrangler configuration file, or pass it as an argument with \`--name <worker-name>\`]`
641
685
);
642
686
});
687
+
688
+
describe("multi-env warning",()=>{
689
+
it("should warn if the wrangler config contains environments but none was specified in the command",async()=>{
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mMultiple environments are defined in the Wrangler configuration file, but no target environment was specified for the secret delete command.[0m
703
+
704
+
To avoid unintentional changes to the wrong environment, it is recommended to explicitly specify
705
+
the target environment using the \`-e|--env\` flag.
706
+
If your intention is to use the top-level environment of your configuration simply pass an empty
707
+
string to the flag to target such environment. For example \`--env=\\"\\"\`.
708
+
709
+
"
710
+
`);
711
+
});
712
+
713
+
it("should not warn if the wrangler config contains environments and one was specified in the command",async()=>{
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mMultiple environments are defined in the Wrangler configuration file, but no target environment was specified for the secret bulk command.[0m
1360
+
1361
+
To avoid unintentional changes to the wrong environment, it is recommended to explicitly specify
1362
+
the target environment using the \`-e|--env\` flag.
1363
+
If your intention is to use the top-level environment of your configuration simply pass an empty
1364
+
string to the flag to target such environment. For example \`--env=\\"\\"\`.
1365
+
1366
+
"
1367
+
`);
1368
+
});
1369
+
1370
+
it("should not warn if the wrangler config contains environments and one was specified in the command",async()=>{
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mMultiple environments are defined in the Wrangler configuration file, but no target environment was specified for the versions secret bulk command.[0m
300
+
301
+
To avoid unintentional changes to the wrong environment, it is recommended to explicitly specify
302
+
the target environment using the \`-e|--env\` flag.
303
+
If your intention is to use the top-level environment of your configuration simply pass an empty
304
+
string to the flag to target such environment. For example \`--env=\\"\\"\`.
305
+
306
+
"
307
+
`);
308
+
});
309
+
310
+
it("should not warn if the wrangler config contains environments and one was specified in the command",async()=>{
0 commit comments