Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: footgun protective boots. #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/unexpectedMitm.js
Original file line number Diff line number Diff line change
@@ -829,9 +829,20 @@ module.exports = {
.addAssertion('<any> with http mocked out [and verified] [with extra info] <array|object> <assertion>', function (expect, subject, requestDescriptions) { // ...
expect.errorMode = 'nested';
var mitm = createMitm();
var cleanedUpMitm = false;
var shouldBeVerified = checkEnvFlag('UNEXPECTED_MITM_VERIFY') || expect.flags['and verified'];
var shouldReturnExtraInfo = expect.flags['with extra info'];

// XXX: Register footgun detection in case an uncaught exception
// breaks the test in such a way that our finally block will not
// be called, and mitm thus will not be cleaned up.
afterEach(function () {
if (!cleanedUpMitm) {
cleanedUpMitm = true;
mitm.disable();
}
});

if (!Array.isArray(requestDescriptions)) {
if (typeof requestDescriptions === 'undefined') {
requestDescriptions = [];
@@ -1120,6 +1131,7 @@ module.exports = {
}
});
}).finally(function () {
cleanedUpMitm = true;
mitm.disable();
});