diff --git a/cucumber/cucumber-tests.ts b/cucumber/cucumber-tests.ts new file mode 100644 index 0000000000..f8b5606070 --- /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: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: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..75faeff7a5 --- /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?:any) => 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:any, callback:CallbackStepDefinition) =>void): void; + } +} + +declare module 'cucumber'{ + export = cucumber; +} \ No newline at end of file