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

ericelliott opened this Issue Mar 28, 2013 · 0 comments

1 participant


Here's how I hacked it to work:


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);

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

Then from my test suite:

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


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 () {
    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