From 35bd0916879601ddd2f6e9cb65519fe94b156046 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Mon, 15 Jul 2019 09:53:27 -0700 Subject: [PATCH] Updated signature of setDefinitionFunctionWrapper (#36709) * Fixes to definition cucumber wrapper * Add types * Oops --- types/cucumber/cucumber-tests.ts | 18 +++++++++++++++++- types/cucumber/index.d.ts | 4 +++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/types/cucumber/cucumber-tests.ts b/types/cucumber/cucumber-tests.ts index 41a52c6d61..753e06f0a3 100644 --- a/types/cucumber/cucumber-tests.ts +++ b/types/cucumber/cucumber-tests.ts @@ -1,5 +1,5 @@ import * as assert from "power-assert"; -import { setWorldConstructor, defineParameterType, After, AfterAll, Before, BeforeAll, Given, When, Then } from "cucumber"; +import { setDefinitionFunctionWrapper, setWorldConstructor, defineParameterType, After, AfterAll, Before, BeforeAll, Given, When, Then } from "cucumber"; import cucumber = require("cucumber"); type Callback = cucumber.CallbackStepDefinition; @@ -187,6 +187,22 @@ function StepSampleWithoutDefineSupportCode() { Given('a {param} step', param => { assert.equal(param, 'PARTICULAR'); }); + + Given('a step with custom options for function wrapper', { timeout: 1, wrapperOptions: { retry: 2 } }, param => { + console.log('Mock step'); + }); + + Given('a step with custom options for function wrapper with any complext wrapper options', { wrapperOptions: { moreOptions: { nested: [] } } }, param => { + console.log('Mock step'); + }); + + setDefinitionFunctionWrapper((fn: () => void) => { + return fn; + }); + setDefinitionFunctionWrapper((fn: () => void, options: {}) => { + console.log(`Custom Options passed into step`); + return fn; + }); } // syntax defineSupportCode deprecated diff --git a/types/cucumber/index.d.ts b/types/cucumber/index.d.ts index b28f2f1d31..497db1352b 100644 --- a/types/cucumber/index.d.ts +++ b/types/cucumber/index.d.ts @@ -6,6 +6,7 @@ // BendingBender // ErikSchierboom // Peter Morlion +// Don Jayamanne // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 @@ -45,6 +46,7 @@ export type StepDefinitionCode = (this: World, ...stepArgs: any[]) => any; export interface StepDefinitionOptions { timeout?: number; + wrapperOptions?: {[key: string]: any}; } export interface StepDefinitions { @@ -73,7 +75,7 @@ export function defineStep(pattern: RegExp | string, options: StepDefinitionOpti export function Given(pattern: RegExp | string, code: StepDefinitionCode): void; export function Given(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void; export function setDefaultTimeout(time: number): void; -export function setDefinitionFunctionWrapper(fn: () => void, options?: {[key: string]: any}): void; +export function setDefinitionFunctionWrapper(fn: ((fn: () => void) => (...args: any[]) => any) | ((fn: () => void, options?: {[key: string]: any}) => (...args: any[]) => any)): void; // tslint:disable-next-line ban-types export function setWorldConstructor(world: ((this: World, init: {attach: Function, parameters: {[key: string]: any}}) => void) | {}): void; export function Then(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void;