@cucumber/query 13.5.0 → 14.0.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.
@@ -6,270 +6,231 @@ import util from 'node:util'
6
6
 
7
7
  // eslint-disable-next-line n/no-extraneous-import
8
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'
9
+ import { Envelope } from '@cucumber/messages'
17
10
 
18
- import {
19
- namingStrategy,
20
- NamingStrategyExampleName,
21
- NamingStrategyFeatureName,
22
- NamingStrategyLength,
23
- } from './Lineage'
24
11
  import Query from './Query'
25
12
 
26
13
  const asyncPipeline = util.promisify(pipeline)
27
- const TESTDATA_PATH = path.join(__dirname, '..', '..', 'testdata')
28
14
 
29
15
  describe('Acceptance Tests', async () => {
30
- const fixtureFiles = glob.sync(`*.query-results.json`, {
31
- cwd: TESTDATA_PATH,
32
- absolute: true,
33
- })
34
-
35
- for (const fixtureFile of fixtureFiles) {
36
- const [suiteName] = path.basename(fixtureFile).split('.')
37
- const ndjsonFile = fixtureFile.replace('.query-results.json', '.ndjson')
16
+ const sources = [
17
+ path.join(__dirname, '../../testdata/src/attachments.ndjson'),
18
+ path.join(__dirname, '../../testdata/src/empty.ndjson'),
19
+ path.join(__dirname, '../../testdata/src/hooks.ndjson'),
20
+ path.join(__dirname, '../../testdata/src/minimal.ndjson'),
21
+ path.join(__dirname, '../../testdata/src/rules.ndjson'),
22
+ path.join(__dirname, '../../testdata/src/examples-tables.ndjson'),
23
+ ]
24
+ const queries: Queries = {
25
+ countMostSevereTestStepResultStatus: (query: Query) =>
26
+ query.countMostSevereTestStepResultStatus(),
27
+ countTestCasesStarted: (query: Query) => query.countTestCasesStarted(),
28
+ findAllPickles: (query: Query) => query.findAllPickles().length,
29
+ findAllPickleSteps: (query: Query) => query.findAllPickleSteps().length,
30
+ findAllTestCaseStarted: (query: Query) => query.findAllTestCaseStarted().length,
31
+ findAllTestSteps: (query: Query) => query.findAllTestSteps().length,
32
+ findAttachmentsBy: (query: Query) =>
33
+ query
34
+ .findAllTestCaseStarted()
35
+ .map((testCaseStarted) => query.findTestStepsFinishedBy(testCaseStarted))
36
+ .map((testStepFinisheds) =>
37
+ testStepFinisheds.map((testStepFinished) => query.findAttachmentsBy(testStepFinished))
38
+ )
39
+ .flat(2)
40
+ .map((attachment) => [
41
+ attachment.testStepId,
42
+ attachment.testCaseStartedId,
43
+ attachment.mediaType,
44
+ attachment.contentEncoding,
45
+ ]),
46
+ findHookBy: (query: Query) =>
47
+ query
48
+ .findAllTestSteps()
49
+ .map((testStep) => query.findHookBy(testStep))
50
+ .map((hook) => hook?.id)
51
+ .filter((value) => !!value),
52
+ findMeta: (query: Query) => query.findMeta()?.implementation?.name,
53
+ findMostSevereTestStepResultBy: (query: Query) => {
54
+ return {
55
+ testCaseStarted: query
56
+ .findAllTestCaseStarted()
57
+ .map((testCaseStarted) => query.findMostSevereTestStepResultBy(testCaseStarted))
58
+ .map((testStepResult) => testStepResult?.status)
59
+ .filter((value) => value),
60
+ testCaseFinished: query
61
+ .findAllTestCaseFinished()
62
+ .map((testCaseStarted) => query.findMostSevereTestStepResultBy(testCaseStarted))
63
+ .map((testStepResult) => testStepResult?.status)
64
+ .filter((value) => value),
65
+ }
66
+ },
67
+ findLocationOf: (query: Query) =>
68
+ query.findAllPickles().map((pickle) => query.findLocationOf(pickle)),
69
+ findPickleBy: (query: Query) => {
70
+ return {
71
+ testCaseStarted: query
72
+ .findAllTestCaseStarted()
73
+ .map((testCaseStarted) => query.findPickleBy(testCaseStarted))
74
+ .map((pickle) => pickle?.name),
75
+ testCaseFinished: query
76
+ .findAllTestCaseFinished()
77
+ .map((testCaseFinished) => query.findPickleBy(testCaseFinished))
78
+ .map((pickle) => pickle?.name),
79
+ testStepStarted: query
80
+ .findAllTestStepFinished()
81
+ .map((testCaseStarted) => query.findPickleBy(testCaseStarted))
82
+ .map((pickle) => pickle?.name),
83
+ testStepFinished: query
84
+ .findAllTestStepFinished()
85
+ .map((testCaseFinished) => query.findPickleBy(testCaseFinished))
86
+ .map((pickle) => pickle?.name),
87
+ }
88
+ },
89
+ findPickleStepBy: (query: Query) =>
90
+ query
91
+ .findAllTestSteps()
92
+ .map((testStep) => query.findPickleStepBy(testStep))
93
+ .map((pickleStep) => pickleStep?.text)
94
+ .filter((value) => !!value),
95
+ findStepBy: (query: Query) =>
96
+ query
97
+ .findAllPickleSteps()
98
+ .map((pickleStep) => query.findStepBy(pickleStep))
99
+ .map((step) => step?.text),
100
+ findStepDefinitionsBy: (query: Query) =>
101
+ query
102
+ .findAllTestSteps()
103
+ .map((pickleStep) =>
104
+ query.findStepDefinitionsBy(pickleStep).map((stepDefinition) => stepDefinition?.id)
105
+ ),
106
+ findSuggestionsBy: (query: Query) => {
107
+ return {
108
+ pickleStep: query
109
+ .findAllPickleSteps()
110
+ .flatMap((pickleSteps) => query.findSuggestionsBy(pickleSteps))
111
+ .map((suggestion) => suggestion.id),
112
+ pickle: query
113
+ .findAllPickles()
114
+ .flatMap((pickle) => query.findSuggestionsBy(pickle))
115
+ .map((suggestion) => suggestion.id),
116
+ }
117
+ },
118
+ findUnambiguousStepDefinitionBy: (query: Query) =>
119
+ query
120
+ .findAllTestSteps()
121
+ .map((pickleStep) => query.findUnambiguousStepDefinitionBy(pickleStep))
122
+ .filter((stepDefinition) => !!stepDefinition)
123
+ .map((stepDefinition) => stepDefinition.id),
124
+ findTestCaseBy: (query: Query) => {
125
+ return {
126
+ testCaseStarted: query
127
+ .findAllTestCaseStarted()
128
+ .map((testCaseStarted) => query.findTestCaseBy(testCaseStarted))
129
+ .map((testCase) => testCase?.id),
130
+ testCaseFinished: query
131
+ .findAllTestCaseFinished()
132
+ .map((testCaseFinished) => query.findTestCaseBy(testCaseFinished))
133
+ .map((testCase) => testCase?.id),
134
+ testStepStarted: query
135
+ .findAllTestStepStarted()
136
+ .map((testStepStarted) => query.findTestCaseBy(testStepStarted))
137
+ .map((testCase) => testCase?.id),
138
+ testStepFinished: query
139
+ .findAllTestStepFinished()
140
+ .map((testStepFinished) => query.findTestCaseBy(testStepFinished))
141
+ .map((testCase) => testCase?.id),
142
+ }
143
+ },
144
+ findTestCaseDurationBy: (query: Query) => {
145
+ return {
146
+ testCaseStarted: query
147
+ .findAllTestCaseStarted()
148
+ .map((testCaseStarted) => query.findTestCaseDurationBy(testCaseStarted)),
149
+ testCaseFinished: query
150
+ .findAllTestCaseFinished()
151
+ .map((testCaseFinished) => query.findTestCaseDurationBy(testCaseFinished)),
152
+ }
153
+ },
154
+ findTestCaseFinishedBy: (query: Query) =>
155
+ query
156
+ .findAllTestCaseStarted()
157
+ .map((testCaseStarted) => query.findTestCaseFinishedBy(testCaseStarted))
158
+ .map((testCaseFinished) => testCaseFinished?.testCaseStartedId),
159
+ findTestRunDuration: (query: Query) => query.findTestRunDuration(),
160
+ findTestRunFinished: (query: Query) => query.findTestRunFinished(),
161
+ findTestRunStarted: (query: Query) => query.findTestRunStarted(),
162
+ findTestStepByTestStepStarted: (query: Query) =>
163
+ query
164
+ .findAllTestCaseStarted()
165
+ .flatMap((testCaseStarted) => query.findTestStepsStartedBy(testCaseStarted))
166
+ .map((testStepStarted) => query.findTestStepBy(testStepStarted))
167
+ .map((testStep) => testStep?.id),
168
+ findTestStepByTestStepFinished: (query: Query) => {
169
+ return {
170
+ testCaseStarted: query
171
+ .findAllTestCaseStarted()
172
+ .flatMap((testCaseStarted) => query.findTestStepsFinishedBy(testCaseStarted))
173
+ .map((testStepFinished) => query.findTestStepBy(testStepFinished))
174
+ .map((testStep) => testStep?.id),
175
+ testCaseFinished: query
176
+ .findAllTestCaseFinished()
177
+ .flatMap((testCaseFinished) => query.findTestStepsFinishedBy(testCaseFinished))
178
+ .map((testStepFinished) => query.findTestStepBy(testStepFinished))
179
+ .map((testStep) => testStep?.id),
180
+ }
181
+ },
182
+ findTestStepsFinishedBy: (query: Query) =>
183
+ query
184
+ .findAllTestCaseStarted()
185
+ .map((testCaseStarted) => query.findTestStepsFinishedBy(testCaseStarted))
186
+ .map((testStepFinisheds) =>
187
+ testStepFinisheds.map((testStepFinished) => testStepFinished?.testStepId)
188
+ ),
189
+ findTestStepFinishedAndTestStepBy: (query: Query) =>
190
+ query
191
+ .findAllTestCaseStarted()
192
+ .flatMap((testCaseStarted) => query.findTestStepFinishedAndTestStepBy(testCaseStarted))
193
+ .map(([testStepFinished, testStep]) => [testStepFinished.testStepId, testStep.id]),
194
+ }
38
195
 
39
- it(suiteName, async () => {
40
- const query = new Query()
196
+ for (const source of sources) {
197
+ for (const methodName in queries) {
198
+ const [suiteName] = path.basename(source).split('.')
41
199
 
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
- )
200
+ it(suiteName + ' -> ' + methodName, async () => {
201
+ const query = new Query()
53
202
 
54
- const expectedResults: ResultsFixture = {
55
- ...defaults,
56
- ...JSON.parse(
57
- fs.readFileSync(fixtureFile, {
58
- encoding: 'utf-8',
203
+ await asyncPipeline(
204
+ fs.createReadStream(source, { encoding: 'utf-8' }),
205
+ new NdjsonToMessageStream(),
206
+ new Writable({
207
+ objectMode: true,
208
+ write(envelope: Envelope, _: BufferEncoding, callback) {
209
+ query.update(envelope)
210
+ callback()
211
+ },
59
212
  })
60
- ),
61
- }
213
+ )
62
214
 
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
- findStepDefinitionsBy: query
161
- .findAllTestSteps()
162
- .map((pickleStep) =>
163
- query.findStepDefinitionsBy(pickleStep).map((stepDefinition) => stepDefinition?.id)
164
- ),
165
- findUnambiguousStepDefinitionBy: query
166
- .findAllTestSteps()
167
- .map((pickleStep) => query.findUnambiguousStepDefinitionBy(pickleStep))
168
- .filter((stepDefinition) => !!stepDefinition)
169
- .map((stepDefinition) => stepDefinition.id),
170
- findTestCaseBy: query
171
- .findAllTestCaseStarted()
172
- .map((testCaseStarted) => query.findTestCaseBy(testCaseStarted))
173
- .map((testCase) => testCase?.id),
174
- findTestCaseDurationBy: query
175
- .findAllTestCaseStarted()
176
- .map((testCaseStarted) => query.findTestCaseDurationBy(testCaseStarted)),
177
- findTestCaseFinishedBy: query
178
- .findAllTestCaseStarted()
179
- .map((testCaseStarted) => query.findTestCaseFinishedBy(testCaseStarted))
180
- .map((testCaseFinished) => testCaseFinished?.testCaseStartedId),
181
- findTestRunDuration: query.findTestRunDuration(),
182
- findTestRunFinished: query.findTestRunFinished(),
183
- findTestRunStarted: query.findTestRunStarted(),
184
- findTestStepByTestStepStarted: query
185
- .findAllTestCaseStarted()
186
- .flatMap((testCaseStarted) => query.findTestStepsStartedBy(testCaseStarted))
187
- .map((testStepStarted) => query.findTestStepBy(testStepStarted))
188
- .map((testStep) => testStep?.id),
189
- findTestStepByTestStepFinished: query
190
- .findAllTestCaseStarted()
191
- .flatMap((testCaseStarted) => query.findTestStepsFinishedBy(testCaseStarted))
192
- .map((testStepFinished) => query.findTestStepBy(testStepFinished))
193
- .map((testStep) => testStep?.id),
194
- findTestStepsFinishedBy: query
195
- .findAllTestCaseStarted()
196
- .map((testCaseStarted) => query.findTestStepsFinishedBy(testCaseStarted))
197
- .map((testStepFinisheds) =>
198
- testStepFinisheds.map((testStepFinished) => testStepFinished?.testStepId)
215
+ const expectedResults = JSON.parse(
216
+ fs.readFileSync(
217
+ path.join(
218
+ __dirname,
219
+ '../../testdata/src/' + suiteName + '.' + methodName + '.results.json'
199
220
  ),
200
- findTestStepFinishedAndTestStepBy: query
201
- .findAllTestCaseStarted()
202
- .flatMap((testCaseStarted) => query.findTestStepFinishedAndTestStepBy(testCaseStarted))
203
- .map(([testStepFinished, testStep]) => [testStepFinished.testStepId, testStep.id]),
204
- })
205
- )
206
-
207
- assert.deepStrictEqual(actualResults, expectedResults)
208
- })
221
+ {
222
+ encoding: 'utf-8',
223
+ }
224
+ )
225
+ )
226
+ const actualResults = JSON.parse(JSON.stringify(queries[methodName](query)))
227
+ assert.deepStrictEqual(actualResults, expectedResults)
228
+ })
229
+ }
209
230
  }
210
231
  })
