Skip to content

Commit

Permalink
Merge pull request #8418 from elastic/jasper/backport/8396/5.x
Browse files Browse the repository at this point in the history
[backport] PR #8396 to 5.x
  • Loading branch information
ppisljar authored Sep 21, 2016
2 parents 6776cda + f3809d4 commit 64f9f1b
Showing 1 changed file with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,38 @@ export function setupTopLevelDescribeFilter(test) {
let describeCallDepth = 0;
const ignoredCalls = [];

const describeInterceptor = function (describeName, describeBody) {
const context = this;

const isTopLevelCall = describeCallDepth === 0;
const shouldIgnore = isTopLevelCall && Boolean(test(describeName)) === false;
if (shouldIgnore) return;

/**
* we wrap the delegation to mocha in a try/finally block
* to ensure that our describeCallDepth counter stays up
* to date even if the call throws an error.
*
* note that try/finally won't actually catch the error, it
* will continue to propogate up the call stack
*/
let result;
try {
describeCallDepth += 1;
result = originalDescribe.call(context, describeName, describeBody);
} finally {
describeCallDepth -= 1;
}
return result;
};

// to allow describe.only calls. we dont need interceptor as it will call describe internally
describeInterceptor.only = originalDescribe.only;

// ensure that window.describe isn't messed with by other code
Object.defineProperty(window, 'describe', {
configurable: false,
enumerable: true,
value: function describeInterceptor(describeName, describeBody) {
const context = this;

const isTopLevelCall = describeCallDepth === 0;
const shouldIgnore = isTopLevelCall && Boolean(test(describeName)) === false;
if (shouldIgnore) return;

/**
* we wrap the delegation to mocha in a try/finally block
* to ensure that our describeCallDepth counter stays up
* to date even if the call throws an error.
*
* note that try/finally won't actually catch the error, it
* will continue to propogate up the call stack
*/
try {
describeCallDepth += 1;
originalDescribe.call(context, describeName, describeBody);
} finally {
describeCallDepth -= 1;
}
}
value: describeInterceptor
});
}

0 comments on commit 64f9f1b

Please sign in to comment.