Skip to content

Commit

Permalink
use appropriate log methods for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiemonge committed Mar 17, 2016
1 parent b5f6644 commit b649193
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions test/wiredep_cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,34 @@ describe('wiredep-cli', function () {
});

describe('argument checks', function () {
function runLog (args, errMsg) {
var stub = sinon.stub(console, 'log');
function runLog (args, errMsg, method) {
var stub = sinon.stub(console, method);

reset();
process.argv = ['', ''].concat(args);
require('../wiredep-cli');

assert(stub.calledOnce, 'Console.log was not called');
assert(stub.calledOnce, 'Console.' + method + ' was not called');
assert(stub.calledWithMatch(errMsg), 'Message did not match');
stub.restore();
}

it('should return the version', function () {
var version = require('../package.json').version;
runLog(['-v'], version);
runLog(['--version'], version);
runLog(['-v'], version, 'info');
runLog(['--version'], version, 'info');
});

it('should display help when called with no args or help ones', function () {
[[], ['-h'], ['--help']].forEach(function (arg) {
runLog(arg, /^Wire Bower dependencies to your source code/);
runLog(arg, /^Wire Bower dependencies to your source code/, 'info');
});
});

it('should log when source is not specified', function () {
it('should error when source is not specified', function () {
var msg = /Source file not specified/;
runLog(['-b', 'bower.json'], msg);
runLog(['--bowerJson', 'bower.json'], msg);
runLog(['-b', 'bower.json'], msg, 'error');
runLog(['--bowerJson', 'bower.json'], msg, 'error');
});
});
});
Expand Down
10 changes: 5 additions & 5 deletions wiredep-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ var helpOptionText = Object.keys(options).map(function (key) {


if (argv.version) {
console.log(pkg.version);
console.info(pkg.version);
return;
}

if (argv.help || !Object.keys(argv).length) {
console.log(
console.info(
pkg.description + EOL +
EOL +
'Usage: ' + chalk.cyan('$') + chalk.bold(' wiredep ') +
Expand All @@ -62,7 +62,7 @@ if (argv.help || !Object.keys(argv).length) {
}

if (!argv.src) {
console.log(
console.error(
chalk.bold.red('> Source file not specified.') + EOL +
'Please pass a `--src path/to/source.html` to `wiredep`.'
);
Expand All @@ -80,7 +80,7 @@ try {
fs.statSync(path.normalize('./bower.json'));
}
} catch (e) {
console.log(
console.error(
chalk.bold.red('> bower.json not found.') + EOL +
'Please run `wiredep` from the directory where your `bower.json` file' +
' is located.' + EOL +
Expand All @@ -93,5 +93,5 @@ try {
var results = wiredep(argv);

if (argv.verbose) {
console.log(results);
console.info(results);
}

0 comments on commit b649193

Please sign in to comment.