From 5b5bfbec4c121532ac5754e742797ed3eb9fe6da Mon Sep 17 00:00:00 2001 From: abraaoalves Date: Sat, 12 Dec 2015 10:54:06 -0300 Subject: [PATCH 1/2] definitions to steps and hooks --- cucumber/cucumber-tests.ts | 40 ++++++++++++++++++++++++++ cucumber/cucumber.d.ts | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 cucumber/cucumber-tests.ts create mode 100644 cucumber/cucumber.d.ts diff --git a/cucumber/cucumber-tests.ts b/cucumber/cucumber-tests.ts new file mode 100644 index 0000000000..ba7ff1f72e --- /dev/null +++ b/cucumber/cucumber-tests.ts @@ -0,0 +1,40 @@ +/// + +function StepSample() { + type Callback = cucumber.CallbackStepDefinition; + var step = this; + var hook = this; + + hook.Before(function(scenario, callback){ + scenario.isFailed() && callback.pending(); + }) + + hook.Around(function(scenario, runScenario) { + scenario.isFailed() && runScenario(null, function(){ + console.log('finish tasks'); + }); + }); + + hook.registerHandler('AfterFeatures', function (event, callback) { + callback(); + }); + + step.Given(/^I am on the Cucumber.js GitHub repository$/, function(callback) { + this.visit('https://github.com/cucumber/cucumber-js', callback); + }); + + step.When(/^I go to the README file$/, function(title:string, callback:Callback) { + callback.pending(); + }); + + step.Then(/^I should see "(.*)" as the page title$/, { timeout:60*1000}, function(title:string, callback) { + var pageTitle = this.browser.text('title'); + + if (title === pageTitle) { + callback(); + } else { + callback(new Error("Expected to be on page with title " + title)); + } + }); +} + diff --git a/cucumber/cucumber.d.ts b/cucumber/cucumber.d.ts new file mode 100644 index 0000000000..b70fbb6b46 --- /dev/null +++ b/cucumber/cucumber.d.ts @@ -0,0 +1,57 @@ +// Type definitions for cucumber-js +// Project: https://github.com/cucumber/cucumber-js +// Definitions by: Abraão Alves +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module cucumber { + + export interface CallbackStepDefinition{ + pending : () => Thenable; + (errror?:any):void; + } + + interface StepDefinitionCode { + (...stepArgs: Array): Thenable | any | void; + } + + interface StepDefinitionOptions{ + timeout?: number; + } + + export interface StepDefinitions { + Given(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void; + Given(pattern: RegExp | string, code: StepDefinitionCode): void; + When(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void; + When(pattern: RegExp | string, code: StepDefinitionCode): void; + Then(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void; + Then(pattern: RegExp | string, code: StepDefinitionCode): void; + setDefaultTimeout(time:number): void; + } + + interface HookScenario{ + attach(text: string, mimeType?: string, callback?: (err?) => void): void; + isFailed() : boolean; + } + + interface HookCode { + (scenario: HookScenario, callback?: CallbackStepDefinition): void; + } + + interface AroundCode{ + (scenario: HookScenario, runScenario?: (error:string, callback?:Function)=>void): void; + } + + export interface Hooks { + Before(code: HookCode): void; + After(code: HookCode): void; + Around(code: AroundCode):void; + setDefaultTimeout(time:number): void; + registerHandler(handlerOption:string, code:(event, callback:CallbackStepDefinition) =>void): void; + } +} + +declare module 'cucumber'{ + export = cucumber; +} \ No newline at end of file From 0bcb4658eca981568d5cce48fd4b370c8778cbd6 Mon Sep 17 00:00:00 2001 From: abraaoalves Date: Sat, 12 Dec 2015 11:24:19 -0300 Subject: [PATCH 2/2] fix noimplicitAny errors --- cucumber/cucumber-tests.ts | 6 +++--- cucumber/cucumber.d.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cucumber/cucumber-tests.ts b/cucumber/cucumber-tests.ts index ba7ff1f72e..f8b5606070 100644 --- a/cucumber/cucumber-tests.ts +++ b/cucumber/cucumber-tests.ts @@ -1,4 +1,4 @@ -/// +/// function StepSample() { type Callback = cucumber.CallbackStepDefinition; @@ -19,7 +19,7 @@ function StepSample() { callback(); }); - step.Given(/^I am on the Cucumber.js GitHub repository$/, function(callback) { + step.Given(/^I am on the Cucumber.js GitHub repository$/, function(callback:Callback) { this.visit('https://github.com/cucumber/cucumber-js', callback); }); @@ -27,7 +27,7 @@ function StepSample() { callback.pending(); }); - step.Then(/^I should see "(.*)" as the page title$/, { timeout:60*1000}, function(title:string, callback) { + step.Then(/^I should see "(.*)" as the page title$/, { timeout:60*1000}, function(title:string, callback:Callback) { var pageTitle = this.browser.text('title'); if (title === pageTitle) { diff --git a/cucumber/cucumber.d.ts b/cucumber/cucumber.d.ts index b70fbb6b46..75faeff7a5 100644 --- a/cucumber/cucumber.d.ts +++ b/cucumber/cucumber.d.ts @@ -31,7 +31,7 @@ declare module cucumber { } interface HookScenario{ - attach(text: string, mimeType?: string, callback?: (err?) => void): void; + attach(text: string, mimeType?: string, callback?: (err?:any) => void): void; isFailed() : boolean; } @@ -48,7 +48,7 @@ declare module cucumber { After(code: HookCode): void; Around(code: AroundCode):void; setDefaultTimeout(time:number): void; - registerHandler(handlerOption:string, code:(event, callback:CallbackStepDefinition) =>void): void; + registerHandler(handlerOption:string, code:(event:any, callback:CallbackStepDefinition) =>void): void; } }