jest-metadata
Version:
🦸♂️ Superhero power for your Jest reporters! 🦸♀️
69 lines • 3.12 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MetadataFactoryImpl = void 0;
const tslib_1 = require("tslib");
const checker_1 = require("../checker");
const containers_1 = require("../containers");
const ids_1 = require("../ids");
const selector_1 = require("../selector");
const symbols = tslib_1.__importStar(require("../symbols"));
class MetadataFactoryImpl {
metadataRegistry;
emitter;
#checker = new checker_1.InstanceOfMetadataChecker({
GlobalMetadata: containers_1.GlobalMetadata,
DescribeBlockMetadata: containers_1.DescribeBlockMetadata,
HookDefinitionMetadata: containers_1.HookDefinitionMetadata,
HookInvocationMetadata: containers_1.HookInvocationMetadata,
TestFileMetadata: containers_1.TestFileMetadata,
TestEntryMetadata: containers_1.TestEntryMetadata,
TestFnInvocationMetadata: containers_1.TestFnInvocationMetadata,
TestInvocationMetadata: containers_1.TestInvocationMetadata,
});
#context;
constructor(metadataRegistry, emitter) {
this.metadataRegistry = metadataRegistry;
this.emitter = emitter;
this.#context = {
factory: this,
checker: this.#checker,
emitter: this.emitter,
createMetadataSelector: (fn) => new selector_1.MetadataSelectorImpl(this.#checker, fn),
};
}
get checker() {
return this.#checker;
}
createGlobalMetadata() {
const id = ids_1.AggregatedIdentifier.global('globalMetadata');
return this._register(new containers_1.GlobalMetadata(this.#context, id));
}
createDescribeBlockMetadata(parent, id) {
return this._register(new containers_1.DescribeBlockMetadata(this.#context, parent, id));
}
createHookDefinitionMetadata(owner, id, hookType) {
return this._register(new containers_1.HookDefinitionMetadata(this.#context, owner, id, hookType));
}
createHookInvocationMetadata(hookDefinition, parent, id) {
return this._register(new containers_1.HookInvocationMetadata(this.#context, hookDefinition, parent, id));
}
createTestFileMetadata(testFilePath, globalMetadata) {
const testFileId = new ids_1.AggregatedIdentifier(testFilePath, '');
return this._register(new containers_1.TestFileMetadata(this.#context, testFileId, globalMetadata));
}
createTestEntryMetadata(describeBlock, id) {
return this._register(new containers_1.TestEntryMetadata(this.#context, describeBlock, id));
}
createTestFnInvocationMetadata(testInvocation, id) {
return this._register(new containers_1.TestFnInvocationMetadata(this.#context, testInvocation, id));
}
createTestInvocationMetadata(testEntry, id) {
return this._register(new containers_1.TestInvocationMetadata(this.#context, testEntry, id));
}
_register(metadata) {
this.metadataRegistry.register(metadata[symbols.id], metadata);
return metadata;
}
}
exports.MetadataFactoryImpl = MetadataFactoryImpl;
//# sourceMappingURL=MetadataFactoryImpl.js.map