Skip to content

Commit fd3c931

Browse files
committed
implement ProgressPrinter
1 parent bf91cbb commit fd3c931

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

javascript/src/ProgressPrinter.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
1-
import { Envelope, TestRunFinished } from '@cucumber/messages'
1+
import { Envelope } from '@cucumber/messages'
22
import { Query } from '@cucumber/query'
33

4+
import { formatStatusCharacter } from './helpers.js'
45
import type { Options } from './types.js'
56

67
export class ProgressPrinter {
7-
private readonly println: (content?: string) => void
88
private readonly query: Query = new Query()
99

1010
constructor(
1111
private readonly stream: NodeJS.WritableStream,
1212
private readonly print: (content: string) => void,
1313
private readonly options: Required<Options>
14-
) {
15-
this.println = (content: string = '') => this.print(`${content}\n`)
16-
}
14+
) {}
1715

1816
update(message: Envelope) {
1917
this.query.update(message)
2018

21-
if (message.testRunFinished) {
22-
this.handleTestRunFinished(message.testRunFinished)
19+
if (message.testStepFinished) {
20+
this.print(
21+
formatStatusCharacter(
22+
message.testStepFinished.testStepResult.status,
23+
this.options.theme,
24+
this.stream
25+
)
26+
)
2327
}
24-
}
2528

26-
private handleTestRunFinished(testRunFinished: TestRunFinished) {
27-
this.println('Progress!')
29+
if (message.testRunHookFinished) {
30+
this.print(
31+
formatStatusCharacter(
32+
message.testRunHookFinished.result.status,
33+
this.options.theme,
34+
this.stream
35+
)
36+
)
37+
}
38+
39+
if (message.testRunFinished) {
40+
this.print('\n')
41+
}
2842
}
29-
}
43+
}

javascript/src/helpers.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ export const GHERKIN_INDENT_LENGTH = 2
2626
export const STEP_ARGUMENT_INDENT_LENGTH = 2
2727
export const ATTACHMENT_INDENT_LENGTH = 4
2828
export const ERROR_INDENT_LENGTH = 4
29+
const STATUS_CHARACTERS: Record<TestStepResultStatus, string> = {
30+
[TestStepResultStatus.AMBIGUOUS]: 'A',
31+
[TestStepResultStatus.FAILED]: 'F',
32+
[TestStepResultStatus.PASSED]: '.',
33+
[TestStepResultStatus.PENDING]: 'P',
34+
[TestStepResultStatus.SKIPPED]: '-',
35+
[TestStepResultStatus.UNDEFINED]: 'U',
36+
[TestStepResultStatus.UNKNOWN]: '?',
37+
} as const
2938

3039
export function ensure<T>(value: T | undefined, message: string): T {
3140
if (!value) {
@@ -307,3 +316,12 @@ function formatBase64Attachment(
307316
function formatTextAttachment(content: string, theme: Theme, stream: NodeJS.WritableStream) {
308317
return new TextBuilder(stream).append(content).build(theme.attachment)
309318
}
319+
320+
export function formatStatusCharacter(
321+
status: TestStepResultStatus,
322+
theme: Theme,
323+
stream: NodeJS.WritableStream
324+
) {
325+
const character = STATUS_CHARACTERS[status]
326+
return new TextBuilder(stream).append(character).build(theme.status?.all?.[status])
327+
}

0 commit comments

Comments
 (0)