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

feat: support custom reporters #16

Merged
merged 1 commit into from
Feb 1, 2024
Merged
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
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()
mcollina marked this conversation as resolved.
Show resolved Hide resolved
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)
})