Open History to see the last commit
1import { readFile, writeFile } from 'node:fs/promises'
2
3const [input, output] = process.argv.slice(2)
4if (!input || !output) throw new Error('Usage: summarize-test-results.mjs input.json output.json')
5const report = JSON.parse(await readFile(input, 'utf8'))
6const secrets = Object.entries(process.env).filter(([key, value]) => /SECRET|TOKEN|KEY|PASSWORD|DATABASE_URL/.test(key) && value?.length >= 8).map(([, value]) => value)
7if (process.env.DURABLE_STREAMS_KEYRING) secrets.push(...Object.values(JSON.parse(process.env.DURABLE_STREAMS_KEYRING).keys))
8const redact = (message) => {
9 let text = String(message)
10 for (const secret of secrets) text = text.replaceAll(secret, '[redacted]')
11 return text.replace(/postgres(?:ql)?:\/\/[^\s'"<>]+/g, '[database URL]')
12 .replace(/dsw\.2\.[A-Za-z0-9_-]{1,128}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]{43}|dsw\.[0-9a-f-]{36}\.[A-Za-z0-9_-]{43}/gi, '[wake token]').slice(0, 8000)
13}
14await writeFile(output, JSON.stringify({ total: report.numTotalTests, passed: report.numPassedTests,
15 failed: report.numFailedTests, pending: report.numPendingTests,
16 suites: report.testResults.map((suite) => ({ file: suite.name.split(/[\\/]/).at(-1), status: suite.status,
17 message: redact(suite.message ?? ''), tests: suite.assertionResults.map((test) => ({ name: test.fullName, status: test.status,
18 durationMs: test.duration, failures: test.failureMessages.map(redact) })) })),
19}, null, 2) + '\n')