Skip to content

Commit 48a5493

Browse files
committed
fix: test timeout -d
1 parent 741627d commit 48a5493

File tree

4 files changed

+37
-2057
lines changed

4 files changed

+37
-2057
lines changed

@fiction/core/test-utils/setupTest.ts

+36-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
// setupTests.js
12
import process from 'node:process'
2-
import { beforeAll } from 'vitest'
3+
import { beforeAll, beforeEach } from 'vitest'
34

45
process.env.IS_TEST = '1'
56
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+
911
beforeAll(async () => {
1012
process.env.TEST_RUN = '1'
1113
process.env.IS_TEST = '1'
@@ -14,6 +16,35 @@ beforeAll(async () => {
1416
process.env.NODE_ENV = 'development'
1517
process.env.MODE = 'development'
1618

17-
if (typeof window !== 'undefined')
19+
if (typeof window !== 'undefined') {
1820
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
1950
})

0 commit comments

Comments
 (0)