|
1 | 1 | import { EventEmitter } from 'node:events'
|
2 |
| -import { Readable } from 'node:stream' |
3 |
| -import { GherkinStreams } from '@cucumber/gherkin-streams' |
4 | 2 | import * as messages from '@cucumber/messages'
|
5 |
| -import { IdGenerator, SourceMediaType } from '@cucumber/messages' |
| 3 | +import { IdGenerator } from '@cucumber/messages' |
6 | 4 | import { expect } from 'chai'
|
7 | 5 | import { describe, it } from 'mocha'
|
8 | 6 | import {
|
9 | 7 | CucumberExpression,
|
10 | 8 | ParameterType,
|
11 | 9 | RegularExpression,
|
12 | 10 | } from '@cucumber/cucumber-expressions'
|
13 |
| -import { EventDataCollector } from '../formatter/helpers' |
14 |
| -import PickleFilter from '../pickle_filter' |
15 | 11 | import StepDefinition from '../models/step_definition'
|
16 | 12 | import { SupportCodeLibrary } from '../support_code_library_builder/types'
|
17 | 13 | import TestCaseHookDefinition from '../models/test_case_hook_definition'
|
18 | 14 | import TestRunHookDefinition from '../models/test_run_hook_definition'
|
19 | 15 | import { SourcedParameterTypeRegistry } from '../support_code_library_builder/sourced_parameter_type_registry'
|
20 |
| -import { IPickleOrder } from '../api' |
21 |
| -import { |
22 |
| - emitMetaMessage, |
23 |
| - emitSupportCodeMessages, |
24 |
| - parseGherkinMessageStream, |
25 |
| -} from './helpers' |
| 16 | +import { emitMetaMessage, emitSupportCodeMessages } from './helpers' |
26 | 17 |
|
27 | 18 | const noopFunction = (): void => {
|
28 | 19 | // no code
|
29 | 20 | }
|
30 | 21 |
|
31 |
| -interface ITestParseGherkinMessageStreamRequest { |
32 |
| - gherkinMessageStream: Readable |
33 |
| - order: IPickleOrder |
34 |
| - pickleFilter: PickleFilter |
35 |
| -} |
36 |
| - |
37 |
| -interface ITestParseGherkinMessageStreamResponse { |
38 |
| - envelopes: messages.Envelope[] |
39 |
| - result: string[] |
40 |
| -} |
41 |
| - |
42 |
| -async function testParseGherkinMessageStream( |
43 |
| - options: ITestParseGherkinMessageStreamRequest |
44 |
| -): Promise<ITestParseGherkinMessageStreamResponse> { |
45 |
| - const envelopes: messages.Envelope[] = [] |
46 |
| - const eventBroadcaster = new EventEmitter() |
47 |
| - eventBroadcaster.on('envelope', (e) => envelopes.push(e)) |
48 |
| - const eventDataCollector = new EventDataCollector(eventBroadcaster) |
49 |
| - const result = await parseGherkinMessageStream({ |
50 |
| - eventBroadcaster, |
51 |
| - eventDataCollector, |
52 |
| - gherkinMessageStream: options.gherkinMessageStream, |
53 |
| - order: options.order, |
54 |
| - pickleFilter: options.pickleFilter, |
55 |
| - }) |
56 |
| - return { envelopes, result } |
57 |
| -} |
58 |
| - |
59 | 22 | function testEmitSupportCodeMessages(
|
60 | 23 | supportCode: Partial<SupportCodeLibrary>
|
61 | 24 | ): messages.Envelope[] {
|
@@ -373,123 +336,4 @@ describe('helpers', () => {
|
373 | 336 | expect(envelopes).to.deep.eq(expectedEnvelopes)
|
374 | 337 | })
|
375 | 338 | })
|
376 |
| - describe('parseGherkinMessageStream', () => { |
377 |
| - describe('empty feature', () => { |
378 |
| - it('emits source and gherkinDocument events and returns an empty array', async function () { |
379 |
| - // Arrange |
380 |
| - const cwd = '/project' |
381 |
| - const sourceEnvelope: messages.Envelope = { |
382 |
| - source: { |
383 |
| - data: '', |
384 |
| - mediaType: SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN, |
385 |
| - uri: '/project/features/a.feature', |
386 |
| - }, |
387 |
| - } |
388 |
| - const gherkinMessageStream = GherkinStreams.fromSources( |
389 |
| - [sourceEnvelope], |
390 |
| - {} |
391 |
| - ) |
392 |
| - const order = 'defined' |
393 |
| - const pickleFilter = new PickleFilter({ cwd }) |
394 |
| - |
395 |
| - // Act |
396 |
| - const { envelopes, result } = await testParseGherkinMessageStream({ |
397 |
| - gherkinMessageStream, |
398 |
| - order, |
399 |
| - pickleFilter, |
400 |
| - }) |
401 |
| - |
402 |
| - // Assert |
403 |
| - expect(result).to.eql([]) |
404 |
| - expect(envelopes).to.have.lengthOf(2) |
405 |
| - expect(envelopes[0]).to.eql(sourceEnvelope) |
406 |
| - expect(envelopes[1].gherkinDocument).to.exist() |
407 |
| - expect(envelopes[1].gherkinDocument).to.have.keys([ |
408 |
| - 'comments', |
409 |
| - 'feature', |
410 |
| - 'uri', |
411 |
| - ]) |
412 |
| - }) |
413 |
| - }) |
414 |
| - |
415 |
| - describe('feature with scenario that does not match the filter', () => { |
416 |
| - it('emits pickle event and returns an empty array', async function () { |
417 |
| - // Arrange |
418 |
| - const cwd = '/project' |
419 |
| - const sourceEnvelope: messages.Envelope = { |
420 |
| - source: { |
421 |
| - data: '@tagA\nFeature: a\nScenario: b\nGiven a step', |
422 |
| - mediaType: SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN, |
423 |
| - uri: '/project/features/a.feature', |
424 |
| - }, |
425 |
| - } |
426 |
| - const gherkinMessageStream = GherkinStreams.fromSources( |
427 |
| - [sourceEnvelope], |
428 |
| - {} |
429 |
| - ) |
430 |
| - const order = 'defined' |
431 |
| - const pickleFilter = new PickleFilter({ |
432 |
| - cwd, |
433 |
| - tagExpression: 'not @tagA', |
434 |
| - }) |
435 |
| - |
436 |
| - // Act |
437 |
| - const { envelopes, result } = await testParseGherkinMessageStream({ |
438 |
| - gherkinMessageStream, |
439 |
| - order, |
440 |
| - pickleFilter, |
441 |
| - }) |
442 |
| - |
443 |
| - // Assert |
444 |
| - expect(result).to.eql([]) |
445 |
| - expect(envelopes).to.have.lengthOf(3) |
446 |
| - expect(envelopes[0]).to.eql(sourceEnvelope) |
447 |
| - expect(envelopes[1].gherkinDocument).to.exist() |
448 |
| - expect(envelopes[2].pickle).to.exist() |
449 |
| - expect(envelopes[2].pickle).to.have.keys([ |
450 |
| - 'astNodeIds', |
451 |
| - 'id', |
452 |
| - 'language', |
453 |
| - 'name', |
454 |
| - 'steps', |
455 |
| - 'tags', |
456 |
| - 'uri', |
457 |
| - ]) |
458 |
| - }) |
459 |
| - }) |
460 |
| - |
461 |
| - describe('feature with scenario that matches the filter', () => { |
462 |
| - it('emits pickle and returns the pickleId', async function () { |
463 |
| - // Arrange |
464 |
| - const cwd = '/project' |
465 |
| - const sourceEnvelope: messages.Envelope = { |
466 |
| - source: { |
467 |
| - data: 'Feature: a\nScenario: b\nGiven a step', |
468 |
| - mediaType: SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN, |
469 |
| - uri: '/project/features/a.feature', |
470 |
| - }, |
471 |
| - } |
472 |
| - const gherkinMessageStream = GherkinStreams.fromSources( |
473 |
| - [sourceEnvelope], |
474 |
| - {} |
475 |
| - ) |
476 |
| - const order = 'defined' |
477 |
| - const pickleFilter = new PickleFilter({ cwd }) |
478 |
| - |
479 |
| - // Act |
480 |
| - const { envelopes, result } = await testParseGherkinMessageStream({ |
481 |
| - gherkinMessageStream, |
482 |
| - order, |
483 |
| - pickleFilter, |
484 |
| - }) |
485 |
| - |
486 |
| - // Assert |
487 |
| - expect(result).to.eql([envelopes[2].pickle.id]) |
488 |
| - expect(envelopes).to.have.lengthOf(3) |
489 |
| - expect(envelopes[0]).to.eql(sourceEnvelope) |
490 |
| - expect(envelopes[1].gherkinDocument).to.exist() |
491 |
| - expect(envelopes[2].pickle).to.exist() |
492 |
| - }) |
493 |
| - }) |
494 |
| - }) |
495 | 339 | })
|
0 commit comments