Skip to content

Commit

Permalink
Merge pull request #894 from geek/master
Browse files Browse the repository at this point in the history
Have correct exit code with multiple reporters
  • Loading branch information
geek committed Nov 13, 2018
2 parents 6dbb48c + 4ef5bc4 commit d5c6976
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
3 changes: 0 additions & 3 deletions bin/lab
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ if (process.env.NODE_DEBUG_OPTION || inspectArg) {
const main = async () => {

let { code } = await require('../lib/cli').run();
if (typeof code !== 'number') {
code = code[Object.keys(code)[0]];
}
process.exit(code);
};

Expand Down
5 changes: 2 additions & 3 deletions lib/reporters/multiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,14 @@ internals.Reporter.prototype.report = function (text) {

internals.Reporter.prototype.finalize = async function (notebook) {

this._results = { err: false, code: [], output: [], count: 0 };
this._results = { err: false, code: 0, output: [], count: 0 };

for (const key in this._reporters) {
this._results.count++;
try {
const { code, output } = await this._reporters[key].finalize(notebook);
this._results.code[key] = code;
this._results.code = this._results.code || code;
this._results.output[key] = output;
this._results.processCode = this._results.processCode || code;
}
catch (ex) {
this._results.err = this._results.err || ex;
Expand Down
2 changes: 1 addition & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('CLI', () => {

it('exits with code 1 when function returns error with multiple reporters', async () => {

const result = await RunCli(['test/cli_failure/failure.js', '-r', 'console', '-r', 'lcov']);
const result = await RunCli(['test/cli_throws/throws.js', '-r', 'console', '-r', 'lcov']);
expect(result.code).to.equal(1);
});

Expand Down
6 changes: 3 additions & 3 deletions test/cli_throws/throws.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ const it = lab.it;

describe('Test CLI throws', () => {

after((done) => {
after(() => {

throw new Error('throwing after');
});

it('handles thrown error', (done) => {
it('handles thrown error', () => {

done();
throw new Error('throwing in test');
});
});

10 changes: 3 additions & 7 deletions test/reporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -1863,8 +1863,7 @@ describe('Reporter', () => {
const filename = Path.join(Os.tmpdir(), [Date.now(), process.pid, Crypto.randomBytes(8).toString('hex')].join('-'));

const { code, output } = await Lab.report(script, { reporter: ['lcov', 'console'], output: [filename, recorder], coverage: true });
expect(code.lcov).to.equal(0);
expect(code.console).to.equal(0);
expect(code).to.equal(0);
expect(output.lcov).to.equal(Fs.readFileSync(filename).toString());
expect(output.console).to.equal(recorder.content);
Fs.unlinkSync(filename);
Expand Down Expand Up @@ -1908,9 +1907,7 @@ describe('Reporter', () => {
const filename = Path.join(Os.tmpdir(), [Date.now(), process.pid, Crypto.randomBytes(8).toString('hex')].join('-'));

const { code, output } = await Lab.report(script, { reporter: ['lcov', 'html', 'console'], output: [filename, htmlRecorder, consoleRecorder], coverage: true, coveragePath: Path.join(__dirname, './coverage/basic.js') });
expect(code.console).to.equal(1);
expect(code.lcov).to.equal(1);
expect(code.html).to.equal(1);
expect(code).to.equal(1);
expect(output.lcov).to.equal(Fs.readFileSync(filename).toString());
expect(output.html).to.equal(htmlRecorder.content);
expect(consoleRecorder.content).to.contain('Coverage: 100.00%');
Expand Down Expand Up @@ -1982,8 +1979,7 @@ describe('Reporter', () => {

const { code, output } = await Lab.report(script, { reporter: ['console', 'console'], output: [filename, recorder], coverage: true });

expect(code.console).to.equal(0);
expect(code.console2).to.equal(0);
expect(code).to.equal(0);
expect(output.console).to.equal(Fs.readFileSync(filename).toString());
expect(output.console2).to.equal(recorder.content);
Fs.unlinkSync(filename);
Expand Down

0 comments on commit d5c6976

Please sign in to comment.