mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Backport PR #8396
--------- **Commit 1:** fixing top_level_describe_filter to allow describe.only in unit tests * Original sha:14817199a7
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-21T08:12:41Z **Commit 2:** adding comment * Original sha:65edc94a23
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-21T14:05:32Z
This commit is contained in:
parent
a2b7a46f8d
commit
1214092b77
1 changed files with 29 additions and 22 deletions
|
@ -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
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue