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

Do not crash when using gh reporter #18

Merged
merged 2 commits into from
Feb 2, 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
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)
})
Loading