@cucumber/query 13.1.0 → 13.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +1 -0
- package/.prettierrc.json +6 -0
- package/dist/src/Query.d.ts +12 -7
- package/dist/src/Query.d.ts.map +1 -1
- package/dist/src/Query.js +80 -40
- package/dist/src/Query.js.map +1 -1
- package/dist/src/helpers.d.ts +2 -8
- package/dist/src/helpers.d.ts.map +1 -1
- package/dist/src/helpers.js +3 -26
- package/dist/src/helpers.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/eslint.config.mjs +67 -0
- package/package.json +29 -36
- package/src/Query.spec.ts +86 -9
- package/src/Query.ts +127 -70
- package/src/acceptance.spec.ts +236 -160
- package/src/helpers.ts +16 -44
- package/src/helpers.spec.ts +0 -15
package/src/acceptance.spec.ts
CHANGED
|
@@ -1,185 +1,261 @@
|
|
|
1
1
|
import assert from 'node:assert'
|
|
2
2
|
import fs from 'node:fs'
|
|
3
3
|
import * as path from 'node:path'
|
|
4
|
-
import {pipeline, Writable} from 'node:stream'
|
|
4
|
+
import { pipeline, Writable } from 'node:stream'
|
|
5
5
|
import util from 'node:util'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
// eslint-disable-next-line n/no-extraneous-import
|
|
8
|
+
import { NdjsonToMessageStream } from '@cucumber/message-streams'
|
|
9
|
+
import {
|
|
10
|
+
Duration,
|
|
11
|
+
Envelope,
|
|
12
|
+
TestRunFinished,
|
|
13
|
+
TestRunStarted,
|
|
14
|
+
TestStepResultStatus,
|
|
15
|
+
} from '@cucumber/messages'
|
|
16
|
+
import { glob } from 'glob'
|
|
10
17
|
|
|
11
|
-
import Query from './Query'
|
|
12
18
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
namingStrategy,
|
|
20
|
+
NamingStrategyExampleName,
|
|
21
|
+
NamingStrategyFeatureName,
|
|
22
|
+
NamingStrategyLength,
|
|
17
23
|
} from './Lineage'
|
|
24
|
+
import Query from './Query'
|
|
18
25
|
|
|
19
26
|
const asyncPipeline = util.promisify(pipeline)
|
|
20
27
|
const TESTDATA_PATH = path.join(__dirname, '..', '..', 'testdata')
|
|
21
28
|
|
|
22
29
|
describe('Acceptance Tests', async () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (const fixtureFile of fixtureFiles) {
|
|
29
|
-
const [suiteName] = path.basename(fixtureFile).split('.')
|
|
30
|
-
const ndjsonFile = fixtureFile.replace('.query-results.json', '.ndjson')
|
|
30
|
+
const fixtureFiles = glob.sync(`*.query-results.json`, {
|
|
31
|
+
cwd: TESTDATA_PATH,
|
|
32
|
+
absolute: true,
|
|
33
|
+
})
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
for (const fixtureFile of fixtureFiles) {
|
|
36
|
+
const [suiteName] = path.basename(fixtureFile).split('.')
|
|
37
|
+
const ndjsonFile = fixtureFile.replace('.query-results.json', '.ndjson')
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
new NdjsonToMessageStream(),
|
|
38
|
-
new Writable({
|
|
39
|
-
objectMode: true,
|
|
40
|
-
write(envelope: Envelope, _: BufferEncoding, callback) {
|
|
41
|
-
query.update(envelope)
|
|
42
|
-
callback()
|
|
43
|
-
},
|
|
44
|
-
})
|
|
45
|
-
)
|
|
39
|
+
it(suiteName, async () => {
|
|
40
|
+
const query = new Query()
|
|
46
41
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
await asyncPipeline(
|
|
43
|
+
fs.createReadStream(ndjsonFile, { encoding: 'utf-8' }),
|
|
44
|
+
new NdjsonToMessageStream(),
|
|
45
|
+
new Writable({
|
|
46
|
+
objectMode: true,
|
|
47
|
+
write(envelope: Envelope, _: BufferEncoding, callback) {
|
|
48
|
+
query.update(envelope)
|
|
49
|
+
callback()
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
)
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
.map(([feature, testCaseStarteds]) => [feature.name, testCaseStarteds.map(testCaseStarted => testCaseStarted.id)]),
|
|
63
|
-
findAttachmentsBy: query.findAllTestCaseStarted()
|
|
64
|
-
.map(testCaseStarted => query.findTestStepsFinishedBy(testCaseStarted))
|
|
65
|
-
.map(testStepFinisheds => testStepFinisheds.map(testStepFinished => query.findAttachmentsBy(testStepFinished)))
|
|
66
|
-
.flat(2)
|
|
67
|
-
.map(attachment => ([
|
|
68
|
-
attachment.testStepId,
|
|
69
|
-
attachment.testCaseStartedId,
|
|
70
|
-
attachment.mediaType,
|
|
71
|
-
attachment.contentEncoding,
|
|
72
|
-
])),
|
|
73
|
-
findFeatureBy: query.findAllTestCaseStarted()
|
|
74
|
-
.map(testCaseStarted => query.findFeatureBy(testCaseStarted))
|
|
75
|
-
.map(feature => feature?.name),
|
|
76
|
-
findHookBy: query.findAllTestSteps()
|
|
77
|
-
.map(testStep => query.findHookBy(testStep))
|
|
78
|
-
.map(hook => hook?.id)
|
|
79
|
-
.filter(value => !!value),
|
|
80
|
-
findMeta: query.findMeta()?.implementation?.name,
|
|
81
|
-
findMostSevereTestStepResultBy: query.findAllTestCaseStarted()
|
|
82
|
-
.map(testCaseStarted => query.findMostSevereTestStepResultBy(testCaseStarted))
|
|
83
|
-
.map(testStepResult => testStepResult?.status),
|
|
84
|
-
findNameOf: {
|
|
85
|
-
long : query.findAllPickles().map(pickle => query.findNameOf(pickle, namingStrategy(NamingStrategyLength.LONG))),
|
|
86
|
-
excludeFeatureName : query.findAllPickles().map(pickle => query.findNameOf(pickle, namingStrategy(NamingStrategyLength.LONG, NamingStrategyFeatureName.EXCLUDE))),
|
|
87
|
-
longPickleName : query.findAllPickles().map(pickle => query.findNameOf(pickle, namingStrategy(NamingStrategyLength.LONG, NamingStrategyFeatureName.INCLUDE, NamingStrategyExampleName.PICKLE))),
|
|
88
|
-
short : query.findAllPickles().map(pickle => query.findNameOf(pickle, namingStrategy(NamingStrategyLength.SHORT))),
|
|
89
|
-
shortPickleName : query.findAllPickles().map(pickle => query.findNameOf(pickle, namingStrategy(NamingStrategyLength.SHORT, NamingStrategyFeatureName.INCLUDE, NamingStrategyExampleName.PICKLE)))
|
|
90
|
-
},
|
|
91
|
-
findPickleBy: query.findAllTestCaseStarted()
|
|
92
|
-
.map(testCaseStarted => query.findPickleBy(testCaseStarted))
|
|
93
|
-
.map(pickle => pickle?.name),
|
|
94
|
-
findPickleStepBy: query.findAllTestSteps()
|
|
95
|
-
.map(testStep => query.findPickleStepBy(testStep))
|
|
96
|
-
.map(pickleStep => pickleStep?.text)
|
|
97
|
-
.filter(value => !!value),
|
|
98
|
-
findStepBy: query.findAllPickleSteps()
|
|
99
|
-
.map(pickleStep => query.findStepBy(pickleStep))
|
|
100
|
-
.map(step => step?.text),
|
|
101
|
-
findTestCaseBy: query.findAllTestCaseStarted()
|
|
102
|
-
.map(testCaseStarted => query.findTestCaseBy(testCaseStarted))
|
|
103
|
-
.map(testCase => testCase?.id),
|
|
104
|
-
findTestCaseDurationBy: query.findAllTestCaseStarted()
|
|
105
|
-
.map(testCaseStarted => query.findTestCaseDurationBy(testCaseStarted)),
|
|
106
|
-
findTestCaseFinishedBy: query.findAllTestCaseStarted()
|
|
107
|
-
.map(testCaseStarted => query.findTestCaseFinishedBy(testCaseStarted))
|
|
108
|
-
.map(testCaseFinished => testCaseFinished?.testCaseStartedId),
|
|
109
|
-
findTestRunDuration: query.findTestRunDuration(),
|
|
110
|
-
findTestRunFinished: query.findTestRunFinished(),
|
|
111
|
-
findTestRunStarted: query.findTestRunStarted(),
|
|
112
|
-
findTestStepBy: query.findAllTestCaseStarted()
|
|
113
|
-
.flatMap(testCaseStarted => query.findTestStepsFinishedBy(testCaseStarted))
|
|
114
|
-
.map(testStepFinished => query.findTestStepBy(testStepFinished))
|
|
115
|
-
.map(testStep => testStep?.id),
|
|
116
|
-
findTestStepsFinishedBy: query.findAllTestCaseStarted()
|
|
117
|
-
.map(testCaseStarted => query.findTestStepsFinishedBy(testCaseStarted))
|
|
118
|
-
.map(testStepFinisheds => testStepFinisheds.map(testStepFinished => testStepFinished?.testStepId)),
|
|
119
|
-
findTestStepFinishedAndTestStepBy: query.findAllTestCaseStarted()
|
|
120
|
-
.flatMap(testCaseStarted => query.findTestStepFinishedAndTestStepBy(testCaseStarted))
|
|
121
|
-
.map(([testStepFinished, testStep]) => ([testStepFinished.testStepId, testStep.id]))
|
|
122
|
-
}))
|
|
54
|
+
const expectedResults: ResultsFixture = {
|
|
55
|
+
...defaults,
|
|
56
|
+
...JSON.parse(
|
|
57
|
+
fs.readFileSync(fixtureFile, {
|
|
58
|
+
encoding: 'utf-8',
|
|
59
|
+
})
|
|
60
|
+
),
|
|
61
|
+
}
|
|
123
62
|
|
|
124
|
-
|
|
63
|
+
const actualResults: ResultsFixture = JSON.parse(
|
|
64
|
+
JSON.stringify({
|
|
65
|
+
countMostSevereTestStepResultStatus: query.countMostSevereTestStepResultStatus(),
|
|
66
|
+
countTestCasesStarted: query.countTestCasesStarted(),
|
|
67
|
+
findAllPickles: query.findAllPickles().length,
|
|
68
|
+
findAllPickleSteps: query.findAllPickleSteps().length,
|
|
69
|
+
findAllTestCaseStarted: query.findAllTestCaseStarted().length,
|
|
70
|
+
findAllTestSteps: query.findAllTestSteps().length,
|
|
71
|
+
findAllTestCaseStartedGroupedByFeature: [
|
|
72
|
+
...query.findAllTestCaseStartedGroupedByFeature().entries(),
|
|
73
|
+
].map(([feature, testCaseStarteds]) => [
|
|
74
|
+
feature.name,
|
|
75
|
+
testCaseStarteds.map((testCaseStarted) => testCaseStarted.id),
|
|
76
|
+
]),
|
|
77
|
+
findAttachmentsBy: query
|
|
78
|
+
.findAllTestCaseStarted()
|
|
79
|
+
.map((testCaseStarted) => query.findTestStepsFinishedBy(testCaseStarted))
|
|
80
|
+
.map((testStepFinisheds) =>
|
|
81
|
+
testStepFinisheds.map((testStepFinished) => query.findAttachmentsBy(testStepFinished))
|
|
82
|
+
)
|
|
83
|
+
.flat(2)
|
|
84
|
+
.map((attachment) => [
|
|
85
|
+
attachment.testStepId,
|
|
86
|
+
attachment.testCaseStartedId,
|
|
87
|
+
attachment.mediaType,
|
|
88
|
+
attachment.contentEncoding,
|
|
89
|
+
]),
|
|
90
|
+
findFeatureBy: query
|
|
91
|
+
.findAllTestCaseStarted()
|
|
92
|
+
.map((testCaseStarted) => query.findFeatureBy(testCaseStarted))
|
|
93
|
+
.map((feature) => feature?.name),
|
|
94
|
+
findHookBy: query
|
|
95
|
+
.findAllTestSteps()
|
|
96
|
+
.map((testStep) => query.findHookBy(testStep))
|
|
97
|
+
.map((hook) => hook?.id)
|
|
98
|
+
.filter((value) => !!value),
|
|
99
|
+
findMeta: query.findMeta()?.implementation?.name,
|
|
100
|
+
findMostSevereTestStepResultBy: query
|
|
101
|
+
.findAllTestCaseStarted()
|
|
102
|
+
.map((testCaseStarted) => query.findMostSevereTestStepResultBy(testCaseStarted))
|
|
103
|
+
.map((testStepResult) => testStepResult?.status),
|
|
104
|
+
findNameOf: {
|
|
105
|
+
long: query
|
|
106
|
+
.findAllPickles()
|
|
107
|
+
.map((pickle) => query.findNameOf(pickle, namingStrategy(NamingStrategyLength.LONG))),
|
|
108
|
+
excludeFeatureName: query
|
|
109
|
+
.findAllPickles()
|
|
110
|
+
.map((pickle) =>
|
|
111
|
+
query.findNameOf(
|
|
112
|
+
pickle,
|
|
113
|
+
namingStrategy(NamingStrategyLength.LONG, NamingStrategyFeatureName.EXCLUDE)
|
|
114
|
+
)
|
|
115
|
+
),
|
|
116
|
+
longPickleName: query
|
|
117
|
+
.findAllPickles()
|
|
118
|
+
.map((pickle) =>
|
|
119
|
+
query.findNameOf(
|
|
120
|
+
pickle,
|
|
121
|
+
namingStrategy(
|
|
122
|
+
NamingStrategyLength.LONG,
|
|
123
|
+
NamingStrategyFeatureName.INCLUDE,
|
|
124
|
+
NamingStrategyExampleName.PICKLE
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
),
|
|
128
|
+
short: query
|
|
129
|
+
.findAllPickles()
|
|
130
|
+
.map((pickle) =>
|
|
131
|
+
query.findNameOf(pickle, namingStrategy(NamingStrategyLength.SHORT))
|
|
132
|
+
),
|
|
133
|
+
shortPickleName: query
|
|
134
|
+
.findAllPickles()
|
|
135
|
+
.map((pickle) =>
|
|
136
|
+
query.findNameOf(
|
|
137
|
+
pickle,
|
|
138
|
+
namingStrategy(
|
|
139
|
+
NamingStrategyLength.SHORT,
|
|
140
|
+
NamingStrategyFeatureName.INCLUDE,
|
|
141
|
+
NamingStrategyExampleName.PICKLE
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
),
|
|
145
|
+
},
|
|
146
|
+
findLocationOf: query.findAllPickles().map((pickle) => query.findLocationOf(pickle)),
|
|
147
|
+
findPickleBy: query
|
|
148
|
+
.findAllTestCaseStarted()
|
|
149
|
+
.map((testCaseStarted) => query.findPickleBy(testCaseStarted))
|
|
150
|
+
.map((pickle) => pickle?.name),
|
|
151
|
+
findPickleStepBy: query
|
|
152
|
+
.findAllTestSteps()
|
|
153
|
+
.map((testStep) => query.findPickleStepBy(testStep))
|
|
154
|
+
.map((pickleStep) => pickleStep?.text)
|
|
155
|
+
.filter((value) => !!value),
|
|
156
|
+
findStepBy: query
|
|
157
|
+
.findAllPickleSteps()
|
|
158
|
+
.map((pickleStep) => query.findStepBy(pickleStep))
|
|
159
|
+
.map((step) => step?.text),
|
|
160
|
+
findTestCaseBy: query
|
|
161
|
+
.findAllTestCaseStarted()
|
|
162
|
+
.map((testCaseStarted) => query.findTestCaseBy(testCaseStarted))
|
|
163
|
+
.map((testCase) => testCase?.id),
|
|
164
|
+
findTestCaseDurationBy: query
|
|
165
|
+
.findAllTestCaseStarted()
|
|
166
|
+
.map((testCaseStarted) => query.findTestCaseDurationBy(testCaseStarted)),
|
|
167
|
+
findTestCaseFinishedBy: query
|
|
168
|
+
.findAllTestCaseStarted()
|
|
169
|
+
.map((testCaseStarted) => query.findTestCaseFinishedBy(testCaseStarted))
|
|
170
|
+
.map((testCaseFinished) => testCaseFinished?.testCaseStartedId),
|
|
171
|
+
findTestRunDuration: query.findTestRunDuration(),
|
|
172
|
+
findTestRunFinished: query.findTestRunFinished(),
|
|
173
|
+
findTestRunStarted: query.findTestRunStarted(),
|
|
174
|
+
findTestStepByTestStepStarted: query
|
|
175
|
+
.findAllTestCaseStarted()
|
|
176
|
+
.flatMap((testCaseStarted) => query.findTestStepsStartedBy(testCaseStarted))
|
|
177
|
+
.map((testStepStarted) => query.findTestStepBy(testStepStarted))
|
|
178
|
+
.map((testStep) => testStep?.id),
|
|
179
|
+
findTestStepByTestStepFinished: query
|
|
180
|
+
.findAllTestCaseStarted()
|
|
181
|
+
.flatMap((testCaseStarted) => query.findTestStepsFinishedBy(testCaseStarted))
|
|
182
|
+
.map((testStepFinished) => query.findTestStepBy(testStepFinished))
|
|
183
|
+
.map((testStep) => testStep?.id),
|
|
184
|
+
findTestStepsFinishedBy: query
|
|
185
|
+
.findAllTestCaseStarted()
|
|
186
|
+
.map((testCaseStarted) => query.findTestStepsFinishedBy(testCaseStarted))
|
|
187
|
+
.map((testStepFinisheds) =>
|
|
188
|
+
testStepFinisheds.map((testStepFinished) => testStepFinished?.testStepId)
|
|
189
|
+
),
|
|
190
|
+
findTestStepFinishedAndTestStepBy: query
|
|
191
|
+
.findAllTestCaseStarted()
|
|
192
|
+
.flatMap((testCaseStarted) => query.findTestStepFinishedAndTestStepBy(testCaseStarted))
|
|
193
|
+
.map(([testStepFinished, testStep]) => [testStepFinished.testStepId, testStep.id]),
|
|
125
194
|
})
|
|
126
|
-
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
assert.deepStrictEqual(actualResults, expectedResults)
|
|
198
|
+
})
|
|
199
|
+
}
|
|
127
200
|
})
|
|
128
201
|
|
|
129
202
|
interface ResultsFixture {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
203
|
+
countMostSevereTestStepResultStatus: Record<TestStepResultStatus, number>
|
|
204
|
+
countTestCasesStarted: number
|
|
205
|
+
findAllPickles: number
|
|
206
|
+
findAllPickleSteps: number
|
|
207
|
+
findAllTestCaseStarted: number
|
|
208
|
+
findAllTestSteps: number
|
|
209
|
+
findAllTestCaseStartedGroupedByFeature: Array<[string, string[]]>
|
|
210
|
+
findAttachmentsBy: Array<[string, string, string, string]>
|
|
211
|
+
findFeatureBy: Array<string>
|
|
212
|
+
findMeta: string
|
|
213
|
+
findMostSevereTestStepResultBy: Array<TestStepResultStatus>
|
|
214
|
+
findNameOf: {
|
|
215
|
+
long: Array<string>
|
|
216
|
+
excludeFeatureName: Array<string>
|
|
217
|
+
longPickleName: Array<string>
|
|
218
|
+
short: Array<string>
|
|
219
|
+
shortPickleName: Array<string>
|
|
220
|
+
}
|
|
221
|
+
findLocationOf: Array<Location>
|
|
222
|
+
findHookBy: Array<string>
|
|
223
|
+
findPickleBy: Array<string>
|
|
224
|
+
findPickleStepBy: Array<string>
|
|
225
|
+
findStepBy: Array<string>
|
|
226
|
+
findTestCaseBy: Array<string>
|
|
227
|
+
findTestCaseDurationBy: Array<Duration>
|
|
228
|
+
findTestCaseFinishedBy: Array<string>
|
|
229
|
+
findTestRunDuration: Duration
|
|
230
|
+
findTestRunFinished: TestRunFinished
|
|
231
|
+
findTestRunStarted: TestRunStarted
|
|
232
|
+
findTestStepByTestStepStarted: Array<string>
|
|
233
|
+
findTestStepByTestStepFinished: Array<string>
|
|
234
|
+
findTestStepsFinishedBy: Array<Array<string>>
|
|
235
|
+
findTestStepFinishedAndTestStepBy: Array<[string, string]>
|
|
161
236
|
}
|
|
162
237
|
|
|
163
238
|
const defaults: Partial<ResultsFixture> = {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
239
|
+
findAllTestCaseStartedGroupedByFeature: [],
|
|
240
|
+
findAttachmentsBy: [],
|
|
241
|
+
findFeatureBy: [],
|
|
242
|
+
findMostSevereTestStepResultBy: [],
|
|
243
|
+
findNameOf: {
|
|
244
|
+
long: [],
|
|
245
|
+
excludeFeatureName: [],
|
|
246
|
+
longPickleName: [],
|
|
247
|
+
short: [],
|
|
248
|
+
shortPickleName: [],
|
|
249
|
+
},
|
|
250
|
+
findHookBy: [],
|
|
251
|
+
findPickleBy: [],
|
|
252
|
+
findPickleStepBy: [],
|
|
253
|
+
findStepBy: [],
|
|
254
|
+
findTestCaseBy: [],
|
|
255
|
+
findTestCaseDurationBy: [],
|
|
256
|
+
findTestCaseFinishedBy: [],
|
|
257
|
+
findTestStepByTestStepStarted: [],
|
|
258
|
+
findTestStepByTestStepFinished: [],
|
|
259
|
+
findTestStepsFinishedBy: [],
|
|
260
|
+
findTestStepFinishedAndTestStepBy: [],
|
|
261
|
+
}
|
package/src/helpers.ts
CHANGED
|
@@ -1,49 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TestStepResultStatus } from '@cucumber/messages'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return -1;
|
|
14
|
-
}
|
|
15
|
-
if ( a[key] > b[key] ){
|
|
16
|
-
return 1;
|
|
17
|
-
}
|
|
18
|
-
return 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function comparatorByStatus(a: TestStepResult, b: TestStepResult) {
|
|
22
|
-
if (ordinal(a.status) < ordinal(b.status)) {
|
|
23
|
-
return -1;
|
|
24
|
-
}
|
|
25
|
-
if (ordinal(a.status) > ordinal(b.status) ){
|
|
26
|
-
return 1;
|
|
27
|
-
}
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function ordinal(status: TestStepResultStatus) {
|
|
32
|
-
return [
|
|
33
|
-
TestStepResultStatus.UNKNOWN,
|
|
34
|
-
TestStepResultStatus.PASSED,
|
|
35
|
-
TestStepResultStatus.SKIPPED,
|
|
36
|
-
TestStepResultStatus.PENDING,
|
|
37
|
-
TestStepResultStatus.UNDEFINED,
|
|
38
|
-
TestStepResultStatus.AMBIGUOUS,
|
|
39
|
-
TestStepResultStatus.FAILED,
|
|
40
|
-
].indexOf(status)
|
|
3
|
+
export function statusOrdinal(status: TestStepResultStatus) {
|
|
4
|
+
return [
|
|
5
|
+
TestStepResultStatus.UNKNOWN,
|
|
6
|
+
TestStepResultStatus.PASSED,
|
|
7
|
+
TestStepResultStatus.SKIPPED,
|
|
8
|
+
TestStepResultStatus.PENDING,
|
|
9
|
+
TestStepResultStatus.UNDEFINED,
|
|
10
|
+
TestStepResultStatus.AMBIGUOUS,
|
|
11
|
+
TestStepResultStatus.FAILED,
|
|
12
|
+
].indexOf(status)
|
|
41
13
|
}
|
|
42
14
|
|
|
43
15
|
export const assert = {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
16
|
+
ok(target: unknown, message: string) {
|
|
17
|
+
if (!target) {
|
|
18
|
+
throw new Error(message)
|
|
48
19
|
}
|
|
49
|
-
}
|
|
20
|
+
},
|
|
21
|
+
}
|
package/src/helpers.spec.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert'
|
|
2
|
-
import { comparatorByStatus } from './helpers'
|
|
3
|
-
import { TestStepResult, TestStepResultStatus } from '@cucumber/messages'
|
|
4
|
-
|
|
5
|
-
describe('comparatorByStatus', () => {
|
|
6
|
-
function resultWithStatus(status: TestStepResultStatus) {
|
|
7
|
-
return { status } as TestStepResult
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
it('puts the more severe status after the less severe', () => {
|
|
11
|
-
assert.strictEqual(comparatorByStatus(resultWithStatus(TestStepResultStatus.PASSED), resultWithStatus(TestStepResultStatus.FAILED)), -1)
|
|
12
|
-
assert.strictEqual(comparatorByStatus(resultWithStatus(TestStepResultStatus.FAILED), resultWithStatus(TestStepResultStatus.PASSED)), 1)
|
|
13
|
-
assert.strictEqual(comparatorByStatus(resultWithStatus(TestStepResultStatus.FAILED), resultWithStatus(TestStepResultStatus.FAILED)), 0)
|
|
14
|
-
})
|
|
15
|
-
})
|