@@ -36,65 +36,53 @@ async function globalSetup(config: FullConfig) {
3636 } ) ;
3737
3838 // Teardown previous test data with retry logic
39- if ( token ) {
40- const maxAttempts = 3 ;
41- const delayMs = 2000 ;
42- let teardownSuccess = false ;
39+ if ( ! token ) {
40+ const errorMsg = 'e2e teardown failed - no available token (set E2E_TEST_TOKEN or E2E_TEST_TOKEN_<ENV>)' ;
41+ console . error ( '\n' , '\x1b[31m' , errorMsg , '\x1b[0m' , '\n' ) ;
42+ throw new Error ( errorMsg ) ;
43+ }
4344
44- for ( let attempt = 0 ; attempt < maxAttempts ; attempt ++ ) {
45- if ( attempt > 0 ) {
46- console . log ( `\x1b[33m%s\x1b[0m` , `Retrying teardown (attempt ${ attempt + 1 } /${ maxAttempts } )...` ) ;
47- await new Promise ( resolve => setTimeout ( resolve , delayMs ) ) ;
48- }
45+ const maxAttempts = 3 ;
46+ const delayMs = 2000 ;
47+
48+ for ( let attempt = 0 ; attempt < maxAttempts ; attempt ++ ) {
49+ if ( attempt > 0 ) {
50+ console . log ( `\x1b[33m%s\x1b[0m` , `Retrying teardown (attempt ${ attempt + 1 } /${ maxAttempts } )...` ) ;
51+ await new Promise ( resolve => setTimeout ( resolve , delayMs ) ) ;
52+ }
4953
50- try {
51- const res = await fetch ( e2eTestApi , {
52- body : JSON . stringify ( { } ) ,
53- headers : {
54- 'Accept' : 'application/json' ,
55- 'Content-Type' : 'application/json' ,
56- 'X-E2E-Test-Auth-Token' : token . trim ( ) ,
57- } ,
58- method : 'POST' ,
59- } ) ;
54+ try {
55+ const res = await fetch ( e2eTestApi , {
56+ body : JSON . stringify ( { } ) ,
57+ headers : {
58+ 'Accept' : 'application/json' ,
59+ 'Content-Type' : 'application/json' ,
60+ 'X-E2E-Test-Auth-Token' : token . trim ( ) ,
61+ } ,
62+ method : 'POST' ,
63+ } ) ;
6064
61- if ( res . ok ) {
62- console . log ( '\n' , '\x1b[32m' , 'e2e teardown successful' , '\x1b[0m' , '\n' ) ;
63- teardownSuccess = true ;
64- break ;
65- } else {
66- console . error ( '\x1b[31m%s\x1b[0m' , `✗ E2E teardown failed: ${ res . status } ` ) ;
67- if ( attempt < maxAttempts - 1 ) {
68- console . log ( '' ) ;
69- }
70- }
71- } catch ( error ) {
72- console . error ( '\x1b[31m%s\x1b[0m' , `✗ E2E teardown error: ${ error . message || String ( error ) } ` ) ;
73- if ( attempt < maxAttempts - 1 ) {
74- console . log ( '' ) ;
75- }
65+ if ( res . ok ) {
66+ console . log ( '\n' , '\x1b[32m' , 'e2e teardown successful' , '\x1b[0m' , '\n' ) ;
67+ console . log ( 'Starting E2E tests' ) ;
68+ return ;
7669 }
77- }
7870
79- if ( ! teardownSuccess ) {
80- const errorMsg = `e2e teardown failed after ${ maxAttempts } attempts` ;
81- console . error ( '\n' , '\x1b[31m' , errorMsg , '\x1b[0m' , '\n' ) ;
82- if ( process . env . E2E_LOCAL !== 'true' && process . env . E2E_DEV !== 'true' ) {
83- throw new Error ( errorMsg ) ; // Fail tests early in CI if teardown fails
71+ console . error ( '\x1b[31m%s\x1b[0m' , `✗ E2E teardown failed: ${ res . status } ` ) ;
72+ if ( attempt < maxAttempts - 1 ) {
73+ console . log ( '' ) ;
74+ }
75+ } catch ( error ) {
76+ console . error ( '\x1b[31m%s\x1b[0m' , `✗ E2E teardown error: ${ error . message || String ( error ) } ` ) ;
77+ if ( attempt < maxAttempts - 1 ) {
78+ console . log ( '' ) ;
8479 }
85- }
86- } else {
87- // Only warn for local/dev testing, don't fail
88- if ( process . env . E2E_LOCAL === 'true' || process . env . E2E_DEV === 'true' ) {
89- console . log ( '\n' , '\x1b[33m' , 'e2e teardown skipped (no token) - OK for local testing' , '\x1b[0m' , '\n' ) ;
90- } else {
91- const errorMsg = 'e2e teardown failed - no available token (set E2E_TEST_TOKEN or E2E_TEST_TOKEN_<ENV>)' ;
92- console . error ( '\n' , '\x1b[31m' , errorMsg , '\x1b[0m' , '\n' ) ;
93- throw new Error ( errorMsg ) ; // Fail tests in CI if token is missing
9480 }
9581 }
9682
97- console . log ( 'Starting E2E tests' ) ;
83+ const errorMsg = `e2e teardown failed after ${ maxAttempts } attempts` ;
84+ console . error ( '\n' , '\x1b[31m' , errorMsg , '\x1b[0m' , '\n' ) ;
85+ throw new Error ( errorMsg ) ;
9886}
9987
10088export default globalSetup ;
0 commit comments