-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
definition.ts
96 lines (84 loc) · 2.32 KB
/
definition.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import * as messages from '@cucumber/messages'
import { ITestCaseHookParameter } from '../support_code_library_builder/types'
import { Expression } from '@cucumber/cucumber-expressions'
export interface IGetInvocationDataRequest {
hookParameter: ITestCaseHookParameter
step: messages.PickleStep
world: any
}
export interface IGetInvocationDataResponse {
getInvalidCodeLengthMessage: () => string
parameters: any[]
validCodeLengths: number[]
}
export interface IDefinitionOptions {
timeout?: number
wrapperOptions?: any
}
export interface IHookDefinitionOptions extends IDefinitionOptions {
name?: string
tags?: string
}
export interface IDefinitionParameters<T extends IDefinitionOptions> {
code: Function
id: string
line: number
options: T
unwrappedCode?: Function
uri: string
}
export interface IStepDefinitionParameters
extends IDefinitionParameters<IDefinitionOptions> {
pattern: string | RegExp
expression: Expression
}
export interface IDefinition {
readonly code: Function
readonly id: string
readonly line: number
readonly options: IDefinitionOptions
readonly unwrappedCode: Function
readonly uri: string
getInvocationParameters: (
options: IGetInvocationDataRequest
) => Promise<IGetInvocationDataResponse>
}
export default abstract class Definition {
public readonly code: Function
public readonly id: string
public readonly line: number
public readonly options: IDefinitionOptions
public readonly unwrappedCode: Function
public readonly uri: string
constructor({
code,
id,
line,
options,
unwrappedCode,
uri,
}: IDefinitionParameters<IDefinitionOptions>) {
this.code = code
this.id = id
this.line = line
this.options = options
this.unwrappedCode = unwrappedCode
this.uri = uri
}
buildInvalidCodeLengthMessage(
syncOrPromiseLength: number | string,
callbackLength: number | string
): string {
return (
`function has ${this.code.length.toString()} arguments` +
`, should have ${syncOrPromiseLength.toString()} (if synchronous or returning a promise)` +
` or ${callbackLength.toString()} (if accepting a callback)`
)
}
baseGetInvalidCodeLengthMessage(parameters: any[]): string {
return this.buildInvalidCodeLengthMessage(
parameters.length,
parameters.length + 1
)
}
}