-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
parallel_steps.ts
57 lines (54 loc) · 1.99 KB
/
parallel_steps.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
import { DataTable, Then } from '../../'
import { World } from '../support/world'
import messages from '@cucumber/messages'
import { expect } from 'chai'
function getSetsOfPicklesRunningAtTheSameTime(
envelopes: messages.Envelope[]
): string[] {
const pickleIdToName: Record<string, string> = {}
const testCaseIdToPickleId: Record<string, string> = {}
const testCaseStarteIdToPickleId: Record<string, string> = {}
let currentRunningPickleIds: string[] = []
const result: string[] = []
envelopes.forEach((envelope) => {
if (envelope.pickle != null) {
pickleIdToName[envelope.pickle.id] = envelope.pickle.name
} else if (envelope.testCase != null) {
testCaseIdToPickleId[envelope.testCase.id] = envelope.testCase.pickleId
} else if (envelope.testCaseStarted != null) {
const pickleId = testCaseIdToPickleId[envelope.testCaseStarted.testCaseId]
testCaseStarteIdToPickleId[envelope.testCaseStarted.id] = pickleId
currentRunningPickleIds.push(pickleId)
if (currentRunningPickleIds.length > 1) {
const setOfPickleNames = currentRunningPickleIds
.map((x) => pickleIdToName[x])
.sort()
.join(', ')
result.push(setOfPickleNames)
}
} else if (envelope.testCaseFinished != null) {
const pickleId =
testCaseStarteIdToPickleId[envelope.testCaseFinished.testCaseStartedId]
currentRunningPickleIds = currentRunningPickleIds.filter(
(x) => x != pickleId
)
}
})
return result
}
Then('no pickles run at the same time', function (this: World) {
const actualSets = getSetsOfPicklesRunningAtTheSameTime(
this.lastRun.envelopes
)
expect(actualSets).to.eql([])
})
Then(
'the following sets of pickles execute at the same time:',
function (this: World, dataTable: DataTable) {
const expectedSets = dataTable.raw().map((row) => row[0])
const actualSets = getSetsOfPicklesRunningAtTheSameTime(
this.lastRun.envelopes
)
expect(actualSets).to.eql(expectedSets)
}
)