Skip to content

Commit

Permalink
Do not crash when using gh reporter (#18)
Browse files Browse the repository at this point in the history
* Do not crash when using gh reporter

Signed-off-by: Matteo Collina <hello@matteocollina.com>

* fixup

Signed-off-by: Matteo Collina <hello@matteocollina.com>

---------

Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Feb 2, 2024
1 parent 0995a48 commit 8d52de1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion borp.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ try {
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 = Object.getOwnPropertyDescriptor(Ctor.prototype, 'constructor') ? new Ctor() : Ctor
const reporter = Ctor.prototype && Object.getOwnPropertyDescriptor(Ctor.prototype, 'constructor') ? new Ctor() : Ctor
let output = process.stdout
if (dest) {
output = createWriteStream(dest)
Expand Down Expand Up @@ -140,6 +140,7 @@ try {
/* c8 ignore next 3 */
} catch (err) {
console.error(err)
process.exitCode = 1
} finally {
if (covDir) {
try {
Expand Down
23 changes: 18 additions & 5 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,29 @@ test('disable ts and run no tests', async () => {
})

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 cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm')
const { stdout } = await execa('node', [
borp,
'--reporter=spec',
'--reporter=@reporters/silent',
'--no-typescript'
'--reporter=@reporters/silent'
], {
cwd
})

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

test('gh reporter', async () => {
const cwd = join(import.meta.url, '..', 'fixtures', 'js-esm')
const { stdout } = await execa('node', [
borp,
'--reporter=gh'
], {
cwd,
env: {
GITHUB_ACTIONS: '1'
}
})

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

0 comments on commit 8d52de1

Please sign in to comment.