Files
websitedev/proto/jest.globalSetup.integration.js

51 lines
1.4 KiB
JavaScript
Executable File

// Global setup for integration tests
module.exports = async () => {
console.log('🔧 Setting up integration test environment...')
// Wait for Docker services to be ready
const maxWaitTime = 60000 // 1 minute
const checkInterval = 2000 // 2 seconds
let waitTime = 0
const checkServices = async () => {
try {
const { fetch } = require('undici')
// Check if Next.js app is ready
const response = await fetch('http://localhost:3000/api/health', {
timeout: 5000
})
if (response.ok) {
console.log('✅ Docker services are ready!')
return true
}
} catch (error) {
// Services not ready yet
}
return false
}
// Only check services if INTEGRATION_TESTS is enabled
if (process.env.INTEGRATION_TESTS === '1' || process.env.E2E_TESTS === '1') {
console.log('⏳ Waiting for Docker services to be ready...')
while (waitTime < maxWaitTime) {
if (await checkServices()) {
break
}
await new Promise(resolve => setTimeout(resolve, checkInterval))
waitTime += checkInterval
if (waitTime % 10000 === 0) {
console.log(`⏳ Still waiting... (${waitTime / 1000}s elapsed)`)
}
}
if (waitTime >= maxWaitTime) {
console.warn('⚠️ Docker services may not be fully ready. Tests might fail.')
}
}
}