Skip to content

Commit

Permalink
Write CLI errors to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
geek committed Feb 9, 2018
1 parent a4e300a commit 0b4c98f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions lib/cli.js
Expand Up @@ -112,12 +112,12 @@ internals.traverse = function (paths, options) {
if (err.code !== 'ENOENT') {
throw err;
}
options.output.write('Could not find test file or directory \'' + nextPath + '\'.\n');
console.error('Could not find test file or directory \'' + nextPath + '\'.\n');
process.exit(1);
}

if (options.pattern && !testFiles.length) {
options.output.write('The pattern provided (-P or --pattern) didn\'t match any files.\n');
console.log('The pattern provided (-P or --pattern) didn\'t match any files.\n');
process.exit(0);
}

Expand All @@ -136,9 +136,9 @@ internals.traverse = function (paths, options) {
require(file);
}
catch (ex) {
options.output.write(`Error requiring file: ${file}\n`);
options.output.write(`${ex.message}\n`);
options.output.write(`${ex.stack}\n`);
console.error(`Error requiring file: ${file}\n`);
console.error(`${ex.message}\n`);
console.error(`${ex.stack}\n`);
return process.exit(1);
}

Expand All @@ -153,7 +153,7 @@ internals.traverse = function (paths, options) {
}
}
else if (global._labScriptRun) {
options.output.write(`The file: ${file} includes a lab script that is not exported via exports.lab\n`);
console.error(`The file: ${file} includes a lab script that is not exported via exports.lab\n`);
return process.exit(1);
}
});
Expand Down
18 changes: 9 additions & 9 deletions test/cli.js
Expand Up @@ -100,9 +100,9 @@ describe('CLI', () => {

const result = await RunCli(['test/cli_error/parse.js']);
expect(result.code).to.equal(1);
expect(result.output).to.contain('Error requiring file');
expect(result.output).to.contain('cli_error/parse_invalid.js:5');
expect(result.output).to.not.contain('UnhandledPromiseRejectionWarning');
expect(result.errorOutput).to.contain('Error requiring file');
expect(result.errorOutput).to.contain('cli_error/parse_invalid.js:5');
expect(result.errorOutput).to.not.contain('UnhandledPromiseRejectionWarning');
});

it('(--bail) exits with code 1 running a directory of tests after one fails', async () => {
Expand Down Expand Up @@ -571,22 +571,22 @@ describe('CLI', () => {
expect(result.output).to.contain('1 tests complete');
});

it('displays error message when a script is detected without an exports.lab', async () => {
it('writes error message to stderr when a script is detected without an exports.lab', async () => {

const result = await RunCli(['test/cli_no_exports/missingExports.js']);

expect(result.errorOutput).to.equal('');
expect(result.output).to.equal('');
expect(result.code).to.equal(1);
expect(result.output).to.contain('includes a lab script that is not exported via exports.lab');
expect(result.errorOutput).to.contain('includes a lab script that is not exported via exports.lab');
});

it('displays error message when a script is missing exports and other scripts contain them', async () => {
it('writes error message to stderr when a script is missing exports and other scripts contain them', async () => {

const result = await RunCli(['test/cli_no_exports/']);

expect(result.errorOutput).to.equal('');
expect(result.output).to.equal('');
expect(result.code).to.equal(1);
expect(result.output).to.contain('includes a lab script that is not exported via exports.lab');
expect(result.errorOutput).to.contain('includes a lab script that is not exported via exports.lab');
});

it('displays error message when an unknown argument is specified', async () => {
Expand Down

0 comments on commit 0b4c98f

Please sign in to comment.