avajs / ava

Node.js test runner that lets you develop with confidence 🚀
MIT License
20.74k stars 1.41k forks source link

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

Closed jamestalmage closed 2 years ago

jamestalmage commented 8 years ago

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.

sindresorhus commented 8 years ago

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

jamestalmage commented 8 years ago

Oh, yeah. That's definitely true

sondr3 commented 8 years ago

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.

IssueHuntBot commented 5 years ago

@issuehunt has funded $60.00 to this issue.