-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgiven-after-background.ts
36 lines (29 loc) · 1.04 KB
/
given-after-background.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
import { switchOrSeveritySchema } from '../schemas'
import Schema from '../schema'
import Rule from '../rule'
import { RawSchema, AcceptedSchema } from '../types'
import Document from '../document'
export default class GivenAfterBackground implements Rule {
public readonly name: string = 'given-after-background'
public readonly acceptedSchema: AcceptedSchema = switchOrSeveritySchema
public readonly schema: Schema
public constructor(rawSchema: RawSchema) {
this.schema = new Schema(rawSchema)
}
public async run(document: Document): Promise<void> {
const backgrounds = document.feature.children.filter((child) => child.background !== undefined)
if (!backgrounds.length) {
return
}
document.feature.children.forEach((child): void => {
if (!child.scenario) {
return
}
child.scenario.steps.forEach((step): void => {
if (step.keyword.trim() === 'Given') {
document.addError(this, 'Found "Given" in scenario when background exists.', step.location)
}
})
})
}
}