UNPKG

@amiceli/vitest-cucumber

Version:

vitest tools to use Gherkin feature in unit tests

194 lines (193 loc) 6.59 kB
export class VitestsCucumberError extends Error { constructor(message, name) { super(message); this.stack = ``; this.name = name || this.constructor.name; } } export class NotScenarioOutlineError extends VitestsCucumberError { constructor(scenario) { super(`${scenario.getTitle()} is not a ScenarioOutline`); } } export class IsScenarioOutlineError extends VitestsCucumberError { constructor(scenario) { super(`${scenario.getTitle()} is a ScenarioOutline`); } } export class BackgroundNotCalledError extends VitestsCucumberError { constructor(background) { super(`${background.getTitle()} was not called`); } } export class ScenarioNotCalledError extends VitestsCucumberError { constructor(scenario) { super(`${scenario.getTitle()} was not called`); } } export class ScenarioOutlineVariableNotCalledInStepsError extends VitestsCucumberError { constructor(scenario, variableName) { super(`${scenario.getTitle()} \n ${variableName} was not called in steps`); } } export class ScenarioOulineWithoutExamplesError extends VitestsCucumberError { constructor(scenario) { super(`${scenario.getTitle()} \n has an empty Examples`); } } export class ScenarioOutlineVariablesDeclaredWithoutExamplesError extends VitestsCucumberError { constructor(scenario) { super(`${scenario.getTitle()} \n variables declared without Examples`); } } export class MissingScenarioOutlineVariableValueError extends VitestsCucumberError { constructor(scenario, variableName) { super(`${scenario.getTitle()} \n missing ${variableName} value in Examples`); } } export class FeatureUknowScenarioError extends VitestsCucumberError { constructor(feature, scenario) { super(`${scenario.getTitle()} does not exist in \n ${feature.getTitle()}`); } } export class StepAbleUnknowStepError extends VitestsCucumberError { constructor(stepable, step) { super(`${stepable.getTitle()} \n ${step.type} ${step.details} does not exist`); } } export class StepAbleStepExpressionError extends VitestsCucumberError { constructor(stepable, step) { super([ `No step match with this expression`, ` ${stepable.getTitle()}`, ` ${step.getTitle()} ❌`, ].join(`\n`)); } } export class StepAbleStepsNotCalledError extends VitestsCucumberError { constructor(stepable, step) { super([ ``, ` ${stepable.getTitle()}`, ` ${step.getTitle()} ❌`, ].join(`\n`), `Missing steps in Scenario`); } } // for rules export class RuleNotCalledError extends VitestsCucumberError { constructor(rule) { super(`${rule.getTitle()} was not called`); } } export class FeatureUknowRuleError extends VitestsCucumberError { constructor(feature, rule) { super(`${rule.getTitle()} does not exist in \n Feature: ${feature.name}`); } } export class FeatureFileNotFoundError extends VitestsCucumberError { constructor(path) { super(`feature file ${path} does not exist`); } } export class NotAllowedBackgroundStepTypeError extends VitestsCucumberError { constructor(type) { super(`${type} step is not allowed in Background`); } } export class TwiceBackgroundError extends VitestsCucumberError { constructor() { super(`A background already exist`); } } export class BackgroundNotExistsError extends VitestsCucumberError { constructor(parent) { super(`${parent.getTitle()} has no background`); } } export class OnlyOneFeatureError extends VitestsCucumberError { constructor() { super(`Gherkin rule: only one Feature per file`); } } export class StepExpressionMatchError extends VitestsCucumberError { constructor(step, expression) { super(`${expression} no match with ${step.details}`); } } export class MissingFeature extends VitestsCucumberError { constructor(line) { super([ `Missing Feature before add Scenario, Rule or Background`, ` ${line.trim()} ❌`, ].join('\n')); } } export class MissingSteppableError extends VitestsCucumberError { constructor(line) { super([ `Missing Scenario, ScenarioOutline or Background before add step`, ` ${line.trim()} ❌`, ].join('\n')); } } export class MissingScnearioOutlineError extends VitestsCucumberError { constructor(line) { super([ `Missing ScenarioOutline before add Examples`, ` ${line.trim()} ❌`, ].join('\n')); } } export class MissingExamplesError extends VitestsCucumberError { constructor(line) { super([`Missing Examples before add value`, ` ${line.trim()} ❌`].join('\n')); } } export class SpokenKeywordError extends VitestsCucumberError { constructor(line, keywords) { super([ `No keywords match for: ${line}`, ` Available keywords : ${keywords.join(', ')}`, ].join('\n')); } } export class ParentWithoutScenario extends VitestsCucumberError { constructor(feature) { super(`${feature.getTitle()} must have at least one scenario`); } } export class InvalidUrlParameterError extends VitestsCucumberError { constructor(arg) { super(`String '${arg}' was not recognized as a valid Url`); } } export class InvalidDateParameterError extends VitestsCucumberError { constructor(arg) { super(`String '${arg}' was not recognized as a valid Date`); } } export class InvalidCurrencyParameterError extends VitestsCucumberError { constructor(arg) { super(`String '${arg}' was not recognized as a valid currency`); } } export class BuiltinParameterExpressionAlreadyExistsError extends VitestsCucumberError { constructor(expressionName) { super(`You cannot redefine the built-in expression '${expressionName}'`); } } export class CustomParameterExpressionAlreadyExistsError extends VitestsCucumberError { constructor(expressionName) { super(`The custom expression '${expressionName}' already exists`); } } export class ItemAlreadyExistsError extends VitestsCucumberError { constructor(parent, child) { super(`${parent.getTitle()} already has ${child.getTitle()}`); } } export class RequiredTitleError extends VitestsCucumberError { constructor(line, keyword) { super([`${line} ❌`, ` ${keyword} required a title`].join('\n')); } }