Skip to content

Commit 8d52de1

Browse files
authored
Do not crash when using gh reporter (#18)
* Do not crash when using gh reporter Signed-off-by: Matteo Collina <[email protected]> * fixup Signed-off-by: Matteo Collina <[email protected]> --------- Signed-off-by: Matteo Collina <[email protected]>
1 parent 0995a48 commit 8d52de1

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

borp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ try {
102102
for (const input of args.values.reporter) {
103103
const [name, dest] = input.split(':')
104104
const Ctor = reporters[name] || await import(name).then((m) => m.default || m)
105-
const reporter = Object.getOwnPropertyDescriptor(Ctor.prototype, 'constructor') ? new Ctor() : Ctor
105+
const reporter = Ctor.prototype && Object.getOwnPropertyDescriptor(Ctor.prototype, 'constructor') ? new Ctor() : Ctor
106106
let output = process.stdout
107107
if (dest) {
108108
output = createWriteStream(dest)
@@ -140,6 +140,7 @@ try {
140140
/* c8 ignore next 3 */
141141
} catch (err) {
142142
console.error(err)
143+
process.exitCode = 1
143144
} finally {
144145
if (covDir) {
145146
try {

test/cli.test.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,29 @@ test('disable ts and run no tests', async () => {
6262
})
6363

6464
test('reporter from node_modules', async () => {
65-
const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm2')
66-
await rm(path.join(cwd, 'dist'), { recursive: true, force: true })
65+
const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm')
6766
const { stdout } = await execa('node', [
6867
borp,
6968
'--reporter=spec',
70-
'--reporter=@reporters/silent',
71-
'--no-typescript'
69+
'--reporter=@reporters/silent'
7270
], {
7371
cwd
7472
})
7573

76-
strictEqual(stdout.indexOf('tests 0') >= 0, true)
74+
strictEqual(stdout.indexOf('tests 2') >= 0, true)
75+
})
76+
77+
test('gh reporter', async () => {
78+
const cwd = join(import.meta.url, '..', 'fixtures', 'js-esm')
79+
const { stdout } = await execa('node', [
80+
borp,
81+
'--reporter=gh'
82+
], {
83+
cwd,
84+
env: {
85+
GITHUB_ACTIONS: '1'
86+
}
87+
})
88+
89+
strictEqual(stdout.indexOf('::notice') >= 0, true)
7790
})

0 commit comments

Comments
 (0)