Skip to content

Commit

Permalink
feat: Write data to process.stdout and process.stderr for debug
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore committed May 23, 2015
1 parent 960eb40 commit 0459696
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ Write data to stdin, see example above.

Callback will be called after completing the assertion, the first argument is Error if throw exception.

#### coffee.debug()

Write data to process.stdout and process.stderr for debug

## LISENCE

Copyright (c) 2015 popomore. Licensed under the MIT license.
8 changes: 8 additions & 0 deletions lib/coffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ function Coffee(opt) {
this.restore();
}

Coffee.prototype.debug = function() {
this._debug = true;
return this;
};

// Only accept these type below for assertion
var acceptType = ['stdout', 'stderr', 'code'];
Coffee.prototype.expect = function(type, value) {
Expand Down Expand Up @@ -45,12 +50,14 @@ Coffee.prototype.end = function(cb) {
cmd.stdout &&
cmd.stdout.on('data', function(buf) {
debug('output stdout `%s`', show(buf));
self._debug && process.stdout.write(buf);
self.stdout += buf;
});

cmd.stderr &&
cmd.stderr.on('data', function(buf) {
debug('output stderr `%s`', show(buf));
self._debug && process.stderr.write(buf);
self.stderr += buf;
});

Expand Down Expand Up @@ -100,6 +107,7 @@ Coffee.prototype.restore = function() {
};
this.complete = false;
this._isEndCalled = false;
this._debug = false;
return this;
};

Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,6 @@ function run(type) {

function call(filepath) {
filepath += type === 'fork' ? '.js' : '.sh';
return coffee[type](path.join(__dirname, 'fixtures/' + filepath));
return coffee[type](path.join(__dirname, 'fixtures/' + filepath)).debug();
}
}

0 comments on commit 0459696

Please sign in to comment.