1
+ // setupTests.js
1
2
import process from 'node:process'
2
- import { beforeAll } from 'vitest'
3
+ import { beforeAll , beforeEach } from 'vitest'
3
4
4
5
process . env . IS_TEST = '1'
5
6
process . env . TEST_ENV = 'unit'
6
- /**
7
- * IN SETUP just do global test variables, don't do imports
8
- */
7
+
8
+ const LOG_INTERVAL = 5 * 60 * 1000 // 5 minutes in milliseconds
9
+ const MAX_TEST_DURATION = 60 * 60 * 1000 // 1 hour max duration
10
+
9
11
beforeAll ( async ( ) => {
10
12
process . env . TEST_RUN = '1'
11
13
process . env . IS_TEST = '1'
@@ -14,6 +16,35 @@ beforeAll(async () => {
14
16
process . env . NODE_ENV = 'development'
15
17
process . env . MODE = 'development'
16
18
17
- if ( typeof window !== 'undefined' )
19
+ if ( typeof window !== 'undefined' ) {
18
20
Object . defineProperty ( window , 'scrollTo' , { value : ( ) => { } , writable : true } )
21
+ }
22
+ } )
23
+
24
+ beforeEach ( async ( testContext ) => {
25
+ const startTime = Date . now ( )
26
+
27
+ // Function to check and log duration
28
+ const checkDuration = ( ) => {
29
+ const elapsed = Date . now ( ) - startTime
30
+ const minutesElapsed = Math . floor ( elapsed / 1000 / 60 )
31
+
32
+ if ( elapsed >= LOG_INTERVAL && elapsed < MAX_TEST_DURATION ) {
33
+ console . warn (
34
+ `[${ new Date ( ) . toISOString ( ) } ] Test "${ testContext . task . name } " has been running for ${ minutesElapsed } minutes` ,
35
+ )
36
+ // Schedule the next check
37
+ const timeoutId = setTimeout ( checkDuration , LOG_INTERVAL )
38
+ timeoutId . unref ( ) // Ensure this timer doesn’t keep the process alive
39
+ }
40
+ else if ( elapsed >= MAX_TEST_DURATION ) {
41
+ console . warn (
42
+ `[${ new Date ( ) . toISOString ( ) } ] Test "${ testContext . task . name } " exceeded ${ MAX_TEST_DURATION / 60000 } minutes!` ,
43
+ )
44
+ }
45
+ }
46
+
47
+ // Start the first check after 5 minutes
48
+ const timeoutId = setTimeout ( checkDuration , LOG_INTERVAL )
49
+ timeoutId . unref ( ) // Unreference the initial timer
19
50
} )
0 commit comments