@@ -341,7 +341,30 @@ describe.sequential.each(RUNTIMES)("Bindings: $flags", ({ runtime, flags }) => {
341341 expect ( result . stdout ) . toBe ( "new-value" ) ;
342342 } ) ;
343343
344- it ( "supports Workers Sites bindings" , async ( ) => {
344+ it ( "supports Workers Sites bindings" , async ( { onTestFinished } ) => {
345+ if ( ! isLocal ) {
346+ onTestFinished ( async ( ) => {
347+ // Try to clean up created remote Workers Sites namespace
348+ const listResult = await helper . run ( `wrangler kv namespace list` ) ;
349+ const list = JSON . parse (
350+ // Ignore extra debug output
351+ listResult . stdout . substring (
352+ listResult . stdout . indexOf ( "[" ) ,
353+ listResult . stdout . lastIndexOf ( "]" ) + 1
354+ )
355+ ) ;
356+ assert ( Array . isArray ( list ) ) ;
357+ const ns = list . find ( ( { title } ) => title . includes ( workerName ) ) ;
358+ if ( ns === undefined ) {
359+ console . warn ( "Couldn't find Workers Sites namespace to delete" ) ;
360+ } else {
361+ await helper . run (
362+ `wrangler kv namespace delete --namespace-id ${ ns . id } `
363+ ) ;
364+ }
365+ } ) ;
366+ }
367+
345368 const kvAssetHandler = require . resolve ( "@cloudflare/kv-asset-handler" ) ;
346369 await helper . seed ( {
347370 "public/index.html" : "<h1>👋</h1>" ,
@@ -380,27 +403,6 @@ describe.sequential.each(RUNTIMES)("Bindings: $flags", ({ runtime, flags }) => {
380403 const { url } = await worker . waitForReady ( ) ;
381404 const res = await fetch ( url ) ;
382405 expect ( await res . text ( ) ) . toBe ( "<h1>👋</h1>" ) ;
383-
384- // Try to clean up created remote Workers Sites namespace
385- if ( ! isLocal ) {
386- const listResult = await helper . run ( `wrangler kv namespace list` ) ;
387- const list = JSON . parse (
388- // Ignore extra debug output
389- listResult . stdout . substring (
390- listResult . stdout . indexOf ( "[" ) ,
391- listResult . stdout . lastIndexOf ( "]" ) + 1
392- )
393- ) ;
394- assert ( Array . isArray ( list ) ) ;
395- const ns = list . find ( ( { title } ) => title . includes ( workerName ) ) ;
396- if ( ns === undefined ) {
397- console . warn ( "Couldn't find Workers Sites namespace to delete" ) ;
398- } else {
399- await helper . run (
400- `wrangler kv namespace delete --namespace-id ${ ns . id } `
401- ) ;
402- }
403- }
404406 } ) ;
405407
406408 it ( "exposes R2 bucket bindings" , async ( ) => {
0 commit comments