11import assert from "node:assert" ;
2+ import { readFile } from "node:fs/promises" ;
23import dedent from "ts-dedent" ;
34import { fetch } from "undici" ;
4- import { afterAll , beforeAll , describe , expect , it , vi } from "vitest" ;
5+ import {
6+ afterAll ,
7+ beforeAll ,
8+ beforeEach ,
9+ describe ,
10+ expect ,
11+ it ,
12+ vi ,
13+ } from "vitest" ;
514import { CLOUDFLARE_ACCOUNT_ID } from "./helpers/account-id" ;
615import { WranglerE2ETestHelper } from "./helpers/e2e-wrangler-test" ;
716import { fetchText } from "./helpers/fetch-text" ;
@@ -38,22 +47,26 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
3847 expect ( text ) . toMatchInlineSnapshot ( `"Hello World!"` ) ;
3948 } ) ;
4049
41- beforeAll ( async ( ) => {
50+ beforeEach ( async ( ) => {
4251 await helper . seed ( {
4352 "wrangler.toml" : dedent `
44- name = "${ workerName } "
45- main = "src/index.ts"
46- compatibility_date = "2023-01-01"
53+ name = "${ workerName } "
54+ main = "src/index.ts"
55+ compatibility_date = "2023-01-01"
4756
48- [[kv_namespaces]]
49- binding = "KV"
57+ [[kv_namespaces]]
58+ binding = "KV"
5059
51- [[r2_buckets]]
52- binding = "R2"
60+ [[r2_buckets]]
61+ binding = "R2"
5362
54- [[d1_databases]]
55- binding = "D1"
56- ` ,
63+ [[r2_buckets]]
64+ binding = "R2_WITH_NAME"
65+ bucket_name = "does-not-exist"
66+
67+ [[d1_databases]]
68+ binding = "D1"
69+ ` ,
5770 "src/index.ts" : dedent `
5871 export default {
5972 fetch(request) {
@@ -75,32 +88,33 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
7588 await worker . exitCode ;
7689 const output = await worker . output ;
7790 expect ( normalize ( output ) ) . toMatchInlineSnapshot ( `
78- "Total Upload: xx KiB / gzip: xx KiB
79- The following bindings need to be provisioned:
80- Binding Resource
81- env.KV KV Namespace
82- env.D1 D1 Database
83- env.R2 R2 Bucket
84- Provisioning KV (KV Namespace)...
85- 🌀 Creating new KV Namespace "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-kv"...
86- ✨ KV provisioned 🎉
87- Provisioning D1 (D1 Database)...
88- 🌀 Creating new D1 Database "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-d1"...
89- ✨ D1 provisioned 🎉
90- Provisioning R2 (R2 Bucket)...
91- 🌀 Creating new R2 Bucket "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2"...
92- ✨ R2 provisioned 🎉
93- 🎉 All resources provisioned, continuing with deployment...
94- Your Worker has access to the following bindings:
95- Binding Resource
96- env.KV (00000000000000000000000000000000) KV Namespace
97- env.D1 (00000000-0000-0000-0000-000000000000) D1 Database
98- env.R2 (tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2) R2 Bucket
99- Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
100- Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS)
101- https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev
102- Current Version ID: 00000000-0000-0000-0000-000000000000"
103- ` ) ;
91+ "Total Upload: xx KiB / gzip: xx KiB
92+ The following bindings need to be provisioned:
93+ Binding Resource
94+ env.KV KV Namespace
95+ env.D1 D1 Database
96+ env.R2 R2 Bucket
97+ Provisioning KV (KV Namespace)...
98+ 🌀 Creating new KV Namespace "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-kv"...
99+ ✨ KV provisioned 🎉
100+ Provisioning D1 (D1 Database)...
101+ 🌀 Creating new D1 Database "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-d1"...
102+ ✨ D1 provisioned 🎉
103+ Provisioning R2 (R2 Bucket)...
104+ 🌀 Creating new R2 Bucket "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2"...
105+ ✨ R2 provisioned 🎉
106+ 🎉 All resources provisioned, continuing with deployment...
107+ Your Worker has access to the following bindings:
108+ Binding Resource
109+ env.KV (00000000000000000000000000000000) KV Namespace
110+ env.D1 (00000000-0000-0000-0000-000000000000) D1 Database
111+ env.R2 (tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2) R2 Bucket
112+ env.R2_WITH_NAME (does-not-exist) R2 Bucket
113+ Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
114+ Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS)
115+ https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev
116+ Current Version ID: 00000000-0000-0000-0000-000000000000"
117+ ` ) ;
104118 const urlMatch = output . match (
105119 / (?< url > h t t p s : \/ \/ t m p - e 2 e - .+ ?\. .+ ?\. w o r k e r s \. d e v ) /
106120 ) ;
@@ -129,25 +143,78 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
129143 await worker . exitCode ;
130144 const output = await worker . output ;
131145 expect ( normalize ( output ) ) . toMatchInlineSnapshot ( `
132- "Total Upload: xx KiB / gzip: xx KiB
133- Your Worker has access to the following bindings:
134- Binding Resource
135- env.KV (inherited) KV Namespace
136- env.D1 (inherited) D1 Database
137- env.R2 (inherited) R2 Bucket
138- Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
139- Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS)
140- https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev
141- Current Version ID: 00000000-0000-0000-0000-000000000000"
142- ` ) ;
146+ "Total Upload: xx KiB / gzip: xx KiB
147+ Your Worker has access to the following bindings:
148+ Binding Resource
149+ env.KV (inherited) KV Namespace
150+ env.D1 (inherited) D1 Database
151+ env.R2 (inherited) R2 Bucket
152+ env.R2_WITH_NAME (does-not-exist) R2 Bucket
153+ Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
154+ Deployed tmp-e2e-worker-00000000-0000-0000-0000-000000000000 triggers (TIMINGS)
155+ https://tmp-e2e-worker-00000000-0000-0000-0000-000000000000.SUBDOMAIN.workers.dev
156+ Current Version ID: 00000000-0000-0000-0000-000000000000"
157+ ` ) ;
143158
144159 const response = await retry (
145160 ( resp ) => ! resp . ok ,
146161 async ( ) => await fetch ( deployedUrl )
147162 ) ;
148163 await expect ( response . text ( ) ) . resolves . toEqual ( "Hello World!" ) ;
149164 } ) ;
165+ it ( "can inspect current bindings" , async ( ) => {
166+ const versionsRaw = await helper . run (
167+ `wrangler versions list --json --x-provision`
168+ ) ;
169+
170+ const versions = JSON . parse ( versionsRaw . stdout ) as unknown [ ] ;
150171
172+ const latest = versions . at ( - 1 ) as { id : string } ;
173+
174+ const versionView = await helper . run (
175+ `wrangler versions view ${ latest . id } --x-provision`
176+ ) ;
177+
178+ expect ( normalizeOutput ( versionView . output ) ) . toMatchInlineSnapshot ( `
179+ "Version ID: 00000000-0000-0000-0000-000000000000
180+ Created: TIMESTAMP
181+ Author:
182+ Source: Unknown (version_upload)
183+ Tag: -
184+ Message: -
185+ Handlers: fetch
186+ Compatibility Date: 2023-01-01
187+ [
188+ {
189+ "database_id": "00000000-0000-0000-0000-000000000000",
190+ "id": "00000000-0000-0000-0000-000000000000",
191+ "name": "D1",
192+ "type": "d1"
193+ },
194+ {
195+ "name": "KV",
196+ "namespace_id": "00000000000000000000000000000000",
197+ "type": "kv_namespace"
198+ },
199+ {
200+ "bucket_name": "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2",
201+ "name": "R2",
202+ "type": "r2_bucket"
203+ },
204+ {
205+ "bucket_name": "does-not-exist",
206+ "name": "R2_WITH_NAME",
207+ "type": "r2_bucket"
208+ }
209+ ]
210+ Your Worker has access to the following bindings:
211+ Binding Resource
212+ env.KV (00000000000000000000000000000000) KV Namespace
213+ env.D1 (00000000-0000-0000-0000-000000000000) D1 Database
214+ env.R2 (tmp-e2e-worker-00000000-0000-0000-0000-000000000000-r2) R2 Bucket
215+ env.R2_WITH_NAME (does-not-exist) R2 Bucket"
216+ ` ) ;
217+ } ) ;
151218 it ( "can inherit and provision resources on version upload" , async ( ) => {
152219 await helper . seed ( {
153220 "wrangler.toml" : dedent `
@@ -167,27 +234,29 @@ describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
167234 ) ;
168235 await worker . exitCode ;
169236 const output = await worker . output ;
170- expect ( normalize ( output ) ) . toMatchInlineSnapshot ( `
171- "Total Upload: xx KiB / gzip: xx KiB
172- The following bindings need to be provisioned:
173- Binding Resource
174- env.KV2 KV Namespace
175- Provisioning KV2 (KV Namespace)...
176- 🌀 Creating new KV Namespace "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-kv2"...
177- ✨ KV2 provisioned 🎉
178- 🎉 All resources provisioned, continuing with deployment...
179- Worker Startup Time: (TIMINGS)
180- Your Worker has access to the following bindings:
181- Binding Resource
182- env.KV2 (00000000000000000000000000000000) KV Namespace
183- env.R2 (inherited) R2 Bucket
184- Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
185- Worker Version ID: 00000000-0000-0000-0000-000000000000
186- Version Preview URL: https://tmp-e2e-worker-PREVIEW-URL.SUBDOMAIN.workers.dev
187- To deploy this version to production traffic use the command wrangler versions deploy
188- Changes to non-versioned settings (config properties 'logpush' or 'tail_consumers') take effect after your next deployment using the command wrangler versions deploy
189- Changes to triggers (routes, custom domains, cron schedules, etc) must be applied with the command wrangler triggers deploy"
190- ` ) ;
237+ expect ( normalize ( output ) ) . toMatchInlineSnapshot (
238+ `
239+ "Total Upload: xx KiB / gzip: xx KiB
240+ The following bindings need to be provisioned:
241+ Binding Resource
242+ env.KV2 KV Namespace
243+ Provisioning KV2 (KV Namespace)...
244+ 🌀 Creating new KV Namespace "tmp-e2e-worker-00000000-0000-0000-0000-000000000000-kv2"...
245+ ✨ KV2 provisioned 🎉
246+ 🎉 All resources provisioned, continuing with deployment...
247+ Worker Startup Time: (TIMINGS)
248+ Your Worker has access to the following bindings:
249+ Binding Resource
250+ env.KV2 (00000000000000000000000000000000) KV Namespace
251+ env.R2 (inherited) R2 Bucket
252+ Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
253+ Worker Version ID: 00000000-0000-0000-0000-000000000000
254+ Version Preview URL: https://tmp-e2e-worker-PREVIEW-URL.SUBDOMAIN.workers.dev
255+ To deploy this version to production traffic use the command wrangler versions deploy
256+ Changes to non-versioned settings (config properties 'logpush' or 'tail_consumers') take effect after your next deployment using the command wrangler versions deploy
257+ Changes to triggers (routes, custom domains, cron schedules, etc) must be applied with the command wrangler triggers deploy"
258+ `
259+ ) ;
191260 const kvMatch = output . match ( / e n v .K V 2 \( (?< kv > [ 0 - 9 a - f ] { 32 } ) / ) ;
192261 assert ( kvMatch ?. groups ) ;
193262 kvId2 = kvMatch . groups . kv ;
0 commit comments