Merge pull request #8419 from elastic/jasper/backport/8396/5.0

[backport] PR #8396 to 5.0
This commit is contained in:
Peter Pisljar 2016-09-21 21:43:18 +02:00 committed by GitHub
commit 761bb9ffc5

View file

@ -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
});
}