@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.
@@ -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
- import {NdjsonToMessageStream} from '@cucumber/message-streams'
8
- import {Duration, Envelope, TestRunFinished, TestRunStarted, TestStepResultStatus} from '@cucumber/messages'
9
- import {glob} from 'glob'
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
- namingStrategy,
14
- NamingStrategyExampleName,
15
- NamingStrategyFeatureName,
16
- NamingStrategyLength
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
- const fixtureFiles = glob.sync(`*.query-results.json`, {
24
- cwd: TESTDATA_PATH,
25
- absolute: true
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
- it(suiteName, async () => {
33
- const query = new Query()
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
- await asyncPipeline(
36
- fs.createReadStream(ndjsonFile, { encoding: 'utf-8' }),
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
- const expectedResults: ResultsFixture = {
48
- ...defaults,
49
- ...JSON.parse(fs.readFileSync(fixtureFile, {
50
- encoding: 'utf-8',
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
- const actualResults: ResultsFixture = JSON.parse(JSON.stringify({
55
- countMostSevereTestStepResultStatus: query.countMostSevereTestStepResultStatus(),
56
- countTestCasesStarted: query.countTestCasesStarted(),
57
- findAllPickles: query.findAllPickles().length,
58
- findAllPickleSteps: query.findAllPickleSteps().length,
59
- findAllTestCaseStarted: query.findAllTestCaseStarted().length,
60
- findAllTestSteps: query.findAllTestSteps().length,
61
- findAllTestCaseStartedGroupedByFeature: [...query.findAllTestCaseStartedGroupedByFeature().entries()]
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
- assert.deepStrictEqual(actualResults, expectedResults)
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
- countMostSevereTestStepResultStatus: Record<TestStepResultStatus, number>,
131
- countTestCasesStarted: number,
132
- findAllPickles: number,
133
- findAllPickleSteps: number,
134
- findAllTestCaseStarted: number,
135
- findAllTestSteps: number,
136
- findAllTestCaseStartedGroupedByFeature: Array<[string, string[]]>,
137
- findAttachmentsBy: Array<[string, string, string, string]>,
138
- findFeatureBy: Array<string>,
139
- findMeta: string,
140
- findMostSevereTestStepResultBy: Array<TestStepResultStatus>,
141
- findNameOf: {
142
- long: Array<string>,
143
- excludeFeatureName: Array<string>,
144
- longPickleName: Array<string>,
145
- short: Array<string>,
146
- shortPickleName: Array<string>
147
- },
148
- findHookBy: Array<string>,
149
- findPickleBy: Array<string>,
150
- findPickleStepBy: Array<string>,
151
- findStepBy: Array<string>,
152
- findTestCaseBy: Array<string>,
153
- findTestCaseDurationBy: Array<Duration>,
154
- findTestCaseFinishedBy: Array<string>,
155
- findTestRunDuration: Duration,
156
- findTestRunFinished: TestRunFinished,
157
- findTestRunStarted: TestRunStarted,
158
- findTestStepBy: Array<string>,
159
- findTestStepsFinishedBy: Array<Array<string>>
160
- findTestStepFinishedAndTestStepBy: Array<[string, string]>
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
- findAllTestCaseStartedGroupedByFeature: [],
165
- findAttachmentsBy: [],
166
- findFeatureBy: [],
167
- findMostSevereTestStepResultBy: [],
168
- findNameOf: {
169
- long: [],
170
- excludeFeatureName: [],
171
- longPickleName: [],
172
- short: [],
173
- shortPickleName: []
174
- },
175
- findHookBy: [],
176
- findPickleBy: [],
177
- findPickleStepBy: [],
178
- findStepBy: [],
179
- findTestCaseBy: [],
180
- findTestCaseDurationBy: [],
181
- findTestCaseFinishedBy: [],
182
- findTestStepBy: [],
183
- findTestStepsFinishedBy: [],
184
- findTestStepFinishedAndTestStepBy: []
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 { TestStepResult, TestStepResultStatus } from '@cucumber/messages'
1
+ import { TestStepResultStatus } from '@cucumber/messages'
2
2
 
3
- interface WithId {
4
- id: string | number
5
- }
6
-
7
- export function comparatorById(a: WithId, b: WithId) {
8
- return comparatorBy(a, b, "id")
9
- }
10
-
11
- export function comparatorBy(a: any, b: any, key: string) {
12
- if ( a[key] < b[key] ){
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
- ok(target: unknown, message: string) {
45
- if (!target) {
46
- throw new Error(message)
47
- }
16
+ ok(target: unknown, message: string) {
17
+ if (!target) {
18
+ throw new Error(message)
48
19
  }
49
- }
20
+ },
21
+ }
@@ -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
- })