Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests and fixes for evented exec.

  • Loading branch information...
commit 239978928927b771d8da46d7167488663a343869 1 parent 541d8e9
mde authored
Showing with 38 additions and 0 deletions.
  1. +1 −0  lib/utils/index.js
  2. +37 −0 tests/exec.js
View
1  lib/utils/index.js
@@ -224,6 +224,7 @@ utils.mixin(Exec.prototype, new (function () {
, next = this._cmds.shift()
, config = this._config
, errData = '';
+
// Keep running as long as there are commands in the array
if (next) {
this.emit('cmdStart', next);
View
37 tests/exec.js
@@ -64,6 +64,43 @@ var tests = new (function () {
h.next();
};
+ this.testPipe = function () {
+ var ex = jake.createExec('ls', function () {})
+ , data
+ , appended = false;
+
+ ex.addListener('stdout', function (d) {
+ data += h.trim(d.toString());
+ });
+
+ // After the first command ends, get the accumulated result,
+ // and use it to build a new command to append to the queue.
+ // Grep through the result for files that end in .js
+ ex.addListener('cmdEnd', function () {
+ // Only append after the first cmd, avoid infinite loop
+ if (appended) {
+ return;
+ }
+ appended = true;
+ // Take the original output and build the new command
+ ex.append('echo "' + data + '" | grep "\\.js$"');
+ // Clear out data
+ data = '';
+ });
+
+ // And the end, the stdout data has been cleared once, and the new
+ // data should be the result of the second command
+ ex.addListener('end', function () {
+ // Should be a list of files ending in .js
+ data = data.split('\n');
+ data.forEach(function (d) {
+ assert.ok(/\.js$/.test(d));
+ });
+ });
+ ex.run();
+ h.next();
+ };
+
})();
h.run(tests, function () {
Please sign in to comment.
Something went wrong with that request. Please try again.