busterjs / buster

Abandoned - A powerful suite of automated test tools for JavaScript.
http://docs.busterjs.org
Other
448 stars 37 forks source link

autotest on windows outputs only the first message #374

Closed dwittner closed 10 years ago

dwittner commented 10 years ago

If you run buster-autotest on windows, the last message you will see is "Running tests...", but not the result of the test run.

dwittner commented 10 years ago

The reason for that issue is, that we do a process.exit and the data of stdout and stderr isn't passed to the process of buster-autotest. We do process.exit in two places:

  1. buster-cli.js->exit: process.exit(code || 0);
  2. buster-test:
}).run(process.argv.slice(2), function (err) {
    if (err) { process.exit(1); }
});

The call of 1. and 2. is made in test-cli.js->exit:

    exit: function (exitCode, callback) {
        callback(exitCode); // 2.
        this.cli.exit(exitCode); // 1.
    },

First of all i think we shouldn't do an exit call in case of an exit code 0. Further i don't know, why we need two exit calls. I would like to eliminate one call.

If i comment out the call of 1., changing buster-test the following way fixes the issue:

}).run(process.argv.slice(2), function (err) {
    if (err) { setTimeout(process.exit.bind(null, 1), 5); }
});

I tried out some timeout values. The value 1 doesn't work, but any value greater than 1 works.

My first attempt was to use that function for a safely exit (found here):

function exit(exitCode) {
  if (process.stdout._pendingWriteReqs || process.stderr._pendingWriteReqs) {
    process.nextTick(function() {
      exit(exitCode);
    });
  } else {
    process.exit(exitCode);
  }
}

But that function doesn't fix the issue. I tried some other ways too to find out if stdout and stderr are flushed, but i think that the problem isn't that they are not flushed at the time we do the process.exit, but the data isn't passed to the calling autotest process. Because calling buster-test directly, without the buster-autotest process wrapped around doesn't lead to the issue.

dwittner commented 10 years ago

We will use setTimeout for a safely exit for both places. It is not planned to eliminate one of the exit calls at the moment.

dwittner commented 10 years ago

Fixed by e09bab10ee and b23c6215e0.