Skip to content

Commit

Permalink
Ensures errors in stdoutEqual callback are logged
Browse files Browse the repository at this point in the history
Since stdout is redirected while the callback is executed, any errors the callback throws are suppressed and never logged. This unhooks `process.stdout.write` after catching an error in `callback()` and re-throws it so it will be logged.
  • Loading branch information
raddevon authored Nov 9, 2017
1 parent 2d237ee commit 7a6fec4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/jshint_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ var stdoutEqual = function(callback, done) {
}
});
// Execute the logging code to be tested.
callback();
try {
callback();
} catch (error) {
hooker.unhook(process.stdout, 'write');
throw error;
}
// Restore process.stdout.write to its original value.
hooker.unhook(process.stdout, 'write');
// Actually test the actually-logged stdout string to the expected value.
Expand Down

0 comments on commit 7a6fec4

Please sign in to comment.