Skip to content

Commit

Permalink
typescript: fix types for hook functions so they can return 'skipped' (
Browse files Browse the repository at this point in the history
…#1542)

* add failing tsd test

* fix hook function signature

* dont need to install dep on long after all

* update contributing docs

* update changelog
  • Loading branch information
davidjgoss authored Feb 2, 2021
1 parent 6489d97 commit 02fcc4f
Show file tree
Hide file tree
Showing 7 changed files with 679 additions and 18 deletions.
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>
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

0 comments on commit 02fcc4f

Please sign in to comment.