Skip to content

Commit

Permalink
chore: setup borp reporter for switch to node test (fastify#5720)
Browse files Browse the repository at this point in the history
* chore: setup borp reporter for switch to node test

* chore: update scripts and test-reporter

* update scripts

* fix

* bump borp to v0.18.0

* pr feedback

* pr feedback

* fix file name to .borp.yaml
  • Loading branch information
dancastillo authored Oct 13, 2024
1 parent db7e382 commit 025fa7a
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .borp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
files:
- 'test/**/*.test.js'
- 'test/**/*.test.mjs'
2 changes: 2 additions & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict'

/* c8 ignore start */
/**
* Code imported from `pino-http`
* Repo: https://github.com/pinojs/pino-http
* License: MIT (https://raw.githubusercontent.com/pinojs/pino-http/master/LICENSE)
*/
/* c8 ignore stop */

const nullLogger = require('abstract-logging')
const pino = require('pino')
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@
"benchmark": "concurrently -k -s first \"node ./examples/benchmark/simple.js\" \"autocannon -c 100 -d 30 -p 10 localhost:3000/\"",
"benchmark:parser": "concurrently -k -s first \"node ./examples/benchmark/parser.js\" \"autocannon -c 100 -d 30 -p 10 -i ./examples/benchmark/body.json -H \"content-type:application/jsoff\" -m POST localhost:3000/\"",
"build:validation": "node build/build-error-serializer.js && node build/build-validation.js",
"coverage": "npm run unit -- --coverage-report=html",
"coverage:ci": "tap --coverage-report=html --coverage-report=lcov --allow-incomplete-coverage",
"coverage:ci-check-coverage": "tap replay",
"coverage": "c8 --reporter html borp --reporter=./test/test-reporter.mjs --coverage --check-coverage --lines 100 ",
"coverage:ci": "c8 --reporter lcov --reporter html borp --reporter=./test/test-reporter.mjs",
"coverage:ci-check-coverage": "borp --reporter=./test/test-reporter.mjs --coverage --check-coverage --lines 100",
"lint": "npm run lint:eslint",
"lint:fix": "eslint --fix",
"lint:markdown": "markdownlint-cli2",
"lint:eslint": "eslint",
"prepublishOnly": "cross-env PREPUBLISH=true tap --allow-incomplete-coverage test/build/**.test.js && npm run test:validator:integrity",
"prepublishOnly": "cross-env PREPUBLISH=true borp --reporter=./test/test-reporter.mjs && npm run test:validator:integrity",
"test": "npm run lint && npm run unit && npm run test:typescript",
"test:ci": "npm run unit -- --coverage-report=lcovonly && npm run test:typescript",
"test:ci": "npm run unit && npm run test:typescript",
"test:report": "npm run lint && npm run unit:report && npm run test:typescript",
"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: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"
"unit": "borp --reporter=./test/test-reporter.mjs --coverage --check-coverage",
"unit:report": "c8 --reporter html borp --reporter=./test/test-reporter.mjs",
"citgm": "borp --reporter=./test/test-reporter.mjs --coverage --check-coverage --concurrency=1"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -163,6 +162,7 @@
"ajv-i18n": "^4.2.0",
"ajv-merge-patch": "^5.0.1",
"autocannon": "^7.15.0",
"borp": "^0.18.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
68 changes: 68 additions & 0 deletions test/test-reporter.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function colorize (type, text) {
if (type === 'pass') {
const blackText = `\x1b[30m${text}`
const boldblackText = `\x1b[1m${blackText}`
// Green background with black text
return `\x1b[42m${boldblackText}\x1b[0m`
}

if (type === 'fail') {
const whiteText = `\x1b[37m${text}`
const boldWhiteText = `\x1b[1m${whiteText}`
// Red background with white text
return `\x1b[41m${boldWhiteText}\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()

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

case 'test:fail': {
failed.add(event.data.name || event.data.file)
yield `${colorize('fail', 'FAILED')}: ${event.data.file || event.data.name}\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`
}
}

yield '\n'

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

export default reporter

0 comments on commit 025fa7a

Please sign in to comment.