jest-allure2-reporter
Version:
Idiomatic Jest reporter for Allure Framework
70 lines • 3.76 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MetadataSelector = void 0;
const utils_1 = require("../../utils");
class MetadataSelector {
_options;
constructor(_options) {
this._options = _options;
this.belowTestInvocation = (0, utils_1.weakMemoize)(this.belowTestInvocation.bind(this));
this.testInvocationAndBelow = (0, utils_1.weakMemoize)(this.testInvocationAndBelow.bind(this));
this.testInvocationAndBelowDirect = (0, utils_1.weakMemoize)(this.testInvocationAndBelowDirect.bind(this));
this.testDefinitionAndBelow = (0, utils_1.weakMemoize)(this.testDefinitionAndBelow.bind(this));
}
_getDocblock = (metadata) => metadata ? this._options.getDocblock(metadata) : undefined;
_getMetadataUnsafe = (metadata) => metadata ? this._options.getMetadata(metadata) : undefined;
getMetadataWithDocblock = (metadata) => this._options.mergeUnsafe(this._options.mergeUnsafe(this._options.empty(), this._getDocblock(metadata)), this._getMetadataUnsafe(metadata));
_describeAncestors = (0, utils_1.weakMemoize)((metadata) => metadata
? this._options.mergeUnsafe(this._describeAncestors(metadata.parent), this._getMetadataUnsafe(metadata))
: this._options.empty());
_ancestors(metadata) {
return this.merge(this.globalAndTestFile(metadata.file), this._describeAncestors(metadata.definition.describeBlock));
}
_hookMetadata = (metadata) => {
const definitionMetadata = this.getMetadataWithDocblock(metadata.definition);
return this.merge(definitionMetadata, this._getMetadataUnsafe(metadata));
};
merge = (a, b) => this._options.mergeUnsafe(this._options.mergeUnsafe(this._options.empty(), a), b);
testInvocation(metadata) {
return this.getMetadataWithDocblock(metadata);
}
testDefinition(metadata) {
return this.getMetadataWithDocblock(metadata.definition);
}
belowTestInvocation(metadata) {
return [...metadata.allInvocations()]
.map(this._getMetadataUnsafe)
.reduce(this._options.mergeUnsafe, this._options.empty());
}
testInvocationAndBelow(metadata) {
return this.merge(this.testInvocation(metadata), this.belowTestInvocation(metadata));
}
testInvocationAndBelowDirect(metadata) {
return this.merge(this.testInvocation(metadata), this.getMetadataWithDocblock(metadata.fn));
}
testDefinitionAndBelow(metadata) {
return this.merge(this.testDefinition(metadata), this.testInvocationAndBelow(metadata));
}
testDefinitionAndBelowDirect(metadata) {
return this.merge(this.testDefinition(metadata), this.testInvocationAndBelowDirect(metadata));
}
testVertical(metadata) {
const ancestors = this._ancestors(metadata);
const test_definition_and_below = this.testDefinitionAndBelow(metadata);
return this.merge(ancestors, test_definition_and_below);
}
steps(metadata) {
const before = [...metadata.beforeAll, ...metadata.beforeEach].map(this._hookMetadata);
const after = [...metadata.afterEach, ...metadata.afterAll].map(this._hookMetadata);
const testFunctionSteps = (metadata.fn && this.getMetadataWithDocblock(metadata.fn).steps) || [];
return [...before, ...testFunctionSteps, ...after];
}
globalAndTestFile(metadata) {
return this.merge(this._getMetadataUnsafe(metadata.globalMetadata), this.getMetadataWithDocblock(metadata));
}
globalAndTestFileAndTestInvocation(metadata) {
return this.merge(this.globalAndTestFile(metadata.file), this._getMetadataUnsafe(metadata));
}
}
exports.MetadataSelector = MetadataSelector;
//# sourceMappingURL=MetadataSelector.js.map