@@ -10,7 +10,7 @@ import { msw } from "./helpers/msw";
1010import { runWrangler } from "./helpers/run-wrangler" ;
1111
1212type PreviewDeploymentPatchBody = {
13- env ?: Record < string , { type : string ; text ? : string } | null > ;
13+ env ?: Record < string , { type : string ; text : string } | null > ;
1414 annotations ?: Record < string , string | undefined > ;
1515} ;
1616
@@ -20,6 +20,8 @@ const BRANCH_ENV_VARS = [
2020 "GITHUB_REF_NAME" ,
2121 "CI_COMMIT_REF_NAME" ,
2222] as const ;
23+ const NO_ACTIVE_PREVIEW_URLS_MESSAGE =
24+ "Note: This Preview deployment has no active URLs. To get one, enable Preview Deployments on workers.dev or a custom domain. See https://developers.cloudflare.com/workers/previews/custom-domains/ for more information" ;
2325
2426async function withoutBranchEnvVars < T > ( callback : ( ) => Promise < T > ) : Promise < T > {
2527 const originalBranchEnv = Object . fromEntries (
@@ -43,7 +45,8 @@ async function withoutBranchEnvVars<T>(callback: () => Promise<T>): Promise<T> {
4345}
4446
4547function mockPatchLatestPreviewDeployment (
46- onRequest ?: ( info : { url : string ; body : PreviewDeploymentPatchBody } ) => void
48+ onRequest ?: ( info : { url : string ; body : PreviewDeploymentPatchBody } ) => void ,
49+ urls : string [ ] | undefined = [ "https://test-preview.example.workers.dev" ]
4750) {
4851 msw . use (
4952 http . patch (
@@ -59,7 +62,7 @@ function mockPatchLatestPreviewDeployment(
5962 id : "deployment-1" ,
6063 preview_id : "preview-1" ,
6164 preview_name : String ( params . previewId ) ,
62- urls : [ "https://test-preview.example.workers.dev" ] ,
65+ urls,
6366 created_on : "2025-01-01T00:00:00Z" ,
6467 } ,
6568 } ) ;
@@ -87,7 +90,7 @@ function mockPatchPreviewDeploymentError(code: number) {
8790}
8891
8992function mockGetLatestPreviewDeployment (
90- env : Record < string , { type : string ; text ? : string } > ,
93+ env : Record < string , { type : string ; text : string } > ,
9194 onRequest ?: ( info : { url : string } ) => void
9295) {
9396 msw . use (
@@ -188,6 +191,21 @@ describe("wrangler preview", () => {
188191 expect ( std . out ) . not . toContain ( "preview-secret" ) ;
189192 } ) ;
190193
194+ test ( "notes when the new Preview deployment has no active URLs" , async ( {
195+ expect,
196+ } ) => {
197+ mockStdIn . send ( "preview-secret" ) ;
198+ mockPatchLatestPreviewDeployment ( undefined , [ ] ) ;
199+
200+ await runWrangler (
201+ "preview secret put API_KEY --name test-preview --worker-name test-worker"
202+ ) ;
203+
204+ expect ( std . out ) . toContain ( "Created Preview deployment deployment-1" ) ;
205+ expect ( std . out ) . toContain ( NO_ACTIVE_PREVIEW_URLS_MESSAGE ) ;
206+ expect ( std . out ) . not . toContain ( "is now live at" ) ;
207+ } ) ;
208+
191209 test ( "defaults the Preview name to the current git branch" , async ( {
192210 expect,
193211 } ) => {
@@ -378,6 +396,20 @@ describe("wrangler preview", () => {
378396 ) ;
379397 } ) ;
380398
399+ test ( "notes when the new Preview deployment has no active URLs" , async ( {
400+ expect,
401+ } ) => {
402+ mockPatchLatestPreviewDeployment ( undefined , [ ] ) ;
403+
404+ await runWrangler (
405+ "preview secret delete REMOVE_ME --name test-preview --skip-confirmation --worker-name test-worker"
406+ ) ;
407+
408+ expect ( std . out ) . toContain ( "Created Preview deployment deployment-1" ) ;
409+ expect ( std . out ) . toContain ( NO_ACTIVE_PREVIEW_URLS_MESSAGE ) ;
410+ expect ( std . out ) . not . toContain ( "is now live at" ) ;
411+ } ) ;
412+
381413 test ( "respects env-specific worker name when deleting a secret" , async ( {
382414 expect,
383415 } ) => {
@@ -450,7 +482,7 @@ describe("wrangler preview", () => {
450482 test ( "reads the latest Preview deployment" , async ( { expect } ) => {
451483 let requestUrl : string | undefined ;
452484 mockGetLatestPreviewDeployment (
453- { API_KEY : { type : "secret_text" } } ,
485+ { API_KEY : { type : "secret_text" , text : "preview-secret" } } ,
454486 ( { url } ) => {
455487 requestUrl = url ;
456488 }
@@ -463,30 +495,24 @@ describe("wrangler preview", () => {
463495 ) ;
464496 } ) ;
465497
466- // Matrix over output format (json vs. pretty) and whether the API
467- // returns a text value for the secret. In every combination we only
468- // list secret bindings (never plain_text) and never print the value.
498+ // Matrix over output format (json vs. pretty). In every combination we
499+ // only list secret bindings (never plain_text) and never print the value.
469500 test . for ( [
470501 {
471502 name : "json, value provided" ,
472503 json : true ,
473504 text : "super-secret-value" ,
474505 } ,
475- { name : "json, no value" , json : true , text : undefined } ,
476506 {
477507 name : "pretty, value provided" ,
478508 json : false ,
479509 text : "super-secret-value" ,
480510 } ,
481- { name : "pretty, no value" , json : false , text : undefined } ,
482511 ] ) (
483512 "lists only secrets and never leaks their values ($name)" ,
484513 async ( { json, text } , { expect } ) => {
485514 mockGetLatestPreviewDeployment ( {
486- MY_SECRET :
487- text === undefined
488- ? { type : "secret_text" }
489- : { type : "secret_text" , text } ,
515+ MY_SECRET : { type : "secret_text" , text } ,
490516 PLAIN : { type : "plain_text" , text : "not-a-secret" } ,
491517 } ) ;
492518 await runWrangler (
@@ -609,6 +635,21 @@ describe("wrangler preview", () => {
609635 expect ( std . out ) . not . toContain ( "two" ) ;
610636 } ) ;
611637
638+ test ( "notes when the new Preview deployment has no active URLs" , async ( {
639+ expect,
640+ } ) => {
641+ writeFileSync ( "secrets.env" , "FIRST_KEY=one\nSECOND_KEY=two\n" ) ;
642+ mockPatchLatestPreviewDeployment ( undefined , [ ] ) ;
643+
644+ await runWrangler (
645+ "preview secret bulk secrets.env --name test-preview --worker-name test-worker"
646+ ) ;
647+
648+ expect ( std . out ) . toContain ( "Created Preview deployment deployment-1" ) ;
649+ expect ( std . out ) . toContain ( NO_ACTIVE_PREVIEW_URLS_MESSAGE ) ;
650+ expect ( std . out ) . not . toContain ( "is now live at" ) ;
651+ } ) ;
652+
612653 test ( "should respect env-specific worker name when bulk uploading secrets" , async ( {
613654 expect,
614655 } ) => {
0 commit comments