From 02ff752907efc578064bdcdc5139d88601129bcd Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Wed, 2 Aug 2017 02:35:16 +0200 Subject: [PATCH] [cucumber] add this definition to steps and hooks, lint code (#18369) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an optional extended description… --- types/cucumber/cucumber-tests.ts | 54 ++-- types/cucumber/index.d.ts | 447 ++++++++++++++-------------- types/cucumber/tsconfig.json | 6 +- types/cucumber/tslint.json | 1 + types/cucumber/v1/cucumber-tests.ts | 52 ++-- types/cucumber/v1/index.d.ts | 371 +++++++++++------------ types/cucumber/v1/tsconfig.json | 56 ++-- types/cucumber/v1/tslint.json | 1 + 8 files changed, 484 insertions(+), 504 deletions(-) create mode 100644 types/cucumber/tslint.json create mode 100644 types/cucumber/v1/tslint.json diff --git a/types/cucumber/cucumber-tests.ts b/types/cucumber/cucumber-tests.ts index e0ecc2bed9..141a201f89 100644 --- a/types/cucumber/cucumber-tests.ts +++ b/types/cucumber/cucumber-tests.ts @@ -6,42 +6,42 @@ function StepSample() { type Table = cucumber.TableDefinition; type HookScenarioResult = cucumber.HookScenarioResult; - cucumber.defineSupportCode(function ({setWorldConstructor, defineParameterType, After, Around, Before, registerHandler, Given, When, Then}) { - setWorldConstructor(function ({attach, parameters}: any) { + cucumber.defineSupportCode(({setWorldConstructor, defineParameterType, After, Around, Before, registerHandler, Given, When, Then}) => { + setWorldConstructor(function({attach, parameters}) { this.attach = attach; this.parameters = parameters; - this.visit = function (url: string, callback: Callback) { + this.visit = (url: string, callback: Callback) => { callback(null, 'pending'); - } + }; }); - Before(function (scenarioResult: HookScenarioResult, callback: Callback) { + Before((scenarioResult: HookScenarioResult, callback: Callback) => { console.log(scenarioResult.status === "failed"); callback(); }); - Before({ timeout: 1000 }, function (scenarioResult: HookScenarioResult, callback: Callback) { + Before({ timeout: 1000 }, (scenarioResult: HookScenarioResult, callback: Callback) => { console.log(scenarioResult.status === "failed"); callback(); }); - Around(function (scenarioResult: HookScenarioResult, runScenario: (error: string, callback?: Function) => void) { - scenarioResult.status === "failed" && runScenario(null, function () { + Around((scenarioResult: HookScenarioResult, runScenario: (error: string | null, callback?: () => void) => void) => { + scenarioResult.status === "failed" && runScenario(null, () => { console.log('finish tasks'); }); }); - After((scenarioResult: HookScenarioResult, callback?: Callback) => { + After((scenarioResult: HookScenarioResult, callback: Callback) => { console.log("After"); callback(); }); - After({ timeout: 1000 }, (scenarioResult: HookScenarioResult, callback?: Callback) => { + After({ timeout: 1000 }, (scenarioResult: HookScenarioResult, callback: Callback) => { console.log("After"); callback(); }); - registerHandler('AfterFeatures', function (event: any, callback: Function) { + registerHandler('AfterFeatures', (event: any, callback: () => void) => { callback(); }); @@ -53,15 +53,15 @@ function StepSample() { console.log(typeof x); }); - Given(/^I am on the Cucumber.js GitHub repository$/, function (callback: Callback) { + Given(/^I am on the Cucumber.js GitHub repository$/, function(callback: Callback) { this.visit('https://github.com/cucumber/cucumber-js', callback); }); - When(/^I go to the README file$/, function (title: string, callback: Callback) { + When(/^I go to the README file$/, (title: string, callback: Callback) => { callback(null, 'pending'); }); - Then(/^I should see "(.*)" as the page title$/, {timeout: 60 * 1000}, function (title: string, callback: Callback) { + Then(/^I should see "(.*)" as the page title$/, {timeout: 60 * 1000}, function(title: string, callback: Callback) { const pageTitle = this.browser.text('title'); if (title === pageTitle) { @@ -74,7 +74,7 @@ function StepSample() { // Type for data_table.js on // https://github.com/cucumber/cucumber-js/blob/a5fd8251918c278ab2e389226d165cedb44df14a/lib/cucumber/ast/data_table.js - Given(/^a table step with Table raw$/, function (table: Table) { + Given(/^a table step with Table raw$/, (table: Table) => { const expected = [ ['Cucumber', 'Cucumis sativus'], ['Burr Gherkin', 'Cucumis anguria'] @@ -83,7 +83,7 @@ function StepSample() { assert.deepEqual(actual, expected); }); - Given(/^a table step with Table rows$/, function (table: Table) { + Given(/^a table step with Table rows$/, (table: Table) => { const expected = [ ['Apricot', '5'], ['Brocolli', '2'], @@ -93,22 +93,22 @@ function StepSample() { assert.deepEqual(actual, expected); }); - Given(/^a table step with Table rowHash$/, function (table: Table) { + Given(/^a table step with Table rowHash$/, (table: Table) => { const expected = { - 'Cucumber': 'Cucumis sativus', + Cucumber: 'Cucumis sativus', 'Burr Gherkin': 'Cucumis anguria' }; - const actual: { [firstCol:string]: string } = table.rowsHash(); + const actual: { [firstCol: string]: string } = table.rowsHash(); assert.deepEqual(actual, expected); }); - Given(/^a table step$/, function (table: Table) { + Given(/^a table step$/, (table: Table) => { const expected = [ - {'Vegetable': 'Apricot', 'Rating': '5'}, - {'Vegetable': 'Brocolli', 'Rating': '2'}, - {'Vegetable': 'Cucumber', 'Rating': '10'} + {Vegetable: 'Apricot', Rating: '5'}, + {Vegetable: 'Brocolli', Rating: '2'}, + {Vegetable: 'Cucumber', Rating: '10'} ]; - const actual: { [colName:string]: string }[] = table.hashes(); + const actual: Array<{ [colName: string]: string }> = table.hashes(); assert.deepEqual(actual, expected); }); @@ -118,10 +118,9 @@ function StepSample() { typeName: 'param' }); - Given('a {param} step', function (param) { - assert.equal(param, 'PARTICULAR') + Given('a {param} step', param => { + assert.equal(param, 'PARTICULAR'); }); - }); let fns: cucumber.SupportCodeConsumer[] = cucumber.getSupportCodeFns(); @@ -132,7 +131,6 @@ function StepSample() { function registerListener(): cucumber.EventListener { let listener = Object.assign(cucumber.Listener(), { handleBeforeScenarioEvent: (scenario: cucumber.events.ScenarioPayload, callback: () => void) => { - // do some interesting stuff ... callback(); diff --git a/types/cucumber/index.d.ts b/types/cucumber/index.d.ts index 635a594ae5..90ed0abe4a 100644 --- a/types/cucumber/index.d.ts +++ b/types/cucumber/index.d.ts @@ -1,196 +1,124 @@ -// Type definitions for cucumber-js v2.0.0 +// Type definitions for cucumber-js 2.0 // Project: https://github.com/cucumber/cucumber-js -// Definitions by: Abraão Alves , Jan Molak , Isaiah Soung +// Definitions by: Abraão Alves +// Jan Molak +// Isaiah Soung +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 -export = cucumber; +export interface CallbackStepDefinition { + pending(): PromiseLike; + (error?: any, pending?: string): void; +} -declare namespace cucumber { +export interface TableDefinition { + raw(): string[][]; + rows(): string[][]; + rowsHash(): { [firstCol: string]: string }; + hashes(): Array<{ [colName: string]: string }>; +} - export interface CallbackStepDefinition { - pending: () => PromiseLike; - (error?: any, pending?: string): void; +export type StepDefinitionParam = string | number | CallbackStepDefinition | TableDefinition; + +export type StepDefinitionCode = (this: {[key: string]: any}, ...stepArgs: StepDefinitionParam[]) => PromiseLike | any | void; + +export 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; +} + +export interface HookScenarioResult { + duration: number; + failureException: Error; + scenario: Scenario; + status: string; + stepsResults: any; +} + +export type HookCode = (this: { [key: string]: any }, scenario: HookScenarioResult, callback?: CallbackStepDefinition) => void; + +// tslint:disable-next-line ban-types +export type AroundCode = (scenario: HookScenarioResult, runScenario?: (error: string, callback?: Function) => void) => void; + +export interface Transform { + regexp: RegExp; + transformer(arg: string): any; + typeName: string; +} + +export interface HookOptions { + timeout?: number; + tags?: any; +} + +export interface Hooks { + Before(code: HookCode): void; + Before(options: HookOptions, code: HookCode): void; + After(code: HookCode): void; + After(options: HookOptions, code: HookCode): void; + 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; + registerHandler(handlerOption: string, code: (event: any, callback: CallbackStepDefinition) => void): void; + registerListener(listener: EventListener): void; + defineParameterType(transform: Transform): void; +} + +export class EventListener { + hear(event: events.Event, callback: () => void): void; + hasHandlerForEvent(event: events.Event): boolean; + buildHandlerNameForEvent(event: events.Event): string; + getHandlerForEvent(event: events.Event): EventHook; + buildHandlerName(shortName: string): string; + setHandlerForEvent(shortName: string, handler: EventListener): void; +} + +export function Listener(): EventListener; + +export namespace events { + interface Event { + name: string; + data: any; } - export interface TableDefinition { - raw: () => Array>; - rows: () => Array>; - rowsHash: () => { [firstCol:string]: string }; - hashes: () => Array<{ [colName:string]: string }>; + // tslint:disable-next-line no-empty-interface + interface EventPayload { } - type StepDefinitionParam = string | number | CallbackStepDefinition | TableDefinition; - - interface StepDefinitionCode { - (...stepArgs: Array): PromiseLike | any | void; + interface FeaturesPayload extends EventPayload { + getFeatures(): any[]; // https://github.com/cucumber/cucumber-js/blob/dc698bf5bc10d591fa7adeec5fa21b2d90dc9679/lib/cucumber/runtime.js#L34 } - 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 HookScenarioResult { + interface FeaturesResultPayload extends EventPayload { duration: number; - failureException: Error; - scenario: Scenario; - status: string; - stepsResults: any; + scenarioResults: any[]; + success: boolean; + stepsResults: any[]; + strict: boolean; } - interface HookCode { - (scenario: HookScenarioResult, callback?: CallbackStepDefinition): void; - } - - interface AroundCode { - (scenario: HookScenarioResult, runScenario?: (error: string, callback?: Function) => void): void; - } - - interface Transform { - regexp: RegExp; - transformer: (arg: string) => any; - typeName: string; - } - - interface HookOptions { - timeout?: number; - tags?: any; - } - - export interface Hooks { - Before(code: HookCode): void; - Before(options: HookOptions, code: HookCode): void; - After(code: HookCode): void; - After(options: HookOptions, code: HookCode): void; - Around(code: AroundCode): void; - setDefaultTimeout(time: number): void; - setWorldConstructor(world: (() => void) | ({})): void; - registerHandler(handlerOption: string, code: (event: any, callback: CallbackStepDefinition) => void): void; - registerListener(listener: EventListener): void; - defineParameterType(transform: Transform): void; - } - - export class EventListener { - hear(event: events.Event, callback: () => void): void; - hasHandlerForEvent(event: events.Event): boolean; - buildHandlerNameForEvent(event: events.Event): string; - getHandlerForEvent(event: events.Event): EventHook; - buildHandlerName(shortName: string): string; - setHandlerForEvent(shortName: string, handler: EventListener): void; - } - - export function Listener(): EventListener; - - export namespace events { - - interface Event { - name: string; - data: any; - } - - interface EventPayload { - } - - interface FeaturesPayload extends EventPayload { - getFeatures(): any[]; // https://github.com/cucumber/cucumber-js/blob/dc698bf5bc10d591fa7adeec5fa21b2d90dc9679/lib/cucumber/runtime.js#L34 - } - - interface FeaturesResultPayload extends EventPayload { - duration: number; - scenarioResults: any[]; - success: boolean; - stepsResults: any[]; - strict: boolean; - } - - interface FeaturePayload extends EventPayload { - description: string; - keyword: string; - line: number; - name: string; - tags: Tag[]; - uri: string; - scenarios: Scenario[]; - } - - interface ScenarioPayload extends EventPayload { - feature: Feature; - exception: Error; - keyword: string; - lines: number[]; - name: string; - tags: Tag[]; - uri: string; - line: number; - description: string; - steps: Step[]; - } - - interface ScenarioResultPayload extends EventPayload { - duration: any; - failureException: Error; - scenario: Scenario; - status: string; - stepResults: any[]; - } - - interface StepPayload extends EventPayload { - arguments: any; - line: number; - name: string; - scenario: Scenario; - uri: string; - isBackground: boolean; - keyword: string; - keywordType: string; - } - - interface StepResultPayload extends EventPayload { - ambiguousStepDefinitions: any; - attachments: any[]; - duration: any; - failureException: Error; - step: Step; - stepDefinition: StepDefinition; - status: string; - } - - } - - export interface StepDefinition { - code: Function; - line: number; - options: {}; - pattern: any; - uri: string; - } - - export interface Tag { - name: string; - line: number; - } - - export interface Step { - arguments: any; - line: number; - name: string; - scenario: Scenario; - uri: string; - isBackground: boolean; + interface FeaturePayload extends EventPayload { + description: string; keyword: string; - keywordType: string; + line: number; + name: string; + tags: Tag[]; + uri: string; + scenarios: Scenario[]; } - export interface Scenario { + interface ScenarioPayload extends EventPayload { feature: Feature; exception: Error; keyword: string; @@ -203,62 +131,125 @@ declare namespace cucumber { steps: Step[]; } - export interface Feature { - description: string; - keyword: string; + interface ScenarioResultPayload extends EventPayload { + duration: any; + failureException: Error; + scenario: Scenario; + status: string; + stepResults: any[]; + } + + interface StepPayload extends EventPayload { + arguments: any; line: number; name: string; - tags: Tag[]; + scenario: Scenario; uri: string; - scenarios: Scenario[]; + isBackground: boolean; + keyword: string; + keywordType: string; } - interface EventHook { - (event: events.Event, callback?: () => void): void; + interface StepResultPayload extends EventPayload { + ambiguousStepDefinitions: any; + attachments: any[]; + duration: any; + failureException: Error; + step: Step; + stepDefinition: StepDefinition; + status: string; } - - export interface SupportCodeConsumer { - (stepDefinitions: StepDefinitions & Hooks): void; - } - - export function defineSupportCode(consumer: SupportCodeConsumer): void; - - export function getSupportCodeFns(): SupportCodeConsumer[]; - - export function clearSupportCodeFns(): void; - - // https://github.com/cucumber/cucumber-js/commit/231183a8a11c985ef7ced1155b7a75f5120a34b6 - export class Formatter { - constructor(options?: any); - - log(data: any): void; - } - - export class SummaryFormatter extends Formatter { - indent(text: string, numberOfSpaces: number): any; - } - export class PrettyFormatter extends SummaryFormatter { - formatTags(tags: Tag[]): any; - logIndented(text: string, level: number): void; - logStepResult(stepResult: any): void; - } - - export class ProgressFormatter extends SummaryFormatter { - } - - export class RerunFormatter extends Formatter { - } - - export class SnippetsFormatter extends Formatter { - } - - export class UsageFormatter extends Formatter { - } - - export class UsageJsonFormatter extends Formatter { - } - - export class JsonFormatter extends Formatter { - } - +} + +export interface StepDefinition { + // tslint:disable-next-line ban-types + code: Function; + line: number; + options: {}; + pattern: any; + uri: string; +} + +export interface Tag { + name: string; + line: number; +} + +export interface Step { + arguments: any; + line: number; + name: string; + scenario: Scenario; + uri: string; + isBackground: boolean; + keyword: string; + keywordType: string; +} + +export interface Scenario { + feature: Feature; + exception: Error; + keyword: string; + lines: number[]; + name: string; + tags: Tag[]; + uri: string; + line: number; + description: string; + steps: Step[]; +} + +export interface Feature { + description: string; + keyword: string; + line: number; + name: string; + tags: Tag[]; + uri: string; + scenarios: Scenario[]; +} + +export type EventHook = (event: events.Event, callback?: () => void) => void; + +export type SupportCodeConsumer = (stepDefinitions: StepDefinitions & Hooks) => void; + +export function defineSupportCode(consumer: SupportCodeConsumer): void; + +export function getSupportCodeFns(): SupportCodeConsumer[]; + +export function clearSupportCodeFns(): void; + +// https://github.com/cucumber/cucumber-js/commit/231183a8a11c985ef7ced1155b7a75f5120a34b6 +export class Formatter { + constructor(options?: any); + + log(data: any): void; +} + +export class SummaryFormatter extends Formatter { + indent(text: string, numberOfSpaces: number): any; +} + +export class PrettyFormatter extends SummaryFormatter { + formatTags(tags: Tag[]): any; + logIndented(text: string, level: number): void; + logStepResult(stepResult: any): void; +} + +export class ProgressFormatter extends SummaryFormatter { +} + +export class RerunFormatter extends Formatter { +} + +export class SnippetsFormatter extends Formatter { +} + +export class UsageFormatter extends Formatter { +} + +export class UsageJsonFormatter extends Formatter { +} + +export class JsonFormatter extends Formatter { } diff --git a/types/cucumber/tsconfig.json b/types/cucumber/tsconfig.json index c7fe6d2258..a2bd1c7023 100644 --- a/types/cucumber/tsconfig.json +++ b/types/cucumber/tsconfig.json @@ -6,8 +6,8 @@ "dom" ], "noImplicitAny": true, - "noImplicitThis": false, - "strictNullChecks": false, + "noImplicitThis": true, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" @@ -20,4 +20,4 @@ "index.d.ts", "cucumber-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/cucumber/tslint.json b/types/cucumber/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cucumber/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/cucumber/v1/cucumber-tests.ts b/types/cucumber/v1/cucumber-tests.ts index 347bec135b..f65d01fc6a 100644 --- a/types/cucumber/v1/cucumber-tests.ts +++ b/types/cucumber/v1/cucumber-tests.ts @@ -1,44 +1,44 @@ -import * as assert from "power-assert"; -import cucumber = require("cucumber"); +import * as assert from 'power-assert'; +import cucumber = require('cucumber'); -function StepSample() { +function StepSample(this: cucumber.StepDefinitions & cucumber.Hooks) { type Callback = cucumber.CallbackStepDefinition; type Table = cucumber.TableDefinition; type HookScenario = cucumber.HookScenario; - const step = this; - const hook = this; + const step = this; + const hook = this; - hook.Before(function (scenario: HookScenario, callback: Callback) { + hook.Before((scenario: HookScenario, callback: Callback) => { scenario.isFailed() && callback.pending(); }); - hook.Before({ timeout: 1000 }, function(scenario: HookScenario, callback: Callback) { + hook.Before({ timeout: 1000 }, (scenario: HookScenario, callback: Callback) => { callback(); }); - hook.After({ timeout: 1000 }, function(scenario: HookScenario, callback: Callback) { + hook.After({ timeout: 1000 }, (scenario: HookScenario, callback: Callback) => { callback(); }); - hook.Around(function (scenario: HookScenario, runScenario: (error: string, callback?: Function) => void) { - scenario.isFailed() && runScenario(null, function () { + hook.Around((scenario: HookScenario, runScenario: (error: string | null, callback?: () => void) => void) => { + scenario.isFailed() && runScenario(null, () => { console.log('finish tasks'); }); }); - hook.registerHandler('AfterFeatures', function (event: any, callback: Function) { + hook.registerHandler('AfterFeatures', (event: any, callback: () => void) => { callback(); }); - step.Given(/^I am on the Cucumber.js GitHub repository$/, function (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) { + step.When(/^I go to the README file$/, (title: string, callback: Callback) => { callback(null, 'pending'); }); - step.Then(/^I should see "(.*)" as the page title$/, {timeout: 60 * 1000}, function (title: string, callback: Callback) { + step.Then(/^I should see "(.*)" as the page title$/, {timeout: 60 * 1000}, function(title: string, callback: Callback) { const pageTitle = this.browser.text('title'); if (title === pageTitle) { @@ -51,7 +51,7 @@ function StepSample() { // Type for data_table.js on // https://github.com/cucumber/cucumber-js/blob/a5fd8251918c278ab2e389226d165cedb44df14a/lib/cucumber/ast/data_table.js - step.Given(/^a table step with Table raw$/, function (table: Table) { + step.Given(/^a table step with Table raw$/, (table: Table) => { const expected = [ ['Cucumber', 'Cucumis sativus'], ['Burr Gherkin', 'Cucumis anguria'] @@ -60,7 +60,7 @@ function StepSample() { assert.deepEqual(actual, expected); }); - step.Given(/^a table step with Table rows$/, function (table: Table) { + step.Given(/^a table step with Table rows$/, (table: Table) => { const expected = [ ['Apricot', '5'], ['Brocolli', '2'], @@ -70,31 +70,29 @@ function StepSample() { assert.deepEqual(actual, expected); }); - step.Given(/^a table step with Table rowHash$/, function (table: Table) { + step.Given(/^a table step with Table rowHash$/, (table: Table) => { const expected = { - 'Cucumber': 'Cucumis sativus', + Cucumber: 'Cucumis sativus', 'Burr Gherkin': 'Cucumis anguria' }; - const actual: { [firstCol:string]: string } = table.rowsHash(); + const actual: { [firstCol: string]: string } = table.rowsHash(); assert.deepEqual(actual, expected); }); - step.Given(/^a table step$/, function (table: Table) { + step.Given(/^a table step$/, (table: Table) => { const expected = [ - {'Vegetable': 'Apricot', 'Rating': '5'}, - {'Vegetable': 'Brocolli', 'Rating': '2'}, - {'Vegetable': 'Cucumber', 'Rating': '10'} + {Vegetable: 'Apricot', Rating: '5'}, + {Vegetable: 'Brocolli', Rating: '2'}, + {Vegetable: 'Cucumber', Rating: '10'} ]; - const actual: { [colName:string]: string }[] = table.hashes(); + const actual: Array<{ [colName: string]: string }> = table.hashes(); assert.deepEqual(actual, expected); }); - } function registerListener(): cucumber.EventListener { let listener = Object.assign(cucumber.Listener(), { - handleBeforeScenarioEvent: (scenario: cucumber.events.ScenarioPayload, callback: () => void) => { - + handleBeforeScenarioEvent(scenario: cucumber.events.ScenarioPayload, callback: () => void) { // do some interesting stuff ... callback(); diff --git a/types/cucumber/v1/index.d.ts b/types/cucumber/v1/index.d.ts index 39a915f935..18c70c5ea6 100644 --- a/types/cucumber/v1/index.d.ts +++ b/types/cucumber/v1/index.d.ts @@ -1,215 +1,206 @@ -// Type definitions for cucumber-js v1.3.1 +// Type definitions for cucumber-js 1.3 // Project: https://github.com/cucumber/cucumber-js -// Definitions by: Abraão Alves , Jan Molak , Isaiah Soung +// Definitions by: Abraão Alves +// Jan Molak +// Isaiah Soung +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 -export = cucumber; +export interface CallbackStepDefinition { + pending(): PromiseLike; + (error?: any, pending?: string): void; +} -declare namespace cucumber { +export interface TableDefinition { + raw(): string[][]; + rows(): string[][]; + rowsHash(): { [firstCol: string]: string }; + hashes(): Array<{ [colName: string]: string }>; +} - export interface CallbackStepDefinition { - pending: () => PromiseLike; - (error?: any, pending?: string): void; - } +export type StepDefinitionParam = string | CallbackStepDefinition | TableDefinition; - export interface TableDefinition { - raw: () => Array>; - rows: () => Array>; - rowsHash: () => { [firstCol:string]: string }; - hashes: () => Array<{ [colName:string]: string }>; - } +export type StepDefinitionCode = (this: { [key: string]: any }, ...stepArgs: StepDefinitionParam[]) => PromiseLike | any | void; - type StepDefinitionParam = string | CallbackStepDefinition | TableDefinition; +export interface StepDefinitionOptions { + timeout?: number; +} - interface StepDefinitionCode { - (...stepArgs: Array): PromiseLike | any | void; - } +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 StepDefinitionOptions { - timeout?: number; - } +export interface HookScenario { + getKeyword(): string; + getName(): string; + getDescription(): string; + getUri(): string; + getLine(): number; + getTags(): string[]; + getException(): Error; + getAttachments(): any[]; + attach(data: any, mimeType?: string, callback?: (err?: any) => void): void; + isSuccessful(): boolean; + isFailed(): boolean; + isPending(): boolean; + isUndefined(): boolean; + isSkipped(): boolean; +} - 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; - } +export type HookCode = (this: { [key: string]: any }, scenario: HookScenario, callback?: CallbackStepDefinition) => void; - interface HookScenario { - getKeyword(): string; +// tslint:disable-next-line ban-types +export type AroundCode = (scenario: HookScenario, runScenario?: (error: string, callback?: Function) => void) => void; + +export interface HookOptions { + timeout?: number; + tags?: any; +} + +export interface Hooks { + Before(code: HookCode): void; + Before(options: HookOptions, code: HookCode): void; + After(code: HookCode): void; + After(options: HookOptions, code: HookCode): void; + Around(code: AroundCode): void; + setDefaultTimeout(time: number): void; + registerHandler(handlerOption: string, code: (event: any, callback: CallbackStepDefinition) => void): void; + registerListener(listener: EventListener): void; +} + +export class EventListener { + hear(event: events.Event, callback: () => void): void; + hasHandlerForEvent(event: events.Event): boolean; + buildHandlerNameForEvent(event: events.Event): string; + getHandlerForEvent(event: events.Event): EventHook; + buildHandlerName(shortName: string): string; + setHandlerForEvent(shortName: string, handler: EventListener): void; +} + +export function Listener(): EventListener; + +export namespace events { + interface Event { getName(): string; - getDescription(): string; - getUri(): string; - getLine(): number; - getTags(): string[]; - getException(): Error; - getAttachments(): any[]; - attach(data: any, mimeType?: string, callback?: (err?: any) => void): void; + getPayloadItem(name: string): EventPayload; + } + + // tslint:disable-next-line no-empty-interface + interface EventPayload { + } + + interface FeaturesPayload extends EventPayload { + getFeatures(): any[]; // https://github.com/cucumber/cucumber-js/blob/dc698bf5bc10d591fa7adeec5fa21b2d90dc9679/lib/cucumber/runtime.js#L34 + } + + interface FeaturesResultPayload extends EventPayload { + getDuration(): any; + getScenarioCounts(): any; + getStepCounts(): any; isSuccessful(): boolean; - isFailed(): boolean; - isPending(): boolean; - isUndefined(): boolean; - isSkipped(): boolean; } - interface HookCode { - (scenario: HookScenario, callback?: CallbackStepDefinition): void; - } - - interface AroundCode { - (scenario: HookScenario, runScenario?: (error: string, callback?: Function) => void): void; - } - - interface HookOptions { - timeout?: number; - tags?: any; - } - - export interface Hooks { - Before(code: HookCode): void; - Before(options: HookOptions, code: HookCode): void; - After(code: HookCode): void; - After(options: HookOptions, code: HookCode): void; - Around(code: AroundCode): void; - setDefaultTimeout(time: number): void; - registerHandler(handlerOption: string, code: (event: any, callback: CallbackStepDefinition) => void): void; - registerListener(listener: EventListener): void; - } - - export class EventListener { - hear(event: events.Event, callback: () => void): void; - hasHandlerForEvent(event: events.Event): boolean; - buildHandlerNameForEvent(event: events.Event): string; - getHandlerForEvent(event: events.Event): EventHook; - buildHandlerName(shortName: string): string; - setHandlerForEvent(shortName: string, handler: EventListener): void; - } - - export function Listener(): EventListener; - - export namespace events { - - interface Event { - getName(): string; - getPayloadItem(name: string): EventPayload; - } - - interface EventPayload { - } - - interface FeaturesPayload extends EventPayload { - getFeatures(): any[]; // https://github.com/cucumber/cucumber-js/blob/dc698bf5bc10d591fa7adeec5fa21b2d90dc9679/lib/cucumber/runtime.js#L34 - } - - interface FeaturesResultPayload extends EventPayload { - getDuration(): any; - getScenarioCounts(): any; - getStepCounts(): any; - isSuccessful(): boolean; - } - - interface FeaturePayload extends EventPayload { - getStepKeywordByLines(): any; - getScenarioKeyword(): string; - getKeyword(): string; - getName(): string; - getDescription(): string; - getUri(): string; - getLine(): number; - getTags(): Tag[]; - getScenarios(): ScenarioPayload[]; - getPayloadItem(): FeaturePayload; - } - - interface ScenarioPayload extends EventPayload { - getName(): string; - getKeyword(): string; - getDescription(): string; - getFeature(): FeaturePayload; - getUri(): string; - getUris(): string[]; - getLine(): number; - getLines(): number[]; - getTags(): Tag[]; - getSteps(): any[]; - getPayloadItem(): ScenarioPayload; - } - - interface ScenarioResultPayload extends EventPayload { - getFailureException(): Error; - getScenario(): any; - getStatus(): any; - } - - interface StepPayload extends EventPayload { - isHidden(): boolean; - isOutlineStep(): boolean; - getKeyword(): string; - getName(): string; - hasUri(): boolean; - getUri(): string; - getLine(): number; - getPreviousStep(): any; - hasPreviousStep(): boolean; - getAttachment(): any; - getAttachmentContents(): any; - getDocString(): string; - getDataTable(): any; - hasAttachment(): boolean; - hasDocString(): boolean; - hasDataTable(): boolean; - ensureDataTableIsAttached(): void; - isOutcomeStep(): boolean; - isEventStep(): boolean; - hasOutcomeStepKeyword(): boolean; - hasEventStepKeyword(): boolean; - isRepeatingOutcomeStep(): boolean; - isRepeatingEventStep(): boolean; - hasRepeatStepKeyword(): boolean; - isPrecededByOutcomeStep(): boolean; - isPrecededByEventStep(): boolean; - } - - interface StepResultPayload extends EventPayload { - getAmbiguousStepDefinitions(): any[]; - getAttachments(): any[]; - getDuration(): any; - getFailureException(): Error; - getStep(): any; - getStepDefinition(): any; - getStatus(): any; - hasAttachments(): boolean; - } - - } - - interface Tag { - getName(): string; - getLine(): number; - } - - export interface Scenario { + interface FeaturePayload extends EventPayload { + getStepKeywordByLines(): any; + getScenarioKeyword(): string; getKeyword(): string; getName(): string; getDescription(): string; getUri(): string; getLine(): number; getTags(): Tag[]; - getException(): Error; - getAttachments(): any[]; - attach(data: any, mimeType?: string, callback?: (err?: any) => void): void; - isSuccessful(): boolean; - isFailed(): boolean; - isPending(): boolean; - isUndefined(): boolean; - isSkipped(): boolean; + getScenarios(): ScenarioPayload[]; + getPayloadItem(): FeaturePayload; } - interface EventHook { - (event: events.Event, callback?: () => void): void; + interface ScenarioPayload extends EventPayload { + getName(): string; + getKeyword(): string; + getDescription(): string; + getFeature(): FeaturePayload; + getUri(): string; + getUris(): string[]; + getLine(): number; + getLines(): number[]; + getTags(): Tag[]; + getSteps(): any[]; + getPayloadItem(): ScenarioPayload; + } + + interface ScenarioResultPayload extends EventPayload { + getFailureException(): Error; + getScenario(): any; + getStatus(): any; + } + + interface StepPayload extends EventPayload { + isHidden(): boolean; + isOutlineStep(): boolean; + getKeyword(): string; + getName(): string; + hasUri(): boolean; + getUri(): string; + getLine(): number; + getPreviousStep(): any; + hasPreviousStep(): boolean; + getAttachment(): any; + getAttachmentContents(): any; + getDocString(): string; + getDataTable(): any; + hasAttachment(): boolean; + hasDocString(): boolean; + hasDataTable(): boolean; + ensureDataTableIsAttached(): void; + isOutcomeStep(): boolean; + isEventStep(): boolean; + hasOutcomeStepKeyword(): boolean; + hasEventStepKeyword(): boolean; + isRepeatingOutcomeStep(): boolean; + isRepeatingEventStep(): boolean; + hasRepeatStepKeyword(): boolean; + isPrecededByOutcomeStep(): boolean; + isPrecededByEventStep(): boolean; + } + + interface StepResultPayload extends EventPayload { + getAmbiguousStepDefinitions(): any[]; + getAttachments(): any[]; + getDuration(): any; + getFailureException(): Error; + getStep(): any; + getStepDefinition(): any; + getStatus(): any; + hasAttachments(): boolean; } } + +export interface Tag { + getName(): string; + getLine(): number; +} + +export interface Scenario { + getKeyword(): string; + getName(): string; + getDescription(): string; + getUri(): string; + getLine(): number; + getTags(): Tag[]; + getException(): Error; + getAttachments(): any[]; + attach(data: any, mimeType?: string, callback?: (err?: any) => void): void; + isSuccessful(): boolean; + isFailed(): boolean; + isPending(): boolean; + isUndefined(): boolean; + isSkipped(): boolean; +} + +export type EventHook = (event: events.Event, callback?: () => void) => void; diff --git a/types/cucumber/v1/tsconfig.json b/types/cucumber/v1/tsconfig.json index b467d8c4b4..3c64799f9a 100644 --- a/types/cucumber/v1/tsconfig.json +++ b/types/cucumber/v1/tsconfig.json @@ -1,31 +1,31 @@ { - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6", - "dom" - ], - "noImplicitAny": true, - "noImplicitThis": false, - "strictNullChecks": false, - "baseUrl": "../../", - "typeRoots": [ - "../../" - ], - "types": [], - "paths": { - "cucumber": [ - "cucumber/v1" - ], - "cucumber/*": [ - "cucumber/v1/*" - ] + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "types": [], + "paths": { + "cucumber": [ + "cucumber/v1" + ], + "cucumber/*": [ + "cucumber/v1/*" + ] + }, + "noEmit": true, + "forceConsistentCasingInFileNames": true }, - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "cucumber-tests.ts" - ] + "files": [ + "index.d.ts", + "cucumber-tests.ts" + ] } diff --git a/types/cucumber/v1/tslint.json b/types/cucumber/v1/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cucumber/v1/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }