getappmap / appmap-agent-js

This project is deprecated. Please use https://github.com/getappmap/appmap-node/ to record Node.js applications.
Other
28 stars 8 forks source link

Agent exit with 0 on mocha assertion failure #145

Closed lachrist closed 2 years ago

lachrist commented 2 years ago

Mocha exit code is the number of test failures (truncated to 255). So if there is no failures, mocha exits with 0, even on uncaught error. This is a case of clashes between layers. The agent (ie the meta layer) wants to exit with 1. But mocha (the base layer) overwrote the normal behavior and exit with 0 instead. We could directly call process.exit(1) on assertion failures to prevent mocha to overwrite it. But this was removed in https://github.com/getappmap/appmap-agent-js/pull/138 to consistently handle failures by throwing errors. Plus, process.exit is a very crude mechanism and I think it will cause more problems that it will solve.

Exit functions passed here: https://github.com/mochajs/mocha/blob/5bd33a0ba201d227159759e8ced86756595b0c54/bin/_mocha#L637

Exit function called here: https://github.com/mochajs/mocha/blob/5bd33a0ba201d227159759e8ced86756595b0c54/lib/mocha.js#L608