4type HealthResultsH = Record<string, boolean> 5type TestResult = { idx: number; name: string; passed: boolean; msg: string } 6type GqlResponse = { errors?: { message?: string }[] } 7type LogHealthOpts = { hostname?: string; gqlPath?: string; operationH?: Record<string, string>; responsesH?: Record<string, unknown>; diagnosticsH?: Record<string, GqlTestDiagnostics> } 10 if (diag.timedOut && !diag.gqlRequestSent) return 'page timed out, no gql request sent' 11 if (diag.timedOut && diag.gqlRequestSent) return 'gql request sent but response not received before timeout' 12 if (diag.gqlRespHadError) return `gql error: ${diag.gqlRespErrSnip?.slice(0, 120) || 'unknown'}` 13 return 'no gql request intercepted' 16export const logHealthTestResults = (resultsH: HealthResultsH, { hostname, gqlPath, operationH = {}, responsesH = {}, diagnosticsH = {} }: LogHealthOpts = {}) => { 17 const testEntries = Object.entries(resultsH) 18 const n = testEntries.length 19 const targetInfo = hostname ? `${hostname}${gqlPath || ''}` : '' 21 const testResults: TestResult[] = [] 22 for (let idx = 0; idx < testEntries.length; idx++) { 23 const [testName, result] = testEntries[idx] 24 const expectsTrue = testName.endsWith('True') 25 const expectsFalse = testName.endsWith('False') 26 const passed = (expectsTrue && result === true) || (expectsFalse && result === false) 27 const opName = operationH[testName] || '' 28 const gqlError = (responsesH[testName] as GqlResponse)?.errors?.[0]?.message 29 const diag = !passed && diagnosticsH[testName] ? ` [${fmtDiagnostics(diagnosticsH[testName])}]` : '' 30 const msgParts = [targetInfo, opName].filter(Boolean).join(' ') 31 const failReason = gqlError ? `(got ${result}: "${gqlError}")` : `(got ${result}, expected ${expectsTrue ? 'true' : 'false'})` 32 const msg = passed ? msgParts : `${failReason} ${msgParts}${diag}` 33 testResults.push({idx, name: testName, passed, msg}) 34 console.log(formatTestLine({idx: idx + 1, total: n, passed, suiteName: 'healthgql', testName, msg})) 37 const passCount = testResults.filter(r => r.passed).length 38 const allPassed = testResults.every(r => r.passed) 40 return {passed: allPassed, message: `${passCount}/${n} healthgql tests passed`, testResults}