-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathindex.ts
75 lines (68 loc) · 2.34 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { Writable } from 'node:stream'
import { EventEmitter } from 'node:events'
import { SupportCodeLibrary } from '../support_code_library_builder/types'
import { valueOrDefault } from '../value_checker'
import { FormatterPlugin } from '../plugin'
import { IColorFns } from './get_color_fns'
import { EventDataCollector } from './helpers'
import StepDefinitionSnippetBuilder from './step_definition_snippet_builder'
import { SnippetInterface } from './step_definition_snippet_builder/snippet_syntax'
export interface FormatRerunOptions {
separator?: string
}
export interface FormatOptions {
colorsEnabled?: boolean
html?: {
externalAttachments?: boolean
}
rerun?: FormatRerunOptions
snippetInterface?: SnippetInterface
snippetSyntax?: string
printAttachments?: boolean
[customKey: string]: any
}
export type FormatterImplementation = typeof Formatter | FormatterPlugin
export type IFormatterStream = Writable
export type IFormatterLogFn = (buffer: string | Uint8Array) => void
export type IFormatterCleanupFn = () => Promise<any>
export interface IFormatterOptions {
colorFns: IColorFns
cwd: string
eventBroadcaster: EventEmitter
eventDataCollector: EventDataCollector
log: IFormatterLogFn
parsedArgvOptions: FormatOptions
snippetBuilder: StepDefinitionSnippetBuilder
stream: Writable
cleanup: IFormatterCleanupFn
supportCodeLibrary: SupportCodeLibrary
}
export default class Formatter {
protected colorFns: IColorFns
protected cwd: string
protected eventDataCollector: EventDataCollector
protected log: IFormatterLogFn
protected snippetBuilder: StepDefinitionSnippetBuilder
protected stream: Writable
protected supportCodeLibrary: SupportCodeLibrary
protected printAttachments: boolean
private readonly cleanup: IFormatterCleanupFn
static readonly documentation: string
constructor(options: IFormatterOptions) {
this.colorFns = options.colorFns
this.cwd = options.cwd
this.eventDataCollector = options.eventDataCollector
this.log = options.log
this.snippetBuilder = options.snippetBuilder
this.stream = options.stream
this.supportCodeLibrary = options.supportCodeLibrary
this.cleanup = options.cleanup
this.printAttachments = valueOrDefault(
options.parsedArgvOptions.printAttachments,
true
)
}
async finished(): Promise<void> {
await this.cleanup()
}
}