jest-metadata
Version:
🦸♂️ Superhero power for your Jest reporters! 🦸♀️
153 lines • 5.01 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MetadataSelectorImpl = void 0;
class MetadataSelectorImpl {
check;
value;
constructor(check, value) {
this.check = check;
this.value = value;
}
get file() {
const metadata = this.value();
if (this.check.isTestFileMetadata(metadata)) {
return metadata;
}
if (this.check.isDescribeBlockMetadata(metadata)) {
return metadata.file;
}
if (this.check.isTestEntryMetadata(metadata)) {
return metadata.describeBlock.file;
}
if (this.check.isHookDefinitionMetadata(metadata)) {
return metadata.describeBlock.file;
}
if (this.check.isHookInvocationMetadata(metadata)) {
return metadata.definition.describeBlock.file;
}
if (this.check.isTestInvocationMetadata(metadata)) {
return metadata.definition.describeBlock.file;
}
if (this.check.isTestFnInvocationMetadata(metadata)) {
return metadata.test.definition.describeBlock.file;
}
return;
}
get describeBlock() {
const metadata = this.value();
if (this.check.isDescribeBlockMetadata(metadata)) {
return metadata;
}
if (this.check.isHookDefinitionMetadata(metadata)) {
return metadata.describeBlock;
}
if (this.check.isHookInvocationMetadata(metadata)) {
return metadata.definition.describeBlock;
}
if (this.check.isTestEntryMetadata(metadata)) {
return metadata.describeBlock;
}
if (this.check.isTestInvocationMetadata(metadata)) {
return metadata.definition.describeBlock;
}
if (this.check.isTestFnInvocationMetadata(metadata)) {
return metadata.test.definition.describeBlock;
}
return;
}
get testEntry() {
const metadata = this.value();
if (this.check.isTestEntryMetadata(metadata)) {
return metadata;
}
if (this.check.isTestInvocationMetadata(metadata)) {
return metadata.definition;
}
if (this.check.isHookInvocationMetadata(metadata) &&
this.check.isTestEntryMetadata(metadata.definition.describeBlock)) {
return metadata.definition.describeBlock;
}
if (this.check.isTestFnInvocationMetadata(metadata)) {
return metadata.test.definition;
}
return;
}
get hookDefinition() {
const metadata = this.value();
if (this.check.isHookDefinitionMetadata(metadata)) {
return metadata;
}
if (this.check.isHookInvocationMetadata(metadata)) {
return metadata.definition;
}
return;
}
get definition() {
return this.hookDefinition ?? this.testEntry ?? this.describeBlock;
}
get testFnInvocation() {
const metadata = this.value();
if (this.check.isTestFnInvocationMetadata(metadata)) {
return metadata;
}
return;
}
get hookInvocation() {
const metadata = this.value();
if (this.check.isHookInvocationMetadata(metadata)) {
return metadata;
}
return;
}
get testInvocation() {
const metadata = this.value();
if (this.check.isTestInvocationMetadata(metadata)) {
return metadata;
}
if (this.check.isTestFnInvocationMetadata(metadata)) {
return metadata.test;
}
if (this.check.isHookInvocationMetadata(metadata) &&
this.check.isTestInvocationMetadata(metadata.parent)) {
return metadata.parent;
}
return;
}
get invocationParent() {
const metadata = this.value();
if (this.check.isDescribeBlockMetadata(metadata)) {
return metadata;
}
if (this.check.isHookInvocationMetadata(metadata)) {
return metadata.parent;
}
if (this.check.isTestFnInvocationMetadata(metadata)) {
return metadata.test;
}
if (this.check.isTestInvocationMetadata(metadata)) {
return metadata;
}
return;
}
get invocation() {
const metadata = this.value();
if (this.check.isTestFileMetadata(metadata)) {
return metadata;
}
if (this.check.isDescribeBlockMetadata(metadata)) {
return metadata;
}
if (this.check.isHookInvocationMetadata(metadata)) {
return metadata;
}
if (this.check.isTestInvocationMetadata(metadata)) {
return metadata;
}
if (this.check.isTestFnInvocationMetadata(metadata)) {
return metadata;
}
return;
}
}
exports.MetadataSelectorImpl = MetadataSelectorImpl;
//# sourceMappingURL=MetadataSelectorImpl.js.map