@amiceli/vitest-cucumber
Version:
vitest tools to use Gherkin feature in unit tests
200 lines (181 loc) • 7.17 kB
text/typescript
import { TaskContext } from 'vitest';
declare enum StepTypes {
THEN = "Then",
AND = "And",
WHEN = "When",
GIVEN = "Given",
BUT = "But"
}
type StepDataTanle = {
[key: string]: string;
}[];
declare class Step {
readonly type: StepTypes;
readonly details: string;
docStrings: string | null;
isCalled: boolean;
dataTables: StepDataTanle;
readonly title: string;
constructor(type: StepTypes, details: string, title?: string);
getTitle(): string;
setDocStrings(docStrings: string): void;
}
type TagFilterItem = string | string[];
type TagFilters = {
includeTags: TagFilterItem[];
excludeTags: TagFilterItem[];
};
type VitestCucumberOptions = {
language?: string;
includeTags?: TagFilterItem[];
excludeTags?: TagFilterItem[];
onStepError?: (args: {
error: Error;
ctx: TaskContext;
step: Step;
}) => void;
};
declare const setVitestCucumberConfiguration: (options: VitestCucumberOptions) => void;
declare abstract class Taggable {
tags: Set<string>;
/**
* Simple matching filter mostly following the cucumber expression tag rules,
* e.g. `[["alpha", "beta"], "vitests", "another"]`
* will be equivalent to:
* (`@alpha` and `@beta`) or `@vitests` or `@another`
*/
matchTags(filterItems: TagFilterItem[]): boolean;
shouldBeCalled(options: TagFilters): boolean;
}
declare abstract class StepAble extends Taggable {
abstract getTitle(): string;
isCalled: boolean;
private readonly _steps;
protected readonly title: string;
constructor(title: string);
stepFailedExpressionMatch: {
[key: string]: number;
};
findStepByTypeAndDetails(type: string, details: string): Step | undefined;
hasUnCalledSteps(): boolean;
getNoCalledStep(): Step | undefined;
addStep(newStep: Step): void;
checkIfStepWasCalled(): void;
checkIfStepExists(stepType: string, stepDetails: string): Step;
get lastStep(): Step;
get steps(): Readonly<Step[]>;
}
declare class Background extends StepAble {
constructor(title?: string);
getTitle(): string;
addStep(step: Step): void;
}
declare class Scenario extends StepAble {
description: string;
constructor(description: string, title?: string);
getTitle(): string;
}
type Example = {
[key: string]: any;
}[];
declare class ScenarioOutline extends Scenario {
examples: Example;
missingExamplesKeyword: boolean;
constructor(description: string, title?: string);
getStepTitle(step: Step, example: Example[0]): string;
getStepDocStrings(step: Step, example: Example[0]): string | null;
}
declare abstract class ScenarioParent extends Taggable {
readonly name: string;
private readonly _scenarii;
background: Background | null;
protected readonly title: string;
protected constructor(name: string, title: string);
addScenario(newScenario: Scenario | ScenarioOutline): void;
getScenarioByName(name: string): Scenario | ScenarioOutline | undefined;
getScenarioExample(name: string): Example | null;
getFirstNotCalledScenario(options: RequiredDescribeFeatureOptions): Scenario | ScenarioOutline | undefined;
haveAlreadyCalledScenario(): boolean;
getTitle(): string;
checkUncalledScenario(options: RequiredDescribeFeatureOptions): this;
checkUncalledBackground(options: RequiredDescribeFeatureOptions): this;
getBackground(): Background;
private checkIfScenarioExists;
private scenarioShouldNotBeOutline;
private scenarioShouldBeOutline;
getScenario(description: string): Scenario;
getScenarioOutline(description: string): ScenarioOutline;
mustHaveScenario(): void;
get hasScenarioOutline(): boolean;
get hasScenario(): boolean;
get scenarii(): Readonly<Scenario[]>;
}
declare class Rule extends ScenarioParent {
isCalled: boolean;
constructor(name: string, title?: string);
}
declare class Feature extends ScenarioParent {
private readonly _rules;
constructor(name: string, title?: string);
getRuleByName(name: string): Rule | undefined;
getFirstRuleNotCalled(options: RequiredDescribeFeatureOptions): Rule | undefined;
haveAlreadyCalledRule(): boolean;
checkUncalledRule(options: RequiredDescribeFeatureOptions): this;
checkIfRuleExists(ruleName: string): Rule;
mustHaveScenarioOrRules(): void;
addRule(newRule: Rule): void;
get rules(): Readonly<Rule[]>;
}
type MaybePromise<T = void> = T | Promise<T>;
type CallbackWithSingleContext = (context: TaskContext) => MaybePromise;
type CallbackWithParamsAndContext<T = any> = (ctx: TaskContext, ...params: T[]) => MaybePromise;
type StepCallbackDefinition = (name: string, fn: CallbackWithSingleContext | CallbackWithParamsAndContext) => void;
type StepTest = {
Given: StepCallbackDefinition;
When: StepCallbackDefinition;
But: StepCallbackDefinition;
And: StepCallbackDefinition;
Then: StepCallbackDefinition;
};
type FeatureDescriibeCallbackParams = {
Background: BackgroundTest;
Scenario: ScenarioTest;
ScenarioOutline: ScenarioOutlineTest;
BeforeAllScenarios: (fn: () => MaybePromise) => void;
AfterAllScenarios: (fn: () => MaybePromise) => void;
BeforeEachScenario: (fn: () => MaybePromise) => void;
AfterEachScenario: (fn: () => MaybePromise) => void;
Rule: RuleTest;
};
type DescribeFeatureCallback = (scenarioCallback: FeatureDescriibeCallbackParams) => void;
type RuleOptions = {
RuleBackground: BackgroundTest;
RuleScenario: ScenarioTest;
RuleScenarioOutline: ScenarioOutlineTest;
};
type RuleTest = (ruleName: string, fn: (options: RuleOptions) => void) => void;
type ScenarioTest = (scenarioDescription: string, fn: (options: StepTest) => MaybePromise) => void;
type ScenarioOutlineTest = (scenarioDescription: string, fn: (options: StepTest, examples: Example[0]) => MaybePromise) => void;
type BackgroundStepTest = Pick<StepTest, 'Given' | 'And'>;
type BackgroundTest = (fn: (options: BackgroundStepTest) => MaybePromise) => void;
type DescribeFeatureOptions = Pick<VitestCucumberOptions, 'includeTags' | 'excludeTags'>;
type RequiredDescribeFeatureOptions = Required<DescribeFeatureOptions>;
declare function describeFeature(feature: Feature, describeFeatureCallback: DescribeFeatureCallback, describeFeatureOptions?: DescribeFeatureOptions): void;
type ParserOptions = Pick<VitestCucumberOptions, 'language'>;
declare function loadFeature(featureFilePath: string, options?: ParserOptions): Promise<Feature>;
type Currency = {
raw: string;
value: number;
currency: string;
};
declare function VitestCucumberPlugin(options: any): {
name: string;
configureServer(server: any): void;
};
type CustomParameterExpressionArgs<T> = {
name: string;
regexp: RegExp;
transformer: (value: string) => T;
};
declare const defineParameterExpression: <T>(args: CustomParameterExpressionArgs<T>) => void;
export { type Currency, type CustomParameterExpressionArgs, type VitestCucumberOptions, VitestCucumberPlugin, defineParameterExpression, describeFeature, loadFeature, setVitestCucumberConfiguration };