Skip to content

Commit

Permalink
chore: setup borp reporter for switch to node test
Browse files Browse the repository at this point in the history
  • Loading branch information
dancastillo committed Sep 29, 2024
1 parent b1b9a75 commit 2413572
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"test:validator:integrity": "npm run build:validation && git diff --quiet --ignore-all-space --ignore-blank-lines --ignore-cr-at-eol lib/error-serializer.js && git diff --quiet --ignore-all-space --ignore-blank-lines --ignore-cr-at-eol lib/configValidator.js",
"test:typescript": "tsc test/types/import.ts --noEmit && tsd",
"test:watch": "npm run unit -- --watch --coverage-report=none --reporter=terse",
"unit": "tap",
"unit": "borp --coverage --check-coverage --lines 100 --reporter ./test/test-reporter.mjs",
"unit:junit": "tap-mocha-reporter xunit < out.tap > test/junit-testresults.xml",
"unit:report": "tap --coverage-report=html --coverage-report=cobertura | tee out.tap",
"citgm": "tap --jobs=1 --timeout=120"
Expand Down Expand Up @@ -163,6 +163,7 @@
"ajv-i18n": "^4.2.0",
"ajv-merge-patch": "^5.0.1",
"autocannon": "^7.15.0",
"borp": "^0.17.0",
"branch-comparer": "^1.1.0",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
Expand Down
10 changes: 5 additions & 5 deletions test/same-shape.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const fastify = require('..')

test('same shape on Request', async (t) => {
Expand All @@ -21,7 +21,7 @@ test('same shape on Request', async (t) => {

app.get('/', (req, reply) => {
if (request) {
t.equal(%HaveSameMap(request, req), true)
t.assert.deepStrictEqual(request, req)
}

request = req
Expand Down Expand Up @@ -51,7 +51,7 @@ test('same shape on Request when object', async (t) => {

app.get('/', (req, reply) => {
if (request) {
t.equal(%HaveSameMap(request, req), true)
t.assert.deepStrictEqual(request, req)
}

request = req
Expand Down Expand Up @@ -81,7 +81,7 @@ test('same shape on Reply', async (t) => {

app.get('/', (req, reply) => {
if (_reply) {
t.equal(%HaveSameMap(_reply, reply), true)
t.assert.deepStrictEqual(_reply, reply)
}

_reply = reply
Expand Down Expand Up @@ -111,7 +111,7 @@ test('same shape on Reply when object', async (t) => {

app.get('/', (req, reply) => {
if (_reply) {
t.equal(%HaveSameMap(_reply, reply), true)
t.assert.deepStrictEqual(_reply, reply)
}

_reply = reply
Expand Down
66 changes: 66 additions & 0 deletions test/test-reporter.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
function colorize (type, text) {
if (type === 'pass') {
const whiteText = `\x1b[30m${text}`
// Green background with black text
return `\x1b[42m${whiteText}\x1b[0m`
}

if (type === 'fail') {
const blackText = `\x1b[37m${text}`
// Red background with white text
return `\x1b[41m${blackText}\x1b[0m`
}

return text
}

function formatDiagnosticStr (str) {
return str.replace(/^(\w+)(\s*\d*)/i, (_, firstWord, rest) => {
return firstWord.charAt(0).toUpperCase() + firstWord.slice(1).toLowerCase() + ':' + rest
})
}

async function * reporter (source) {
const failed = new Set()
const diagnostics = new Set()
diagnostics.add('\n\n')

for await (const event of source) {
switch (event.type) {
case 'test:pass': {
yield `${colorize('pass', 'PASSED')}: ${event.data.file}\n`
break
}

case 'test:fail': {
failed.add(event.data.file)
yield `${colorize('fail', 'FAILED')}: ${event.data.file}\n`
break
}

case 'test:diagnostic': {
diagnostics.add(`${formatDiagnosticStr(event.data.message)}\n`)
break
}

default: {
yield ''
}
}
}

if (failed.size > 0) {
yield `\n\n${colorize('fail', 'Failed tests:')}\n`
for (const file of failed) {
yield `${file}\n`
}
}

diagnostics.add('\n')

for (const diagnostic of diagnostics) {
yield `${diagnostic}`
}
}

export default reporter

0 comments on commit 2413572

Please sign in to comment.