-
Notifications
You must be signed in to change notification settings - Fork 0
Description
I've been finding mock-cli super useful for my current small project. However, I noticed that because it catches process.exit(), it doesn't stop execution of the code, and while at that point mock-cli will stop doing its work, the code in question won't, and in my case trigger another sanity check that will kill the process and my tests...
Here's an example of the issue:
// test.js
const mockCLI = require('mock-cli');
mockCLI(process.argv, { stdout: process.stdout, stderr: process.stderr });
require('./tested');
console.log("This should print.");// tested.js
console.log("Killing process.")
process.exit(1);
console.log("Killing process again.")
process.exit(1);When running node test it will output the following:
▼ Start of CLI capture ▼
Killing process.
▲ End of CLI capture ▲
Killing process again.The workaround was to add a throw statement right after the process.exit() line, which doesn't seem very elegant to do as its evidently only for the mock testing. I wonder if there's a way to fix this without making a mess of the simplicity with which this utility works. I don't really know the innards of Node well enough to speculate at this point...