forked from fastify/fastify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: setup borp reporter for switch to node test
- Loading branch information
1 parent
b1b9a75
commit 2413572
Showing
3 changed files
with
73 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |