Skip to content

fix return type of step hook function to allow async #2038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
### Fixed
- Fix return type of step hook function to allow async functions ([#2038](https://github.com/cucumber/cucumber-js/pull/2038))

## [8.2.0] - 2022-05-05
### Changed
Expand Down
3 changes: 1 addition & 2 deletions features/support/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { After, Before, formatterHelpers } from '../../'
import { After, Before, formatterHelpers, ITestCaseHookParameter } from '../../'
import fs from 'fs'
import fsExtra from 'fs-extra'
import path from 'path'
import tmp from 'tmp'
import { doesHaveValue } from '../../src/value_checker'
import { World } from './world'
import { ITestCaseHookParameter } from '../../src/support_code_library_builder/types'
import { warnUserAboutEnablingDeveloperMode } from './warn_user_about_enabling_developer_mode'

const projectPath = path.join(__dirname, '..', '..')
Expand Down
2 changes: 1 addition & 1 deletion src/support_code_library_builder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type TestCaseHookFunction<WorldType> = (
export type TestStepHookFunction<WorldType> = (
this: WorldType,
arg: ITestStepHookParameter
) => void
) => any | Promise<any>

export type TestStepFunction<WorldType> = (
this: WorldType,
Expand Down
8 changes: 8 additions & 0 deletions test-d/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ After(function () {})
BeforeStep(function () {})
AfterStep(function () {})

// should allow hook functions to be async
BeforeAll(async function () {})
AfterAll(async function () {})
Before(async function () {})
After(async function () {})
BeforeStep(async function () {})
AfterStep(async function () {})

// should allow typed arguments in hooks
Before(function (param: ITestCaseHookParameter) {})
After(function (param: ITestCaseHookParameter) {})
Expand Down