Merge pull request #7167 from AbraaoAlves/cucumber-js

added cucumber-js definitions
This commit is contained in:
Masahiro Wakame
2015-12-15 23:32:45 +09:00
2 changed files with 97 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
/// <reference path="cucumber.d.ts" />
function StepSample() {
type Callback = cucumber.CallbackStepDefinition;
var step = <cucumber.StepDefinitions>this;
var hook = <cucumber.Hooks>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));
}
});
}

57
cucumber/cucumber.d.ts vendored Normal file
View File

@@ -0,0 +1,57 @@
// Type definitions for cucumber-js
// Project: https://github.com/cucumber/cucumber-js
// Definitions by: Abraão Alves <https://github.com/abraaoalves>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../es6-promise/es6-promise.d.ts" />
declare module cucumber {
export interface CallbackStepDefinition{
pending : () => Thenable<any>;
(errror?:any):void;
}
interface StepDefinitionCode {
(...stepArgs: Array<string |CallbackStepDefinition>): Thenable<any> | 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;
}