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

docs: add info about testing custom formatters #2069

Merged
merged 1 commit into from
Jun 29, 2022
Merged
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
6 changes: 6 additions & 0 deletions docs/custom_formatters.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ The base `Formatter` does very little aside from saving some of the options on t

If there is any other formatter functionality you would like access to, please create an [issue](https://github.com/cucumber/cucumber-js).

## Testing

To test your formatter with a good degree of confidence, you probably want to run Cucumber with a predefined set of features and support code, and then assert that the output from your formatter is what you'd expect.

We take this approach with the official [`@cucumber/pretty-formatter`](https://github.com/cucumber/cucumber-js-pretty-formatter), using the [JavaScript API](./javascript_api.md) to run Cucumber in-process and grabbing the result from its `stdout` to compare against a fixture file. Take a look at [the `run` helper function](https://github.com/cucumber/cucumber-js-pretty-formatter/blob/main/test/exec.ts#L19) for some hints on how to go about this.

## Distribution

If you want to share your formatter with other users, [publish it as an npm package](https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry) and make sure your formatter class is the default export of the entry point defined in `package.json` - that way users will be able to just reference it by the package name when running cucumber-js, once they've added it as a dependency.