Skip to content
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

typescript: fix types for hook functions so they can return 'skipped' #1542

Merged
merged 6 commits into from
Feb 2, 2021
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 @@ -21,6 +21,8 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO

### Fixed

* Fix types for hook functions so they can return e.g. `'skipped'` ([#1542](https://github.com/cucumber/cucumber-js/pull/1542))

## [7.0.0] (2020-12-21)

### Added
Expand Down
14 changes: 9 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ Before anything else, thank you. Thank you for taking some of your precious time

## Tests

See the `package.json` scripts section for how to run the tests.
See the `package.json` scripts section for how to run each category of tests.

* lint
* lint - `yarn lint`
* [prettier](https://github.com/prettier/prettier)
* [eslint](https://eslint.org/)
* [dependency-lint](https://github.com/charlierudolph/dependency-lint)
* unit tests
* typescript tests - `yarn types-test`
* [tsd](https://github.com/SamVerschueren/tsd)
* unit tests - `yarn unit-test`
* [mocha](https://mochajs.org/)
* [chai](https://www.chaijs.com/)
* [sinon](https://sinonjs.org/)
* feature tests
* compatibility kit - `yarn cck-test`
* checking that cucumber-js emits the [correct messages](https://github.com/cucumber/cucumber/tree/master/compatibility-kit)
* feature tests - `yarn feature-test`
* cucumber-js tests itself

## Internals
Expand All @@ -45,7 +49,7 @@ The runtime emits events with an [EventEmitter](https://nodejs.org/api/events.ht
### Coding style

* Promises and ES7 async/await
* Try to make things as unit testable as possible. If its hard to unit test, the class/function may be doing too much.
* Try to make things as unit testable as possible. If it's hard to unit test, the class/function may be doing too much.

## Changelog

Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"stream-buffers": "3.0.2",
"stream-to-string": "1.2.0",
"ts-node": "9.1.1",
"tsd": "^0.14.0",
"typescript": "4.1.3"
},
"scripts": {
Expand All @@ -268,11 +269,18 @@
"prefeature-test": "yarn run build-local",
"prepublishOnly": "rm -rf lib && npm run build-local",
"pretest-coverage": "yarn build-local",
"pretypes-test": "yarn build-local",
"test-coverage": "nyc --silent mocha 'src/**/*_spec.ts' 'compatibility/**/*_spec.ts' && nyc --silent --no-clean node ./bin/cucumber-js && nyc report --reporter=lcov",
"test": "yarn run lint && yarn run unit-test && yarn run cck-test && yarn run feature-test",
"test": "yarn run lint && yarn run types-test && yarn run unit-test && yarn run cck-test && yarn run feature-test",
"types-test": "tsd",
"unit-test": "mocha 'src/**/*_spec.ts'",
"update-dependencies": "npx npm-check-updates --upgrade"
},
"tsd": {
"compilerOptions": {
"types": ["long"]
}
},
"bin": {
"cucumber-js": "./bin/cucumber-js"
},
Expand Down
4 changes: 2 additions & 2 deletions src/support_code_library_builder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export interface ITestStepHookParameter {
testStepId: string
}

export type TestCaseHookFunctionWithoutParameter = () => void | Promise<void>
export type TestCaseHookFunctionWithoutParameter = () => any | Promise<any>
export type TestCaseHookFunctionWithParameter = (
arg: ITestCaseHookParameter
) => void | Promise<void>
) => any | Promise<any>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any is obviously a bit broad but I think it's faithful to the API, in the sense that you can return/resolve anything you want from a hook or step function, but skipped and pending have special meaning.

export type TestCaseHookFunction =
| TestCaseHookFunctionWithoutParameter
| TestCaseHookFunctionWithParameter
Expand Down
9 changes: 9 additions & 0 deletions test-d/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { After, Before } from '../'

Before(async function () {
return 'skipped'
})

After(async function () {
return 'skipped'
})
15 changes: 15 additions & 0 deletions test-d/steps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Given, When, Then } from '../'

Given('some context', async function () {})

When('an action context', async function () {})

Then('verification', async function () {})

Given('a step that will be skipped', async function () {
return 'skipped'
})

Given('a step that we need to implement', async function () {
return 'pending'
})
Loading