@@ -17,6 +17,63 @@ async function globalTeardown() {
1717
1818  LoginTestUtil . resetCache ( ) ; 
1919  console . log ( '✅ Test cache cleared' ) ; 
20+ 
21+   // Clean up test notebooks that may have been left behind due to test failures 
22+   await  cleanupTestNotebooks ( ) ; 
23+ } 
24+ 
25+ async  function  cleanupTestNotebooks ( )  { 
26+   try  { 
27+     console . log ( '🗂️ Cleaning up test notebooks...' ) ; 
28+ 
29+     const  baseURL  =  process . env . CI  ? 'http://localhost:8080'  : 'http://localhost:4200' ; 
30+ 
31+     // Get all notebooks 
32+     const  response  =  await  fetch ( `${ baseURL }  /api/notebook` ) ; 
33+     const  data  =  await  response . json ( ) ; 
34+ 
35+     if  ( ! data . body  ||  ! Array . isArray ( data . body ) )  { 
36+       console . log ( 'No notebooks found or invalid response format' ) ; 
37+       return ; 
38+     } 
39+ 
40+     // Filter notebooks that start with "Test Notebook" (created by createTestNotebook) 
41+     const  testNotebooks  =  data . body . filter ( 
42+       ( notebook : {  path : string  } )  =>  notebook . path  &&  notebook . path . startsWith ( '/Test Notebook ' ) 
43+     ) ; 
44+ 
45+     if  ( testNotebooks . length  ===  0 )  { 
46+       console . log ( '✅ No test notebooks to clean up' ) ; 
47+       return ; 
48+     } 
49+ 
50+     console . log ( `Found ${ testNotebooks . length }   test notebooks to delete` ) ; 
51+ 
52+     // Delete test notebooks 
53+     for  ( const  notebook  of  testNotebooks )  { 
54+       try  { 
55+         console . log ( `Deleting test notebook: ${ notebook . id }   (${ notebook . path }  )` ) ; 
56+         const  deleteResponse  =  await  fetch ( `${ baseURL }  /api/notebook/${ notebook . id }  ` ,  { 
57+           method : 'DELETE' 
58+         } ) ; 
59+ 
60+         if  ( deleteResponse . ok )  { 
61+           console . log ( `✅ Deleted: ${ notebook . path }  ` ) ; 
62+         }  else  { 
63+           console . warn ( `⚠️ Failed to delete ${ notebook . path }  : ${ deleteResponse . status }  ` ) ; 
64+         } 
65+ 
66+         // Small delay to avoid overwhelming the server 
67+         await  new  Promise ( resolve  =>  setTimeout ( resolve ,  50 ) ) ; 
68+       }  catch  ( error )  { 
69+         console . warn ( `⚠️ Error deleting notebook ${ notebook . id }  :` ,  error ) ; 
70+       } 
71+     } 
72+ 
73+     console . log ( '✅ Test notebook cleanup completed' ) ; 
74+   }  catch  ( error )  { 
75+     console . warn ( '⚠️ Failed to cleanup test notebooks:' ,  error ) ; 
76+   } 
2077} 
2178
2279export  default  globalTeardown ; 
0 commit comments