211
232
 
212
- interface ResultsFixture {
213
- countMostSevereTestStepResultStatus: Record<TestStepResultStatus, number>
214
- countTestCasesStarted: number
215
- findAllPickles: number
216
- findAllPickleSteps: number
217
- findAllTestCaseStarted: number
218
- findAllTestSteps: number
219
- findAllTestCaseStartedGroupedByFeature: Array<[string, string[]]>
220
- findAttachmentsBy: Array<[string, string, string, string]>
221
- findFeatureBy: Array<string>
222
- findMeta: string
223
- findMostSevereTestStepResultBy: Array<TestStepResultStatus>
224
- findNameOf: {
225
- long: Array<string>
226
- excludeFeatureName: Array<string>
227
- longPickleName: Array<string>
228
- short: Array<string>
229
- shortPickleName: Array<string>
230
- }
231
- findLocationOf: Array<Location>
232
- findHookBy: Array<string>
233
- findPickleBy: Array<string>
234
- findPickleStepBy: Array<string>
235
- findStepBy: Array<string>
236
- findStepDefinitionsBy: Array<Array<string>>
237
- findUnambiguousStepDefinitionBy: Array<string>
238
- findTestCaseBy: Array<string>
239
- findTestCaseDurationBy: Array<Duration>
240
- findTestCaseFinishedBy: Array<string>
241
- findTestRunDuration: Duration
242
- findTestRunFinished: TestRunFinished
243
- findTestRunStarted: TestRunStarted
244
- findTestStepByTestStepStarted: Array<string>
245
- findTestStepByTestStepFinished: Array<string>
246
- findTestStepsFinishedBy: Array<Array<string>>
247
- findTestStepFinishedAndTestStepBy: Array<[string, string]>
248
- }
249
-
250
- const defaults: Partial<ResultsFixture> = {
251
- findAllTestCaseStartedGroupedByFeature: [],
252
- findAttachmentsBy: [],
253
- findFeatureBy: [],
254
- findMostSevereTestStepResultBy: [],
255
- findNameOf: {
256
- long: [],
257
- excludeFeatureName: [],
258
- longPickleName: [],
259
- short: [],
260
- shortPickleName: [],
261
- },
262
- findHookBy: [],
263
- findPickleBy: [],
264
- findPickleStepBy: [],
265
- findStepBy: [],
266
- findStepDefinitionsBy: [],
267
- findUnambiguousStepDefinitionBy: [],
268
- findTestCaseBy: [],
269
- findTestCaseDurationBy: [],
270
- findTestCaseFinishedBy: [],
271
- findTestStepByTestStepStarted: [],
272
- findTestStepByTestStepFinished: [],
273
- findTestStepsFinishedBy: [],
274
- findTestStepFinishedAndTestStepBy: [],
233
+ type Queries = {
234
+ // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
235
+ [key: string]: (query: Query) => Object
275
236
  }