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

Commit

Permalink
test(cli): fix test on iojs
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Mar 7, 2015
1 parent c8badb0 commit 436c8f8
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions test/cli.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
var concat = require('concat-stream');
var expect = require('chai').expect;
var readFileSync = require('fs').readFileSync;
var spawn = require('child_process').spawn;
var concat = require('concat-stream');
var through = require('through2');

var cliPath = './cli.js';
var output1 = readFileSync('test/expected/output1.txt', 'utf-8');
Expand All @@ -11,43 +12,45 @@ 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) {

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

it('should work with a separator', function(done) {
var cp = spawn(cliPath, ['test/fixtures/log2.txt', '===']);

cp.stdout
.pipe(concat(function(chunk) {

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

it('should work with two files', function(done) {
var cp = spawn(cliPath, ['test/fixtures/log.txt', 'test/fixtures/log2.txt', '===']);

cp.stdout
.pipe(concat(function(chunk) {
var expected = output1 + output2;

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

it('should error if files cannot be found', function(done) {
var i = 0;
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');
.pipe(through(function(chunk, enc, cb) {
if (i === 0) {
expect(chunk.toString()).to.contain('Failed to read file test/fixtures/log3.txt');
} else {
expect(chunk.toString()).to.contain('Failed to read file test/fixtures/log4.txt');
}
i++;
cb();
}, function() {
done();
}));
});
Expand Down

0 comments on commit 436c8f8

Please sign in to comment.