Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Borp reporter for tap and nodetest local test #4

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,112 changes: 1,014 additions & 1,098 deletions lib/configValidator.js

Large diffs are not rendered by default.

185 changes: 88 additions & 97 deletions lib/error-serializer.js
Original file line number Diff line number Diff line change
@@ -1,120 +1,111 @@
// This file is autogenerated by build/build-error-serializer.js, do not edit
/* c8 ignore start */

'use strict'
'use strict'

const Serializer = require('fast-json-stringify/lib/serializer')
const serializerState = {"mode":"standalone"}
const serializer = Serializer.restoreFromState(serializerState)
const Serializer = require('fast-json-stringify/lib/serializer')
const serializerState = { mode: 'standalone' }
const serializer = Serializer.restoreFromState(serializerState)

const validator = null
const validator = null


module.exports = function anonymous(validator,serializer
module.exports = (function anonymous (validator, serializer
) {
const JSON_STR_BEGIN_OBJECT = '{'
const JSON_STR_END_OBJECT = '}'
const JSON_STR_BEGIN_ARRAY = '['
const JSON_STR_END_ARRAY = ']'
const JSON_STR_COMMA = ','
const JSON_STR_COLONS = ':'
const JSON_STR_QUOTE = '"'
const JSON_STR_EMPTY_OBJECT = JSON_STR_BEGIN_OBJECT + JSON_STR_END_OBJECT
const JSON_STR_EMPTY_ARRAY = JSON_STR_BEGIN_ARRAY + JSON_STR_END_ARRAY
const JSON_STR_EMPTY_STRING = JSON_STR_QUOTE + JSON_STR_QUOTE
const JSON_STR_NULL = 'null'

const JSON_STR_BEGIN_OBJECT = '{'
const JSON_STR_END_OBJECT = '}'
const JSON_STR_BEGIN_ARRAY = '['
const JSON_STR_END_ARRAY = ']'
const JSON_STR_COMMA = ','
const JSON_STR_COLONS = ':'
const JSON_STR_QUOTE = '"'
const JSON_STR_EMPTY_OBJECT = JSON_STR_BEGIN_OBJECT + JSON_STR_END_OBJECT
const JSON_STR_EMPTY_ARRAY = JSON_STR_BEGIN_ARRAY + JSON_STR_END_ARRAY
const JSON_STR_EMPTY_STRING = JSON_STR_QUOTE + JSON_STR_QUOTE
const JSON_STR_NULL = 'null'



// #
function anonymous0 (input) {
const obj = (input && typeof input.toJSON === 'function')
? input.toJSON()
: input

if (obj === null) return JSON_STR_EMPTY_OBJECT

let value
let json = JSON_STR_BEGIN_OBJECT
let addComma = false

value = obj["statusCode"]
if (value !== undefined) {
!addComma && (addComma = true) || (json += JSON_STR_COMMA)
json += "\"statusCode\":"
json += serializer.asNumber(value)
}
// #
function anonymous0 (input) {
const obj = (input && typeof input.toJSON === 'function')
? input.toJSON()
: input

if (obj === null) return JSON_STR_EMPTY_OBJECT

let value
let json = JSON_STR_BEGIN_OBJECT
let addComma = false

value = obj.statusCode
if (value !== undefined) {
!addComma && (addComma = true) || (json += JSON_STR_COMMA)
json += '"statusCode":'
json += serializer.asNumber(value)
}

value = obj.code
if (value !== undefined) {
!addComma && (addComma = true) || (json += JSON_STR_COMMA)
json += '"code":'

value = obj["code"]
if (value !== undefined) {
!addComma && (addComma = true) || (json += JSON_STR_COMMA)
json += "\"code\":"

if (typeof value !== 'string') {
if (value === null) {
json += JSON_STR_EMPTY_STRING
} else if (value instanceof Date) {
json += JSON_STR_QUOTE + value.toISOString() + JSON_STR_QUOTE
} else if (value instanceof RegExp) {
json += serializer.asString(value.source)
} else {
json += serializer.asString(value.toString())
}
if (typeof value !== 'string') {
if (value === null) {
json += JSON_STR_EMPTY_STRING
} else if (value instanceof Date) {
json += JSON_STR_QUOTE + value.toISOString() + JSON_STR_QUOTE
} else if (value instanceof RegExp) {
json += serializer.asString(value.source)
} else {
json += serializer.asString(value)
json += serializer.asString(value.toString())
}

} else {
json += serializer.asString(value)
}
}

value = obj.error
if (value !== undefined) {
!addComma && (addComma = true) || (json += JSON_STR_COMMA)
json += '"error":'

value = obj["error"]
if (value !== undefined) {
!addComma && (addComma = true) || (json += JSON_STR_COMMA)
json += "\"error\":"

if (typeof value !== 'string') {
if (value === null) {
json += JSON_STR_EMPTY_STRING
} else if (value instanceof Date) {
json += JSON_STR_QUOTE + value.toISOString() + JSON_STR_QUOTE
} else if (value instanceof RegExp) {
json += serializer.asString(value.source)
} else {
json += serializer.asString(value.toString())
}
if (typeof value !== 'string') {
if (value === null) {
json += JSON_STR_EMPTY_STRING
} else if (value instanceof Date) {
json += JSON_STR_QUOTE + value.toISOString() + JSON_STR_QUOTE
} else if (value instanceof RegExp) {
json += serializer.asString(value.source)
} else {
json += serializer.asString(value)
json += serializer.asString(value.toString())
}

} else {
json += serializer.asString(value)
}
}

value = obj.message
if (value !== undefined) {
!addComma && (addComma = true) || (json += JSON_STR_COMMA)
json += '"message":'

value = obj["message"]
if (value !== undefined) {
!addComma && (addComma = true) || (json += JSON_STR_COMMA)
json += "\"message\":"

if (typeof value !== 'string') {
if (value === null) {
json += JSON_STR_EMPTY_STRING
} else if (value instanceof Date) {
json += JSON_STR_QUOTE + value.toISOString() + JSON_STR_QUOTE
} else if (value instanceof RegExp) {
json += serializer.asString(value.source)
} else {
json += serializer.asString(value.toString())
}
if (typeof value !== 'string') {
if (value === null) {
json += JSON_STR_EMPTY_STRING
} else if (value instanceof Date) {
json += JSON_STR_QUOTE + value.toISOString() + JSON_STR_QUOTE
} else if (value instanceof RegExp) {
json += serializer.asString(value.source)
} else {
json += serializer.asString(value)
json += serializer.asString(value.toString())
}

} else {
json += serializer.asString(value)
}
}

return json + JSON_STR_END_OBJECT

}

const main = anonymous0
return main

}(validator, serializer)
}

const main = anonymous0
return main
}(validator, serializer))
/* c8 ignore stop */
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
19 changes: 10 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": "borp --reporter=./test/test-reporter.mjs --coverage --check-coverage --lines 100",
"coverage:ci": "nyc --coverage-report=html --coverage-report=lcov borp --reporter=./test/test-reporter.mjs --coverage --check-coverage",
"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",
"unit:report": "nyc --coverage-report=html --reporter=cobertura borp --reporter=./test/test-reporter.mjs --coverage --check-coverage",
"citgm": "borp --reporter=./test/test-reporter.mjs --coverage --check-coverage --concurrency=1"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -151,6 +150,7 @@
}
],
"devDependencies": {
"@dancastillo/testing-borp-with-fastify": "^0.17.6",
"@fastify/pre-commit": "^2.1.0",
"@sinclair/typebox": "^0.33.4",
"@sinonjs/fake-timers": "^11.2.2",
Expand Down Expand Up @@ -178,6 +178,7 @@
"markdownlint-cli2": "^0.13.0",
"neostandard": "^0.11.3",
"node-forge": "^1.3.1",
"nyc": "^17.1.0",
"proxyquire": "^2.1.3",
"simple-get": "^4.0.1",
"split2": "^4.2.0",
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
2 changes: 1 addition & 1 deletion test/schema-serialization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ test('Different content types', t => {
}
}
}, function (req, reply) {
switch (req.headers['code']) {
switch (req.headers.code) {
case '200': {
reply.header('Content-Type', 'application/json')
reply.code(200).send({ age: 18, city: 'AU' })
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
Loading