From 90ef3be0c80647551aa470329497306689a984d0 Mon Sep 17 00:00:00 2001 From: David Goss Date: Sun, 29 May 2022 10:13:59 +0100 Subject: [PATCH 01/12] mark defineStep as deprecated on entry point --- src/index.ts | 3 +++ src/wrapper.mjs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/index.ts b/src/index.ts index 7af7e040b..b65eb0dc4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,6 +38,9 @@ export const Before = methods.Before export const BeforeAll = methods.BeforeAll export const BeforeStep = methods.BeforeStep export const defineParameterType = methods.defineParameterType +/** + * @deprecated use `Given`, `When` or `Then` instead; see + */ export const defineStep = methods.defineStep export const Given = methods.Given export const setDefaultTimeout = methods.setDefaultTimeout diff --git a/src/wrapper.mjs b/src/wrapper.mjs index c852df3d6..7843f7f9d 100644 --- a/src/wrapper.mjs +++ b/src/wrapper.mjs @@ -28,6 +28,9 @@ export const Before = cucumber.Before export const BeforeAll = cucumber.BeforeAll export const BeforeStep = cucumber.BeforeStep export const defineParameterType = cucumber.defineParameterType +/** + * @deprecated use `Given`, `When` or `Then` instead; see + */ export const defineStep = cucumber.defineStep export const Given = cucumber.Given export const setDefaultTimeout = cucumber.setDefaultTimeout From 68fdd6e0d6e092d6796959b2e744ebcc16c36ce1 Mon Sep 17 00:00:00 2001 From: David Goss Date: Sun, 29 May 2022 10:25:51 +0100 Subject: [PATCH 02/12] failing test and a bit of plumbing --- src/models/gherkin_step_keyword.ts | 1 + src/models/step_definition.ts | 2 ++ src/support_code_library_builder/index.ts | 3 ++ .../index_spec.ts | 36 +++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 src/models/gherkin_step_keyword.ts diff --git a/src/models/gherkin_step_keyword.ts b/src/models/gherkin_step_keyword.ts new file mode 100644 index 000000000..3d5155208 --- /dev/null +++ b/src/models/gherkin_step_keyword.ts @@ -0,0 +1 @@ +export type GherkinStepKeyword = 'Given' | 'When' | 'Then' diff --git a/src/models/step_definition.ts b/src/models/step_definition.ts index 42b7ae111..6584b16b6 100644 --- a/src/models/step_definition.ts +++ b/src/models/step_definition.ts @@ -8,8 +8,10 @@ import Definition, { import { parseStepArgument } from '../step_arguments' import { Expression } from '@cucumber/cucumber-expressions' import { doesHaveValue } from '../value_checker' +import { GherkinStepKeyword } from './gherkin_step_keyword' export default class StepDefinition extends Definition implements IDefinition { + public readonly keyword: GherkinStepKeyword public readonly pattern: string | RegExp public readonly expression: Expression diff --git a/src/support_code_library_builder/index.ts b/src/support_code_library_builder/index.ts index 186a4fbe6..d3754289e 100644 --- a/src/support_code_library_builder/index.ts +++ b/src/support_code_library_builder/index.ts @@ -32,11 +32,13 @@ import { } from './types' import World from './world' import { ICanonicalSupportCodeIds } from '../runtime/parallel/command_types' +import { GherkinStepKeyword } from '../models/gherkin_step_keyword' interface IStepDefinitionConfig { code: any line: number options: any + keyword?: GherkinStepKeyword pattern: string | RegExp uri: string } @@ -142,6 +144,7 @@ export class SupportCodeLibraryBuilder { } defineStep( + keyword: GherkinStepKeyword, pattern: DefineStepPattern, options: IDefineStepOptions | Function, code?: Function diff --git a/src/support_code_library_builder/index_spec.ts b/src/support_code_library_builder/index_spec.ts index 6485741a5..263fcc71a 100644 --- a/src/support_code_library_builder/index_spec.ts +++ b/src/support_code_library_builder/index_spec.ts @@ -99,6 +99,42 @@ describe('supportCodeLibraryBuilder', () => { expect(stepDefinition.unwrappedCode).to.eql(step) }) }) + + describe('keyword retention', () => { + const step = function (): void {} // eslint-disable-line @typescript-eslint/no-empty-function + + beforeEach(() => + supportCodeLibraryBuilder.reset('path/to/project', uuid()) + ) + + it('should record correctly for Given', () => { + supportCodeLibraryBuilder.methods.Given('a thing', step) + expect( + supportCodeLibraryBuilder.finalize().stepDefinitions[0].keyword + ).to.eq('Given') + }) + + it('should record correctly for When', () => { + supportCodeLibraryBuilder.methods.When('a thing', step) + expect( + supportCodeLibraryBuilder.finalize().stepDefinitions[0].keyword + ).to.eq('When') + }) + + it('should record correctly for Then', () => { + supportCodeLibraryBuilder.methods.Then('a thing', step) + expect( + supportCodeLibraryBuilder.finalize().stepDefinitions[0].keyword + ).to.eq('Then') + }) + + it('should record correctly for defineStep', () => { + supportCodeLibraryBuilder.methods.defineStep('a thing', step) + expect( + supportCodeLibraryBuilder.finalize().stepDefinitions[0].keyword + ).to.eq('Given') + }) + }) }) describe('After', () => { From 6b6874208a1d24bd1164aba76a8ee33e3f914dfa Mon Sep 17 00:00:00 2001 From: David Goss Date: Sun, 29 May 2022 11:25:51 +0100 Subject: [PATCH 03/12] scrappy implementation --- src/cli/helpers_spec.ts | 2 ++ src/models/definition.ts | 2 ++ src/models/step_definition.ts | 1 + src/runtime/helpers_spec.ts | 2 ++ src/support_code_library_builder/index.ts | 19 ++++++++++++------- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/cli/helpers_spec.ts b/src/cli/helpers_spec.ts index 1c658c789..cff1a1ef2 100644 --- a/src/cli/helpers_spec.ts +++ b/src/cli/helpers_spec.ts @@ -145,6 +145,7 @@ describe('helpers', () => { line: 9, options: {}, uri: 'features/support/cukes.js', + keyword: 'Given', pattern: 'I have {int} cukes in my belly', expression: new CucumberExpression( 'I have {int} cukes in my belly', @@ -183,6 +184,7 @@ describe('helpers', () => { line: 9, options: {}, uri: 'features/support/cukes.js', + keyword: 'Given', pattern: /I have (\d+) cukes in my belly/, expression: new RegularExpression( /I have (\d+) cukes in my belly/, diff --git a/src/models/definition.ts b/src/models/definition.ts index a7a64d9ae..30b7d873a 100644 --- a/src/models/definition.ts +++ b/src/models/definition.ts @@ -1,6 +1,7 @@ import * as messages from '@cucumber/messages' import { ITestCaseHookParameter } from '../support_code_library_builder/types' import { Expression } from '@cucumber/cucumber-expressions' +import { GherkinStepKeyword } from './gherkin_step_keyword' export interface IGetInvocationDataRequest { hookParameter: ITestCaseHookParameter @@ -35,6 +36,7 @@ export interface IDefinitionParameters { export interface IStepDefinitionParameters extends IDefinitionParameters { + keyword: GherkinStepKeyword pattern: string | RegExp expression: Expression } diff --git a/src/models/step_definition.ts b/src/models/step_definition.ts index 6584b16b6..0e5f207fd 100644 --- a/src/models/step_definition.ts +++ b/src/models/step_definition.ts @@ -17,6 +17,7 @@ export default class StepDefinition extends Definition implements IDefinition { constructor(data: IStepDefinitionParameters) { super(data) + this.keyword = data.keyword this.pattern = data.pattern this.expression = data.expression } diff --git a/src/runtime/helpers_spec.ts b/src/runtime/helpers_spec.ts index 3aae88fe8..f85c4d157 100644 --- a/src/runtime/helpers_spec.ts +++ b/src/runtime/helpers_spec.ts @@ -16,6 +16,7 @@ describe('Helpers', () => { id: '', options: undefined, line: 3, + keyword: 'Given', pattern: 'pattern1', uri: 'steps1.js', }), @@ -25,6 +26,7 @@ describe('Helpers', () => { id: '', options: undefined, line: 4, + keyword: 'Given', pattern: 'longer pattern2', uri: 'steps2.js', }), diff --git a/src/support_code_library_builder/index.ts b/src/support_code_library_builder/index.ts index d3754289e..d3619f1ff 100644 --- a/src/support_code_library_builder/index.ts +++ b/src/support_code_library_builder/index.ts @@ -38,7 +38,7 @@ interface IStepDefinitionConfig { code: any line: number options: any - keyword?: GherkinStepKeyword + keyword: GherkinStepKeyword pattern: string | RegExp uri: string } @@ -98,7 +98,6 @@ export class SupportCodeLibraryBuilder { private parallelCanAssign: ParallelAssignmentValidator constructor() { - const defineStep = this.defineStep.bind(this) this.methods = { After: this.defineTestCaseHook( () => this.afterTestCaseHookDefinitionConfigs @@ -119,8 +118,10 @@ export class SupportCodeLibraryBuilder { () => this.beforeTestStepHookDefinitionConfigs ), defineParameterType: this.defineParameterType.bind(this), - defineStep, - Given: defineStep, + // @ts-expect-error todo + defineStep: (...args) => this.defineStep('Given', ...args), + // @ts-expect-error todo + Given: (...args) => this.defineStep('Given', ...args), setDefaultTimeout: (milliseconds) => { this.defaultTimeout = milliseconds }, @@ -133,8 +134,10 @@ export class SupportCodeLibraryBuilder { setParallelCanAssign: (fn: ParallelAssignmentValidator): void => { this.parallelCanAssign = fn }, - Then: defineStep, - When: defineStep, + // @ts-expect-error todo + Then: (...args) => this.defineStep('Then', ...args), + // @ts-expect-error todo + When: (...args) => this.defineStep('When', ...args), } } @@ -163,6 +166,7 @@ export class SupportCodeLibraryBuilder { code, line, options, + keyword, pattern, uri, }) @@ -348,7 +352,7 @@ export class SupportCodeLibraryBuilder { const stepDefinitions: StepDefinition[] = [] const undefinedParameterTypes: messages.UndefinedParameterType[] = [] this.stepDefinitionConfigs.forEach( - ({ code, line, options, pattern, uri }, index) => { + ({ code, line, options, keyword, pattern, uri }, index) => { let expression if (typeof pattern === 'string') { try { @@ -384,6 +388,7 @@ export class SupportCodeLibraryBuilder { id: canonicalIds ? canonicalIds[index] : this.newId(), line, options, + keyword, pattern, unwrappedCode: code, uri, From f3d3c0bd1cc5840d6fbb67ae6c46b916625736cc Mon Sep 17 00:00:00 2001 From: David Goss Date: Sun, 29 May 2022 14:58:14 +0100 Subject: [PATCH 04/12] split out a type for the step function --- src/support_code_library_builder/types.ts | 50 +++++++---------------- 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/src/support_code_library_builder/types.ts b/src/support_code_library_builder/types.ts index a33d2c56c..435c70ace 100644 --- a/src/support_code_library_builder/types.ts +++ b/src/support_code_library_builder/types.ts @@ -70,17 +70,19 @@ export interface IParameterTypeDefinition { preferForRegexpMatch?: boolean } -export interface IDefineSupportCodeMethods { - defineParameterType: (options: IParameterTypeDefinition) => void - defineStep: (( +export type IDefineStepFunction = (( + pattern: DefineStepPattern, + code: TestStepFunction +) => void) & + (( pattern: DefineStepPattern, + options: IDefineStepOptions, code: TestStepFunction - ) => void) & - (( - pattern: DefineStepPattern, - options: IDefineStepOptions, - code: TestStepFunction - ) => void) + ) => void) + +export interface IDefineSupportCodeMethods { + defineParameterType: (options: IParameterTypeDefinition) => void + defineStep: IDefineStepFunction setDefaultTimeout: (milliseconds: number) => void setDefinitionFunctionWrapper: (fn: Function) => void setParallelCanAssign: (fn: ParallelAssignmentValidator) => void @@ -131,33 +133,9 @@ export interface IDefineSupportCodeMethods { ) => void) BeforeAll: ((code: Function) => void) & ((options: IDefineTestRunHookOptions, code: Function) => void) - Given: (( - pattern: DefineStepPattern, - code: TestStepFunction - ) => void) & - (( - pattern: DefineStepPattern, - options: IDefineStepOptions, - code: TestStepFunction - ) => void) - Then: (( - pattern: DefineStepPattern, - code: TestStepFunction - ) => void) & - (( - pattern: DefineStepPattern, - options: IDefineStepOptions, - code: TestStepFunction - ) => void) - When: (( - pattern: DefineStepPattern, - code: TestStepFunction - ) => void) & - (( - pattern: DefineStepPattern, - options: IDefineStepOptions, - code: TestStepFunction - ) => void) + Given: IDefineStepFunction + Then: IDefineStepFunction + When: IDefineStepFunction } export interface ISupportCodeCoordinates { From 43a13db07e63c5d24cbff1cd119137788bdcc839 Mon Sep 17 00:00:00 2001 From: David Goss Date: Sun, 29 May 2022 15:10:38 +0100 Subject: [PATCH 05/12] better implementation --- src/support_code_library_builder/index.ts | 59 ++++++++++++----------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/support_code_library_builder/index.ts b/src/support_code_library_builder/index.ts index d3619f1ff..8e19a46db 100644 --- a/src/support_code_library_builder/index.ts +++ b/src/support_code_library_builder/index.ts @@ -29,6 +29,7 @@ import { TestStepHookFunction, ParallelAssignmentValidator, ISupportCodeCoordinates, + IDefineStepFunction, } from './types' import World from './world' import { ICanonicalSupportCodeIds } from '../runtime/parallel/command_types' @@ -118,10 +119,8 @@ export class SupportCodeLibraryBuilder { () => this.beforeTestStepHookDefinitionConfigs ), defineParameterType: this.defineParameterType.bind(this), - // @ts-expect-error todo - defineStep: (...args) => this.defineStep('Given', ...args), - // @ts-expect-error todo - Given: (...args) => this.defineStep('Given', ...args), + defineStep: this.defineStep('Given', () => this.stepDefinitionConfigs), + Given: this.defineStep('Given', () => this.stepDefinitionConfigs), setDefaultTimeout: (milliseconds) => { this.defaultTimeout = milliseconds }, @@ -134,10 +133,8 @@ export class SupportCodeLibraryBuilder { setParallelCanAssign: (fn: ParallelAssignmentValidator): void => { this.parallelCanAssign = fn }, - // @ts-expect-error todo - Then: (...args) => this.defineStep('Then', ...args), - // @ts-expect-error todo - When: (...args) => this.defineStep('When', ...args), + Then: this.defineStep('Then', () => this.stepDefinitionConfigs), + When: this.defineStep('When', () => this.stepDefinitionConfigs), } } @@ -148,28 +145,32 @@ export class SupportCodeLibraryBuilder { defineStep( keyword: GherkinStepKeyword, - pattern: DefineStepPattern, - options: IDefineStepOptions | Function, - code?: Function - ): void { - if (typeof options === 'function') { - code = options - options = {} + getCollection: () => IStepDefinitionConfig[] + ): IDefineStepFunction { + return ( + pattern: DefineStepPattern, + options: IDefineStepOptions | Function, + code?: Function + ) => { + if (typeof options === 'function') { + code = options + options = {} + } + const { line, uri } = getDefinitionLineAndUri(this.cwd) + validateArguments({ + args: { code, pattern, options }, + fnName: 'defineStep', + location: formatLocation({ line, uri }), + }) + getCollection().push({ + code, + line, + options, + keyword, + pattern, + uri, + }) } - const { line, uri } = getDefinitionLineAndUri(this.cwd) - validateArguments({ - args: { code, pattern, options }, - fnName: 'defineStep', - location: formatLocation({ line, uri }), - }) - this.stepDefinitionConfigs.push({ - code, - line, - options, - keyword, - pattern, - uri, - }) } defineTestCaseHook( From 29ff11e143b476c7d0722a4910d606920fb1b3f3 Mon Sep 17 00:00:00 2001 From: David Goss Date: Sun, 29 May 2022 15:11:03 +0100 Subject: [PATCH 06/12] rename type --- src/support_code_library_builder/index.ts | 4 ++-- src/support_code_library_builder/types.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/support_code_library_builder/index.ts b/src/support_code_library_builder/index.ts index 8e19a46db..3f37dbb32 100644 --- a/src/support_code_library_builder/index.ts +++ b/src/support_code_library_builder/index.ts @@ -29,7 +29,7 @@ import { TestStepHookFunction, ParallelAssignmentValidator, ISupportCodeCoordinates, - IDefineStepFunction, + DefineStepFunction, } from './types' import World from './world' import { ICanonicalSupportCodeIds } from '../runtime/parallel/command_types' @@ -146,7 +146,7 @@ export class SupportCodeLibraryBuilder { defineStep( keyword: GherkinStepKeyword, getCollection: () => IStepDefinitionConfig[] - ): IDefineStepFunction { + ): DefineStepFunction { return ( pattern: DefineStepPattern, options: IDefineStepOptions | Function, diff --git a/src/support_code_library_builder/types.ts b/src/support_code_library_builder/types.ts index 435c70ace..3d697f50d 100644 --- a/src/support_code_library_builder/types.ts +++ b/src/support_code_library_builder/types.ts @@ -70,7 +70,7 @@ export interface IParameterTypeDefinition { preferForRegexpMatch?: boolean } -export type IDefineStepFunction = (( +export type DefineStepFunction = (( pattern: DefineStepPattern, code: TestStepFunction ) => void) & @@ -82,7 +82,7 @@ export type IDefineStepFunction = (( export interface IDefineSupportCodeMethods { defineParameterType: (options: IParameterTypeDefinition) => void - defineStep: IDefineStepFunction + defineStep: DefineStepFunction setDefaultTimeout: (milliseconds: number) => void setDefinitionFunctionWrapper: (fn: Function) => void setParallelCanAssign: (fn: ParallelAssignmentValidator) => void @@ -133,9 +133,9 @@ export interface IDefineSupportCodeMethods { ) => void) BeforeAll: ((code: Function) => void) & ((options: IDefineTestRunHookOptions, code: Function) => void) - Given: IDefineStepFunction - Then: IDefineStepFunction - When: IDefineStepFunction + Given: DefineStepFunction + Then: DefineStepFunction + When: DefineStepFunction } export interface ISupportCodeCoordinates { From baec4e7450d63a1581b6141a99a4435ea5bfae05 Mon Sep 17 00:00:00 2001 From: David Goss Date: Sun, 29 May 2022 15:17:02 +0100 Subject: [PATCH 07/12] update documentation --- docs/support_files/api_reference.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/docs/support_files/api_reference.md b/docs/support_files/api_reference.md index dee006a94..bcce3354c 100644 --- a/docs/support_files/api_reference.md +++ b/docs/support_files/api_reference.md @@ -104,11 +104,11 @@ Multiple `BeforeStep` hooks are executed in the order that they are defined. --- -#### `defineStep(pattern[, options], fn)` +#### `Given(pattern[, options], fn)` -Defines a step. +Define a "Given" step. -Aliases: `Given`, `When`, `Then`. +Aliases: `defineStep` (deprecated and will be removed in a future release; use the appropriate Given/When/Then keyword to define your step). * `pattern`: A regex or string pattern to match against a gherkin step. * `options`: An object with the following keys: @@ -121,12 +121,6 @@ Aliases: `Given`, `When`, `Then`. --- -#### `Given(pattern[, options], fn)` - -Alias of `defineStep`. - ---- - #### `setDefaultTimeout(milliseconds)` Set the default timeout for asynchronous steps. Defaults to `5000` milliseconds. @@ -199,10 +193,10 @@ function World({attach, parameters}) { #### `Then(pattern[, options], fn)` -Alias of `defineStep`. +Define a "Then" step. Same interface as `Given` --- #### `When(pattern[, options], fn)` -Alias of `defineStep`. +Define a "When" step. Same interface as `Given` From b033db3227f6e33e4de94bd67e7279a560d7450e Mon Sep 17 00:00:00 2001 From: David Goss Date: Sun, 29 May 2022 15:19:12 +0100 Subject: [PATCH 08/12] add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8942acbc5..60d76eca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) on how to contribute to Cucumber. ## [Unreleased] +### Changed +- `defineStep` is now deprecated and will eventually be removed; use the appropriate Given/When/Then keyword to define your step ## [8.2.2] - 2022-05-27 ### Changed From 74d16c5db9d2a03b0390366fa76433ca76f369d9 Mon Sep 17 00:00:00 2001 From: David Goss Date: Sun, 29 May 2022 15:23:49 +0100 Subject: [PATCH 09/12] update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60d76eca1..576329497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO ## [Unreleased] ### Changed -- `defineStep` is now deprecated and will eventually be removed; use the appropriate Given/When/Then keyword to define your step +- `defineStep` is now deprecated and will eventually be removed; use the appropriate Given/When/Then keyword to define your step ([#2044](https://github.com/cucumber/cucumber-js/pull/2044)) ## [8.2.2] - 2022-05-27 ### Changed From 2657c5cacdad7f542a4e868922f2c5142c711c1d Mon Sep 17 00:00:00 2001 From: David Goss Date: Mon, 30 May 2022 08:10:34 +0100 Subject: [PATCH 10/12] rename interface for consistency --- src/support_code_library_builder/index.ts | 4 ++-- src/support_code_library_builder/types.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/support_code_library_builder/index.ts b/src/support_code_library_builder/index.ts index 3f37dbb32..f6801e6ed 100644 --- a/src/support_code_library_builder/index.ts +++ b/src/support_code_library_builder/index.ts @@ -29,7 +29,7 @@ import { TestStepHookFunction, ParallelAssignmentValidator, ISupportCodeCoordinates, - DefineStepFunction, + IDefineStep, } from './types' import World from './world' import { ICanonicalSupportCodeIds } from '../runtime/parallel/command_types' @@ -146,7 +146,7 @@ export class SupportCodeLibraryBuilder { defineStep( keyword: GherkinStepKeyword, getCollection: () => IStepDefinitionConfig[] - ): DefineStepFunction { + ): IDefineStep { return ( pattern: DefineStepPattern, options: IDefineStepOptions | Function, diff --git a/src/support_code_library_builder/types.ts b/src/support_code_library_builder/types.ts index 3d697f50d..f9782b52a 100644 --- a/src/support_code_library_builder/types.ts +++ b/src/support_code_library_builder/types.ts @@ -70,7 +70,7 @@ export interface IParameterTypeDefinition { preferForRegexpMatch?: boolean } -export type DefineStepFunction = (( +export type IDefineStep = (( pattern: DefineStepPattern, code: TestStepFunction ) => void) & @@ -82,7 +82,7 @@ export type DefineStepFunction = (( export interface IDefineSupportCodeMethods { defineParameterType: (options: IParameterTypeDefinition) => void - defineStep: DefineStepFunction + defineStep: IDefineStep setDefaultTimeout: (milliseconds: number) => void setDefinitionFunctionWrapper: (fn: Function) => void setParallelCanAssign: (fn: ParallelAssignmentValidator) => void @@ -133,9 +133,9 @@ export interface IDefineSupportCodeMethods { ) => void) BeforeAll: ((code: Function) => void) & ((options: IDefineTestRunHookOptions, code: Function) => void) - Given: DefineStepFunction - Then: DefineStepFunction - When: DefineStepFunction + Given: IDefineStep + Then: IDefineStep + When: IDefineStep } export interface ISupportCodeCoordinates { From 40e8b75c2df768283a1c11d6a38c15759b1461b6 Mon Sep 17 00:00:00 2001 From: David Goss Date: Mon, 30 May 2022 08:18:12 +0100 Subject: [PATCH 11/12] add runtime deprecation warning --- src/support_code_library_builder/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/support_code_library_builder/index.ts b/src/support_code_library_builder/index.ts index f6801e6ed..b732cd385 100644 --- a/src/support_code_library_builder/index.ts +++ b/src/support_code_library_builder/index.ts @@ -8,6 +8,7 @@ import TestRunHookDefinition from '../models/test_run_hook_definition' import StepDefinition from '../models/step_definition' import { formatLocation } from '../formatter/helpers' import validateArguments from './validate_arguments' +import { deprecate } from 'util' import arity from 'util-arity' import { @@ -119,7 +120,10 @@ export class SupportCodeLibraryBuilder { () => this.beforeTestStepHookDefinitionConfigs ), defineParameterType: this.defineParameterType.bind(this), - defineStep: this.defineStep('Given', () => this.stepDefinitionConfigs), + defineStep: deprecate( + this.defineStep('Given', () => this.stepDefinitionConfigs), + '`defineStep` is deprecated, use `Given`, `When` or `Then` instead; see https://github.com/cucumber/cucumber-js/issues/2043' + ), Given: this.defineStep('Given', () => this.stepDefinitionConfigs), setDefaultTimeout: (milliseconds) => { this.defaultTimeout = milliseconds From 32fe53aec99268adf12052c34e485bfc23d3076a Mon Sep 17 00:00:00 2001 From: David Goss Date: Thu, 9 Jun 2022 12:18:36 +0100 Subject: [PATCH 12/12] use Unknown keyword for defineStep --- src/models/gherkin_step_keyword.ts | 2 +- src/support_code_library_builder/index.ts | 2 +- src/support_code_library_builder/index_spec.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/models/gherkin_step_keyword.ts b/src/models/gherkin_step_keyword.ts index 3d5155208..b55c67e37 100644 --- a/src/models/gherkin_step_keyword.ts +++ b/src/models/gherkin_step_keyword.ts @@ -1 +1 @@ -export type GherkinStepKeyword = 'Given' | 'When' | 'Then' +export type GherkinStepKeyword = 'Unknown' | 'Given' | 'When' | 'Then' diff --git a/src/support_code_library_builder/index.ts b/src/support_code_library_builder/index.ts index b732cd385..38ee3e58e 100644 --- a/src/support_code_library_builder/index.ts +++ b/src/support_code_library_builder/index.ts @@ -121,7 +121,7 @@ export class SupportCodeLibraryBuilder { ), defineParameterType: this.defineParameterType.bind(this), defineStep: deprecate( - this.defineStep('Given', () => this.stepDefinitionConfigs), + this.defineStep('Unknown', () => this.stepDefinitionConfigs), '`defineStep` is deprecated, use `Given`, `When` or `Then` instead; see https://github.com/cucumber/cucumber-js/issues/2043' ), Given: this.defineStep('Given', () => this.stepDefinitionConfigs), diff --git a/src/support_code_library_builder/index_spec.ts b/src/support_code_library_builder/index_spec.ts index 263fcc71a..82c2a7d8a 100644 --- a/src/support_code_library_builder/index_spec.ts +++ b/src/support_code_library_builder/index_spec.ts @@ -132,7 +132,7 @@ describe('supportCodeLibraryBuilder', () => { supportCodeLibraryBuilder.methods.defineStep('a thing', step) expect( supportCodeLibraryBuilder.finalize().stepDefinitions[0].keyword - ).to.eq('Given') + ).to.eq('Unknown') }) }) })