diff --git a/bin/c8.js b/bin/c8.js index 2a908458..21db5452 100755 --- a/bin/c8.js +++ b/bin/c8.js @@ -29,7 +29,12 @@ async function run () { process.env.NODE_V8_COVERAGE = argv.tempDirectory foreground(hideInstrumenterArgs(argv), async (done) => { - await outputReport(argv) + try { + await outputReport(argv) + } catch (err) { + console.error(err.stack) + process.exitCode = 1 + } done() }) } diff --git a/test/integration.js b/test/integration.js index e3300067..b2753012 100644 --- a/test/integration.js +++ b/test/integration.js @@ -53,6 +53,18 @@ describe('c8', () => { ) }) + it('exits with 1 when report output fails', () => { + const { status, stderr } = spawnSync(nodePath, [ + c8Path, + '--clean=false', + '--reporter=unknown', + nodePath, + '--version' + ]) + status.should.equal(1) + stderr.toString().should.match(/Cannot find module 'unknown'/u) + }) + describe('check-coverage', () => { before(() => { spawnSync(nodePath, [