UNPKG

jest-metadata

Version:

🦸‍♂️ Superhero power for your Jest reporters! 🦸‍♀️

41 lines 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GlobalMetadataRegistry = void 0; const utils_1 = require("../../utils"); const ScopedMetadataRegistry_1 = require("./ScopedMetadataRegistry"); class GlobalMetadataRegistry { emitter = new utils_1.SerialEmitter('globalMetadataRegistry'); scopes = {}; root = new ScopedMetadataRegistry_1.ScopedMetadataRegistry('globalMetadata'); get events() { return this.emitter; } get(scopedId) { const { testFilePath, identifier } = scopedId; const registry = testFilePath ? this.scopes[testFilePath] : this.root; if (!registry) { throw new Error(`No metadata registry found for: ${testFilePath}`); } return registry.get(identifier); } register(scopedId, metadata) { this.emitter.emit({ type: 'register_metadata', metadata }); const { testFilePath, identifier } = scopedId; if (!testFilePath) { return this.root.register(identifier, metadata); } if (!this.scopes[testFilePath]) { this.scopes[testFilePath] = new ScopedMetadataRegistry_1.ScopedMetadataRegistry(testFilePath); } const registry = this.scopes[testFilePath]; registry.register(identifier, metadata); } *all() { yield* this.root.all(); for (const registry of Object.values(this.scopes)) { yield* registry.all(); } } } exports.GlobalMetadataRegistry = GlobalMetadataRegistry; //# sourceMappingURL=GlobalMetadataRegistry.js.map