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

Unclear how to use a custom reporter #68

Closed
jsumners-nr opened this issue Jul 24, 2024 · 0 comments · Fixed by #69
Closed

Unclear how to use a custom reporter #68

jsumners-nr opened this issue Jul 24, 2024 · 0 comments · Fixed by #69

Comments

@jsumners-nr
Copy link
Contributor

borp/borp.js

Lines 115 to 124 in b348999

for (const input of args.values.reporter) {
const [name, dest] = input.split(':')
const Ctor = reporters[name] || await import(name).then((m) => m.default || m)
const reporter = Ctor.prototype && Object.getOwnPropertyDescriptor(Ctor.prototype, 'constructor') ? new Ctor() : Ctor
let output = process.stdout
if (dest) {
output = createWriteStream(dest)
}
pipes.push([reporter, output])
}

If I have a reporter, e.g. ./test/lib/my-reporter.js, with code like:

my-reporter.js
'use strict'

const OUTPUT_MODE = process.env.OUTPUT_MODE?.toLowerCase() ?? 'simple'
const isSilent = OUTPUT_MODE === 'quiet' || OUTPUT_MODE === 'silent'

const { Transform } = require('node:stream')
const testReporter = new Transform({
  writableObjectMode: true,
  transform(event, encoding, callback) {
    switch (event.type) {
      case 'test:pass': {
        if (isSilent === true) {
          return callback(null, null)
        }
        return callback(null, `passed: ${event.data.file}\n`)
      }

      case 'test:fail': {
        return callback(null, `failed: ${event.data.file}\n`)
      }

      default: {
        callback(null, null)
      }
    }
  }
})

module.exports = testReporter

Then I am unclear how to get borp to use it. I think we should be doing borp --reporter ':./test/lib/my-reporter.js' 'test/**/*.test.js', but I'm having no luck with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant