11import  assert  from  "node:assert" ; 
22import  dedent  from  "ts-dedent" ; 
33import  {  fetch  }  from  "undici" ; 
4- import  {  afterAll ,  beforeAll ,  describe ,  expect ,  it  }  from  "vitest" ; 
4+ import  {  afterAll ,  beforeEach ,  describe ,  expect ,  it  }  from  "vitest" ; 
55import  {  CLOUDFLARE_ACCOUNT_ID  }  from  "./helpers/account-id" ; 
66import  {  WranglerE2ETestHelper  }  from  "./helpers/e2e-wrangler-test" ; 
77import  {  fetchText  }  from  "./helpers/fetch-text" ; 
@@ -38,23 +38,27 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
3838			expect ( text ) . toMatchInlineSnapshot ( `"Hello World!"` ) ; 
3939		} ) ; 
4040
41- 		beforeAll ( async  ( )  =>  { 
41+ 		beforeEach ( async  ( )  =>  { 
4242			await  helper . seed ( { 
4343				"wrangler.toml" : dedent ` 
4444						name = "${ workerName }  " 
4545						main = "src/index.ts" 
4646						compatibility_date = "2023-01-01" 
4747						workers_dev = true 
4848
49- 						 [[kv_namespaces]] 
50- 						 binding = "KV" 
49+ 					[[kv_namespaces]] 
50+ 					binding = "KV" 
5151
52- 						 [[r2_buckets]] 
53- 						 binding = "R2" 
52+ 					[[r2_buckets]] 
53+ 					binding = "R2" 
5454
55- 						[[d1_databases]] 
56- 						binding = "D1" 
57- 						` , 
55+ 					[[r2_buckets]] 
56+ 					binding = "R2_WITH_NAME" 
57+ 					bucket_name = "does-not-exist" 
58+ 
59+ 					[[d1_databases]] 
60+ 					binding = "D1" 
61+ 				` , 
5862				"src/index.ts" : dedent ` 
5963						export default { 
6064							fetch(request) { 
@@ -76,32 +80,33 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
7680			await  worker . exitCode ; 
7781			const  output  =  await  worker . output ; 
7882			expect ( normalize ( output ) ) . toMatchInlineSnapshot ( ` 
79- 			"Total Upload: xx KiB / gzip: xx KiB 
80- 			The following bindings need to be provisioned: 
81- 			Binding        Resource 
82- 			env.KV         KV Namespace 
83- 			env.D1         D1 Database 
84- 			env.R2         R2 Bucket 
85- 			Provisioning KV (KV Namespace)... 
86- 			🌀 Creating new KV Namespace "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-kv"... 
87- 			✨ KV provisioned 🎉 
88- 			Provisioning D1 (D1 Database)... 
89- 			🌀 Creating new D1 Database "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-d1"... 
90- 			✨ D1 provisioned 🎉 
91- 			Provisioning R2 (R2 Bucket)... 
92- 			🌀 Creating new R2 Bucket "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2"... 
93- 			✨ R2 provisioned 🎉 
94- 			🎉 All resources provisioned, continuing with deployment... 
95- 			Your Worker has access to the following bindings: 
96- 			Binding                                                              Resource 
97- 			env.KV (00000000000000000000000000000000)                            KV Namespace 
98- 			env.D1 (00000000-0000-0000-0000-000000000000)                        D1 Database 
99- 			env.R2 (tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2)      R2 Bucket 
100- 			Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS) 
101- 			Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS) 
102- 			  https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev 
103- 			Current Version ID: 00000000-0000-0000-0000-000000000000" 
104- 		` ) ; 
83+ 				"Total Upload: xx KiB / gzip: xx KiB 
84+ 				The following bindings need to be provisioned: 
85+ 				Binding        Resource 
86+ 				env.KV         KV Namespace 
87+ 				env.D1         D1 Database 
88+ 				env.R2         R2 Bucket 
89+ 				Provisioning KV (KV Namespace)... 
90+ 				🌀 Creating new KV Namespace "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-kv"... 
91+ 				✨ KV provisioned 🎉 
92+ 				Provisioning D1 (D1 Database)... 
93+ 				🌀 Creating new D1 Database "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-d1"... 
94+ 				✨ D1 provisioned 🎉 
95+ 				Provisioning R2 (R2 Bucket)... 
96+ 				🌀 Creating new R2 Bucket "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2"... 
97+ 				✨ R2 provisioned 🎉 
98+ 				🎉 All resources provisioned, continuing with deployment... 
99+ 				Your Worker has access to the following bindings: 
100+ 				Binding                                                                        Resource 
101+ 				env.KV (00000000000000000000000000000000)                                      KV Namespace 
102+ 				env.D1 (00000000-0000-0000-0000-000000000000)                                  D1 Database 
103+ 				env.R2 (tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2)                R2 Bucket 
104+ 				env.R2_WITH_NAME (does-not-exist)                                              R2 Bucket 
105+ 				Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS) 
106+ 				Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS) 
107+ 				  https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev 
108+ 				Current Version ID: 00000000-0000-0000-0000-000000000000" 
109+ 			` ) ; 
105110			const  urlMatch  =  output . match ( 
106111				/ (?< url > h t t p s : \/ \/ t m p - e 2 e - .+ ?\. .+ ?\. w o r k e r s \. d e v ) / 
107112			) ; 
@@ -130,25 +135,55 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
130135			await  worker . exitCode ; 
131136			const  output  =  await  worker . output ; 
132137			expect ( normalize ( output ) ) . toMatchInlineSnapshot ( ` 
133- 			"Total Upload: xx KiB / gzip: xx KiB 
134- 			Your Worker has access to the following bindings: 
135- 			Binding                 Resource 
136- 			env.KV (inherited)      KV Namespace 
137- 			env.D1 (inherited)      D1 Database 
138- 			env.R2 (inherited)      R2 Bucket 
139- 			Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS) 
140- 			Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS) 
141- 			  https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev 
142- 			Current Version ID: 00000000-0000-0000-0000-000000000000" 
143- 		` ) ; 
138+ 				"Total Upload: xx KiB / gzip: xx KiB 
139+ 				Your Worker has access to the following bindings: 
140+ 				Binding                                Resource 
141+ 				env.KV (inherited)                     KV Namespace 
142+ 				env.D1 (inherited)                     D1 Database 
143+ 				env.R2 (inherited)                     R2 Bucket 
144+ 				env.R2_WITH_NAME (does-not-exist)      R2 Bucket 
145+ 				Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS) 
146+ 				Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS) 
147+ 				  https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev 
148+ 				Current Version ID: 00000000-0000-0000-0000-000000000000" 
149+ 			` ) ; 
144150
145151			const  response  =  await  retry ( 
146152				( resp )  =>  ! resp . ok , 
147153				async  ( )  =>  await  fetch ( deployedUrl ) 
148154			) ; 
149155			await  expect ( response . text ( ) ) . resolves . toEqual ( "Hello World!" ) ; 
150156		} ) ; 
157+ 		it ( "can inspect current bindings" ,  async  ( )  =>  { 
158+ 			const  versionsRaw  =  await  helper . run ( 
159+ 				`wrangler versions list --json --x-provision` 
160+ 			) ; 
151161
162+ 			const  versions  =  JSON . parse ( versionsRaw . stdout )  as  unknown [ ] ; 
163+ 
164+ 			const  latest  =  versions . at ( - 1 )  as  {  id : string  } ; 
165+ 
166+ 			const  versionView  =  await  helper . run ( 
167+ 				`wrangler versions view ${ latest . id }   --x-provision` 
168+ 			) ; 
169+ 
170+ 			expect ( normalizeOutput ( versionView . output ) ) . toMatchInlineSnapshot ( ` 
171+ 				"Version ID:  00000000-0000-0000-0000-000000000000 
172+ 				Created:     TIMESTAMP 
173+ 				Author: 
174+ 				Source:      Unknown (version_upload) 
175+ 				Tag:         - 
176+ 				Message:     - 
177+ 				Handlers:            fetch 
178+ 				Compatibility Date:  2023-01-01 
179+ 				Your Worker has access to the following bindings: 
180+ 				Binding                                                                        Resource 
181+ 				env.KV (00000000000000000000000000000000)                                      KV Namespace 
182+ 				env.D1 (00000000-0000-0000-0000-000000000000)                                  D1 Database 
183+ 				env.R2 (tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2)                R2 Bucket 
184+ 				env.R2_WITH_NAME (does-not-exist)                                              R2 Bucket" 
185+ 			` ) ; 
186+ 		} ) ; 
152187		it ( "can inherit and provision resources on version upload" ,  async  ( )  =>  { 
153188			await  helper . seed ( { 
154189				"wrangler.toml" : dedent ` 
0 commit comments