Skip to content

Commit

Permalink
add summary
Browse files Browse the repository at this point in the history
Signed-off-by: flakey5 <[email protected]>
  • Loading branch information
flakey5 committed Nov 19, 2024
1 parent 57c13d0 commit 9e6819f
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions test/cache-interceptor/cache-tests.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict'

import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { styleText } from 'node:util'
import { Worker } from 'node:worker_threads'
import { Client, interceptors, setGlobalDispatcher } from '../../index.js'
import { Client, interceptors, setGlobalDispatcher, fetch } from '../../index.js'
import { getResults, runTests } from '../fixtures/cache-tests/test-engine/client/runner.mjs'
import tests from '../fixtures/cache-tests/tests/index.mjs'
import { once } from 'node:events'
Expand All @@ -12,7 +13,7 @@ import { determineTestResult, testLookup } from '../fixtures/cache-tests/test-en
const PROTOCOL = 'http'
const PORT = 8000
const BASE_URL = `${PROTOCOL}://localhost:${PORT}`
const PIDFILE = '/tmp/http-cache-test-server.pid'
const PIDFILE = join(tmpdir(), 'http-cache-test-server.pid')

// Start the test server, it's in a worker thread since the server isn't exposed
// for us to interact with
Expand All @@ -32,14 +33,26 @@ const client = new Client(BASE_URL).compose(interceptors.cache())
setGlobalDispatcher(client)

// Run the tests
await runTests(tests, globalThis.fetch, false, BASE_URL).catch(err => {
await runTests(tests, fetch, false, BASE_URL).catch(err => {
throw err
})

const stats = {
skipped: 0,
passed: 0,
failed: 0,
optionalFailed: 0,
setupFailed: 0,
testHarnessFailed: 0,
dependencyFailed: 0,
retried: 0
}

// Print the results
const results = getResults()
for (const testId in results) {
const test = testLookup(tests, testId)
// eslint-disable-next-line no-unused-vars
const [code, _, icon] = determineTestResult(tests, testId, results, false)

let status
Expand All @@ -49,50 +62,59 @@ for (const testId in results) {
// Untested
status = 'skipped'
color = 'gray'
stats.skipped++
break
case '\uf058':
// Pass
status = 'pass'
color = 'green'
stats.passed++
break
case '\uf057':
// Required behavior failed
status = 'failed'
color = 'red'
stats.failed++
break
case '\uf05a':
// Optional behavior failed
status = 'failed (optional)'
color = 'yellow'
stats.optionalFailed++
break
case '\uf055':
// Yes
status = 'yes'
color = 'green'
stats.passed++
break
case '\uf056':
// No
status = 'no'
color = 'red'
stats.failed++
break
case '\uf059':
// Setup failure
status = 'setup failure'
color = 'bgRed'
color = 'red'
break
case '\uf06a':
// Harness failure
status = 'test harness failure'
color = 'bgRed'
color = 'red'
stats.testHarnessFailed++
break
case '\uf192':
// Dependency failure
status = 'dependency failure'
color = 'bgRed'
color = 'red'
stats.dependencyFailed++
break
case '\uf01e':
status = 'retry'
color = 'yellow'
stats.retried++
break
default:
status = 'unknown'
Expand All @@ -109,3 +131,14 @@ for (const testId in results) {
}

await worker.terminate()

const testCount = Object.keys(results).length
console.log(`\n Total tests: ${testCount}`)
console.log(` ${styleText('gray', 'Skipped')}: ${stats.skipped} (${((stats.skipped / testCount) * 100).toFixed(1)}%)`)
console.log(` ${styleText('green', 'Passed')}: ${stats.passed} (${((stats.passed / testCount) * 100).toFixed(1)}%)`)
console.log(` ${styleText('red', 'Failed')}: ${stats.failed} (${((stats.failed / testCount) * 100).toFixed(1)}%)`)
console.log(` ${styleText('yellow', 'Failed (optional)')}: ${stats.optionalFailed} (${((stats.optionalFailed / testCount) * 100).toFixed(1)}%)`)
console.log(` ${styleText('red', 'Setup failed')}: ${stats.setupFailed} (${((stats.setupFailed / testCount) * 100).toFixed(1)}%)`)
console.log(`${styleText('red', 'Test Harness Failed')}: ${stats.testHarnessFailed} (${((stats.testHarnessFailed / testCount) * 100).toFixed(1)}%)`)
console.log(` ${styleText('red', 'Dependency Failed')}: ${stats.dependencyFailed} (${((stats.dependencyFailed / testCount) * 100).toFixed(1)}%)`)
console.log(` ${styleText('yellow', 'Retried')}: ${stats.retried} (${((stats.retried / testCount) * 100).toFixed(1)}%)`)

0 comments on commit 9e6819f

Please sign in to comment.