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

fix: end html formatter stream at appropriate time #2233

Merged
merged 4 commits into from
Feb 11, 2023
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
- Exit correctly when there's a Gherkin parse failure [#2233](https://github.com/cucumber/cucumber-js/pull/2233)

## [8.11.0] - 2023-02-10
### Added
Expand Down
10 changes: 10 additions & 0 deletions features/gherkin_parse_failure.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,13 @@ Feature: Gherkin parse failure
| pickle | 1 |
| parseError | 2 |

Scenario: Formatters handle the truncated test run
Given a file named "features/a.feature" with:
"""
Feature: a feature name
Scenario: a scenario name
Given a step
Parse Error
"""
When I run cucumber-js with all formatters
Then it fails
16 changes: 6 additions & 10 deletions src/formatter/html_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,30 @@ import Formatter, { IFormatterOptions } from '.'
import * as messages from '@cucumber/messages'
import resolvePkg from 'resolve-pkg'
import CucumberHtmlStream from '@cucumber/html-formatter'
import { doesHaveValue } from '../value_checker'
import { finished } from 'stream'
import { promisify } from 'util'

export default class HtmlFormatter extends Formatter {
private readonly _finished: Promise<void>
private readonly _htmlStream: CucumberHtmlStream
public static readonly documentation: string = 'Outputs HTML report'

constructor(options: IFormatterOptions) {
super(options)
const cucumberHtmlStream = new CucumberHtmlStream(
this._htmlStream = new CucumberHtmlStream(
resolvePkg('@cucumber/html-formatter', { cwd: __dirname }) +
'/dist/main.css',
resolvePkg('@cucumber/html-formatter', { cwd: __dirname }) +
'/dist/main.js'
)
options.eventBroadcaster.on('envelope', (envelope: messages.Envelope) => {
cucumberHtmlStream.write(envelope)
if (doesHaveValue(envelope.testRunFinished)) {
cucumberHtmlStream.end()
}
this._htmlStream.write(envelope)
})
cucumberHtmlStream.on('data', (chunk) => this.log(chunk))
this._finished = promisify(finished)(cucumberHtmlStream)
this._htmlStream.on('data', (chunk) => this.log(chunk))
}

async finished(): Promise<void> {
await this._finished
this._htmlStream.end()
await promisify(finished)(this._htmlStream)
await super.finished()
}
}