Skip to content

Commit

Permalink
feat: support custom reporters (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Feb 1, 2024
1 parent b4e6e2e commit d900129
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
10 changes: 3 additions & 7 deletions borp.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ try {

const reporters = {
...Reporters,
gh: githubReporter,
/* eslint new-cap: "off" */
spec: new Reporters.spec()
gh: githubReporter
}

// If we're running in a GitHub action, adds the gh reporter
Expand All @@ -103,10 +101,8 @@ try {

for (const input of args.values.reporter) {
const [name, dest] = input.split(':')
const reporter = reporters[name]
if (!reporter) {
throw new Error(`Unknown reporter: ${name}`)
}
const Ctor = reporters[name] || await import(name).then((m) => m.default || m)
const reporter = Object.getOwnPropertyDescriptor(Ctor.prototype, 'constructor') ? new Ctor() : Ctor
let output = process.stdout
if (dest) {
output = createWriteStream(dest)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"license": "MIT",
"devDependencies": {
"@matteo.collina/tspl": "^0.1.0",
"@reporters/silent": "^1.2.4",
"@types/node": "^20.10.0",
"desm": "^1.3.0",
"snazzy": "^9.0.0",
Expand Down
15 changes: 15 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,18 @@ test('disable ts and run no tests', async () => {

strictEqual(stdout.indexOf('tests 0') >= 0, true)
})

test('reporter from node_modules', async () => {
const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm2')
await rm(path.join(cwd, 'dist'), { recursive: true, force: true })
const { stdout } = await execa('node', [
borp,
'--reporter=spec',
'--reporter=@reporters/silent',
'--no-typescript'
], {
cwd
})

strictEqual(stdout.indexOf('tests 0') >= 0, true)
})

0 comments on commit d900129

Please sign in to comment.