UNPKG

gauge-ts

Version:
98 lines (97 loc) 2.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StepRegistry = void 0; const node_assert_1 = require("node:assert"); class StepRegistry { _registry; _continueOnFailureFunctions; constructor() { this._registry = new Map(); this._continueOnFailureFunctions = new Map(); } get(text) { return this._registry.get(text)[0]; } isImplemented(text) { return this._registry.has(text); } hasMultipleImplementations(stepText) { return (this._registry.has(stepText) && this._registry.get(stepText).length > 1); } add(text, entry) { if (this._registry.has(text)) { this._registry.get(text).push(entry); } else { this._registry.set(text, [entry]); } } addContinueOnFailure(func, exceptions) { this._continueOnFailureFunctions.set(func, exceptions || [node_assert_1.AssertionError.name]); } getContinueOnFailureFunctions(func) { if (this._continueOnFailureFunctions.has(func)) { return this._continueOnFailureFunctions.get(func); } return []; } getStepPositions(filePath) { const positions = []; this._registry.forEach((entries, step) => { for (const entry of entries) { if (entry.getFilePath() === filePath) { positions.push({ stepValue: step, span: entry.getRange(), }); } } }); return positions; } getStepTexts() { let steps = []; for (const v of this._registry.values()) { steps = steps.concat(v[0].getStepText()); } return steps; } isFileCached(filePath) { for (const kv of this._registry) { if (kv[1].some((i) => i.getFilePath() === filePath)) { return true; } } return false; } removeSteps(filePath) { const newReg = new Map(); this._registry.forEach((entries, stepValue) => { const methods = entries.filter((entry) => entry.getFilePath() !== filePath); if (methods.length > 0) { newReg.set(stepValue, methods); } }); this._registry = newReg; } setInstanceForMethodsIn(file, instance) { for (const entries of this._registry.values()) { for (const entry of entries) { if (entry.getFilePath() === file) { entry.setInstance(instance); } } } } clear() { this._registry.clear(); this._continueOnFailureFunctions.clear(); } } exports.StepRegistry = StepRegistry; if (!global.gaugeStepRegistry) { global.gaugeStepRegistry = new StepRegistry(); } const registry = global.gaugeStepRegistry; exports.default = registry;