Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
fix(cli): error handling for ENOENT is fixed
Browse files Browse the repository at this point in the history
It should warn the correct unfound file names. Also it should continue if one file cannot be found. Tests are added for these
  • Loading branch information
stevemao committed Mar 7, 2015
1 parent 056f582 commit dcdc036
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
8 changes: 6 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ forEach(cli.input, function(arg) {
var length = filePaths.length;

function processFile(fileIndex) {
fs.createReadStream(filePaths[fileIndex])
var filePath = filePaths[fileIndex];
fs.createReadStream(filePath)
.on('error', function(err) {
console.log('Failed to read file ' + filePaths[0] + '\n' + err);
console.warn('Failed to read file ' + filePath + '\n' + err);
if(++fileIndex < length) {
processFile(fileIndex);
}
})
.pipe(split(separator))
.pipe(conventionalCommitsParser(cli.flags))
Expand Down
19 changes: 14 additions & 5 deletions test/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ var spawn = require('child_process').spawn;
var concat = require('concat-stream');

var cliPath = './cli.js';
var output1 = readFileSync('test/expected/output1.txt', 'utf-8');
var output2 = readFileSync('test/expected/output2.txt', 'utf-8');

describe('cli', function() {
it('should parse commits in a file', function(done) {
var cp = spawn(cliPath, ['test/fixtures/log.txt']);

cp.stdout
.pipe(concat(function(chunk) {
var expected = readFileSync('test/expected/output1.txt', 'utf-8');

expect(chunk.toString()).to.equal(expected);
expect(chunk.toString()).to.equal(output1);
done();
}));
});
Expand All @@ -24,9 +25,8 @@ describe('cli', function() {

cp.stdout
.pipe(concat(function(chunk) {
var expected = readFileSync('test/expected/output2.txt', 'utf-8');

expect(chunk.toString()).to.equal(expected);
expect(chunk.toString()).to.equal(output2);
done();
}));
});
Expand All @@ -36,10 +36,19 @@ describe('cli', function() {

cp.stdout
.pipe(concat(function(chunk) {
var expected = readFileSync('test/expected/output_both.txt', 'utf-8');
var expected = output1 + output2;

expect(chunk.toString()).to.equal(expected);
done();
}));
});

it('should error if files cannot be found', function(done) {
var cp = spawn(cliPath, ['test/fixtures/log.txt', 'test/fixtures/log3.txt', 'test/fixtures/log2.txt', 'test/fixtures/log4.txt', '===']);
cp.stderr
.pipe(concat(function(chunk) {
expect(chunk.toString()).to.equal('Failed to read file test/fixtures/log3.txt\nError: ENOENT, open \'test/fixtures/log3.txt\'\nFailed to read file test/fixtures/log4.txt\nError: ENOENT, open \'test/fixtures/log4.txt\'\n');
done();
}));
});
});
8 changes: 0 additions & 8 deletions test/expected/output_both.txt

This file was deleted.

0 comments on commit dcdc036

Please sign in to comment.