cucumber: define overridable World interface (#19867)

* cucumber: define overridable World interface

By implementing World as an interface, it can be extended in projects by using declaration merging.

* cucumber: add example World override to test
This commit is contained in:
Romke van der Meulen
2017-09-26 07:12:04 +02:00
committed by Masahiro Wakame
parent 6031cbb0ca
commit bbcb604ea2
2 changed files with 14 additions and 3 deletions

View File

@@ -1,6 +1,13 @@
import * as assert from "power-assert";
import cucumber = require("cucumber");
// You can optionally declare your own world properties
declare module "cucumber" {
interface World {
visit(url: string, callback: CallbackStepDefinition): void;
}
}
function StepSample() {
type Callback = cucumber.CallbackStepDefinition;
type Table = cucumber.TableDefinition;

View File

@@ -7,6 +7,10 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
export interface World {
[key: string]: any;
}
export interface CallbackStepDefinition {
pending(): PromiseLike<any>;
(error?: any, pending?: string): void;
@@ -21,7 +25,7 @@ export interface TableDefinition {
export type StepDefinitionParam = string | number | CallbackStepDefinition | TableDefinition;
export type StepDefinitionCode = (this: {[key: string]: any}, ...stepArgs: StepDefinitionParam[]) => PromiseLike<any> | any | void;
export type StepDefinitionCode = (this: World, ...stepArgs: StepDefinitionParam[]) => PromiseLike<any> | any | void;
export interface StepDefinitionOptions {
timeout?: number;
@@ -45,7 +49,7 @@ export interface HookScenarioResult {
stepsResults: any;
}
export type HookCode = (this: { [key: string]: any }, scenario: HookScenarioResult, callback?: CallbackStepDefinition) => void;
export type HookCode = (this: World, scenario: HookScenarioResult, callback?: CallbackStepDefinition) => void;
// tslint:disable-next-line ban-types
export type AroundCode = (scenario: HookScenarioResult, runScenario?: (error: string, callback?: Function) => void) => void;
@@ -69,7 +73,7 @@ export interface Hooks {
Around(code: AroundCode): void;
setDefaultTimeout(time: number): void;
// tslint:disable-next-line ban-types
setWorldConstructor(world: ((this: {[key: string]: any}, init: {attach: Function, parameters: {[key: string]: any}}) => void) | {}): void;
setWorldConstructor(world: ((this: World, init: {attach: Function, parameters: {[key: string]: any}}) => void) | {}): void;
registerHandler(handlerOption: string, code: (event: any, callback: CallbackStepDefinition) => void): void;
registerListener(listener: EventListener): void;
defineParameterType(transform: Transform): void;