Files
DevRunbook-Public/scripts/run-integration-tests.mjs
T
DevRunbook release export cfd2804e27
Managed validation / full (push) Successful in 3m18s
Publish DevRunbook source
2026-09-03 04:09:17 +02:00

90 lines
2.3 KiB
JavaScript

import { spawnSync } from 'node:child_process'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const repositoryRoot = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'..',
)
if (!process.env.DATABASE_URL) {
console.error(
'Integration gate failed: DATABASE_URL is required and all PostgreSQL tests would otherwise be skipped.',
)
process.exit(1)
}
const vitestPath = path.join(
repositoryRoot,
'node_modules',
'vitest',
'vitest.mjs',
)
const startedAt = Date.now()
const result = spawnSync(
process.execPath,
[
vitestPath,
'run',
'--config',
path.join(repositoryRoot, 'vitest.integration.config.ts'),
'--reporter=json',
],
{
cwd: repositoryRoot,
encoding: 'utf8',
env: process.env,
maxBuffer: 64 * 1024 * 1024,
},
)
if (result.stderr) process.stderr.write(result.stderr)
let report
try {
report = JSON.parse(result.stdout)
} catch {
if (result.stdout) process.stdout.write(result.stdout)
console.error(
'Integration gate failed: Vitest did not produce a valid JSON report.',
)
process.exit(result.status && result.status !== 0 ? result.status : 1)
}
const executed = report.numPassedTests + report.numFailedTests
const skipped = report.numPendingTests
const failed = report.numFailedTests
const durationMs = Date.now() - startedAt
console.log(
`Integration test summary: executed=${executed} skipped=${skipped} failed=${failed} durationMs=${durationMs}`,
)
if (result.status !== 0 || failed > 0) {
for (const testFile of report.testResults ?? []) {
for (const assertion of testFile.assertionResults ?? []) {
if (assertion.status !== 'failed') continue
console.error(`FAIL ${assertion.fullName}`)
for (const message of assertion.failureMessages ?? [])
console.error(message)
}
}
process.exit(result.status && result.status !== 0 ? result.status : 1)
}
if (executed === 0) {
console.error(
`Integration gate failed: zero tests executed (${skipped} skipped). A green Vitest process is insufficient.`,
)
process.exit(1)
}
if (skipped > 0) {
console.error(
`Integration gate failed: ${skipped} required PostgreSQL tests were skipped.`,
)
process.exit(1)
}
console.log('Integration gate passed with non-zero PostgreSQL test execution.')