allure-jest
Version:
Allure Jest integration
52 lines (48 loc) • 2.06 kB
JavaScript
/**
* Returns array of names which represents full test hierarchy
* Omits ROOT_DESCRIBE_BLOCK because it shouldn't be reported
*
* @param test Test or describe block
* @returns
*/
export var getTestPath = test => {
var path = [];
var currentUnit = test;
while (currentUnit) {
if (currentUnit.name) {
path.unshift(currentUnit.name);
}
currentUnit = currentUnit.parent;
}
// debugger
// first element is always ROOT_DESCRIBE_BLOCK, which shouldn't be reported
return path.slice(1);
};
/**
* Returns starndartized test name what can be used as test Id
*
* @see https://github.com/jestjs/jest/blob/25a8785584c9d54a05887001ee7f498d489a5441/packages/jest-circus/src/utils.ts#L410
* @param path Path memebers
* @returns
*/
export var getTestId = path => path.join(" ");
/**
* Returns test full name (test hierarchy joined by " > ")
*
* @param path Path memebers
* @returns
*/
export var getTestFullName = path => path.join(" > ");
var jestHookPattern = /^at jestAdapter/i;
// A slightly different reference should be used to identify jestAdapter's global hook in some older versions of Jest.
var jestHookLegacyPattern = /jest-circus\/build\/legacy-code-todo-rewrite\/jestAdapter.js:\d+:\d+$/;
export var shouldHookBeSkipped = hook => {
var _stack$split;
// In older versions of Jest the hook's stack is direcrly in asyncError. In newer ones - in asyncError.stack.
var stackOrError = hook === null || hook === void 0 ? void 0 : hook.asyncError;
var stack = typeof stackOrError === "string" ? stackOrError : stackOrError === null || stackOrError === void 0 ? void 0 : stackOrError.stack;
var errorFirstLine = (stack === null || stack === void 0 || (_stack$split = stack.split("\n")) === null || _stack$split === void 0 || (_stack$split = _stack$split[1]) === null || _stack$split === void 0 ? void 0 : _stack$split.trim()) || "";
return jestHookPattern.test(errorFirstLine) || jestHookLegacyPattern.test(errorFirstLine);
};
export var last = array => array[array.length - 1];
//# sourceMappingURL=utils.js.map