Hard to get this working from inside a node script #1

Open
ericelliott opened this Issue Mar 28, 2013 · 0 comments

1 participant

@ericelliott

Here's how I hacked it to work:

hookstdout.js:

module.exports = function hookStdout(callback) {
  var oldWrite = process.stdout.write;

  process.stdout.write = (function(write) {
    return function(string, encoding, fd) {
      write.apply(process.stdout, arguments);
      callback(string, encoding, fd);
    }
  })(process.stdout.write);

  return function() {
    process.stdout.write = oldWrite;
  }
};

Then from my test suite:

var finished = require('tap-finished'),
  tapStream = finished(function () {
    process.exit();
  }),
  hookStdout = require('../lib/utils/hookstdout.js');

hookStdout(tapStream.write);

That does the trick.

I also tried creating a test harness and piping the output to tapStream like this:

var test = require('tape');
var harness = test.createHarness();

// ...

server.on('listening', function () {
  harness(function () {
    test.stream.pipe(tapStream);
    all(request, test);
  });
});

That did not work. I didn't bother stepping into it to figure out what was going on, since I already had the work-around at that point, and I was just taking a random shot in the dark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment