ava icon indicating copy to clipboard operation
ava copied to clipboard

Override `process.exit` to give some context when it's called unexpectedly in a test.

Open jamestalmage opened this issue 9 years ago • 4 comments

Issuehunt badges

Just had an issue on Gitter where a users code was causing process.exit(1) to be called. He got the "test.js exited with a non-zero exit code message", but there was no helpful information.

I say we try and capture that somehow:

var oldExit = process.exit;
process.exit = function (code) {
  if (code > 0) {
    var stack = new Error().stack;
    // log it? send it to parent?
    // ...
  }
  oldExit.apply(process, arguments);
};

There is a $60.00 open bounty on this issue. Add more on Issuehunt.

jamestalmage avatar May 23 '16 22:05 jamestalmage

Shouldn't we log no matter what the code is? People should not be calling process.exit() in tests at all.

sindresorhus avatar May 24 '16 05:05 sindresorhus

Oh, yeah. That's definitely true

jamestalmage avatar May 24 '16 05:05 jamestalmage

I brought this up on Gitter, what tripped me up was a function that checks that all the needed dependencies are installed exits with 1 if one is missing, which means it will exit with 1 on Travis but not locally, and I didn't think of this. However, as you mentioned, it shouldn't run in tests so I've fixed it by now. So yeah, it was a case of PEBCAK.

sondr3 avatar May 29 '16 13:05 sondr3

@issuehunt has funded $60.00 to this issue.


IssueHuntBot avatar May 15 '19 05:05 IssueHuntBot