|
| 1 | +import { describe, it } from 'mocha' |
| 2 | +import { expect } from 'chai' |
| 3 | +import * as messages from '@cucumber/messages' |
| 4 | +import { parseTestCaseAttempt } from '.' |
| 5 | +import { getBaseSupportCodeLibrary } from '../../../test/fixtures/steps' |
| 6 | +import StepDefinitionSnippetBuilder from '../step_definition_snippet_builder' |
| 7 | +import { ParameterTypeRegistry } from '@cucumber/cucumber-expressions' |
| 8 | +import { reindent } from 'reindent-template-literals' |
| 9 | +import { getTestCaseAttempts } from '../../../test/formatter_helpers' |
| 10 | + |
| 11 | +describe('TestCaseAttemptParser', () => { |
| 12 | + describe('parseTestCaseAttempt', () => { |
| 13 | + const cwd = '' |
| 14 | + const supportCodeLibrary = getBaseSupportCodeLibrary() |
| 15 | + const snippetSyntax = { |
| 16 | + build: () => 'snippet', |
| 17 | + } |
| 18 | + |
| 19 | + const snippetBuilder = new StepDefinitionSnippetBuilder({ |
| 20 | + snippetSyntax, |
| 21 | + parameterTypeRegistry: new ParameterTypeRegistry(), |
| 22 | + }) |
| 23 | + |
| 24 | + const source = { |
| 25 | + data: reindent(` |
| 26 | + Feature: my feature |
| 27 | + Scenario: my scenario |
| 28 | + Given a passing step |
| 29 | + `), |
| 30 | + uri: 'a.feature', |
| 31 | + } |
| 32 | + |
| 33 | + describe('with no test step result', () => { |
| 34 | + it('initialize step result with status UNKNOWN', async () => { |
| 35 | + // Arrange |
| 36 | + const [testCaseAttempt] = await getTestCaseAttempts({ |
| 37 | + sources: [source], |
| 38 | + supportCodeLibrary, |
| 39 | + }) |
| 40 | + |
| 41 | + testCaseAttempt.stepResults = {} |
| 42 | + |
| 43 | + // Act |
| 44 | + const output = parseTestCaseAttempt({ |
| 45 | + cwd, |
| 46 | + testCaseAttempt, |
| 47 | + snippetBuilder, |
| 48 | + supportCodeLibrary, |
| 49 | + }) |
| 50 | + |
| 51 | + // Assert |
| 52 | + expect(output.testSteps[0].result.status).to.eq( |
| 53 | + messages.TestStepResultStatus.UNKNOWN |
| 54 | + ) |
| 55 | + }) |
| 56 | + }) |
| 57 | + |
| 58 | + describe('with test step result', () => { |
| 59 | + it('uses the parsed step result', async () => { |
| 60 | + // Arrange |
| 61 | + const [testCaseAttempt] = await getTestCaseAttempts({ |
| 62 | + sources: [source], |
| 63 | + supportCodeLibrary, |
| 64 | + }) |
| 65 | + |
| 66 | + // Act |
| 67 | + const output = parseTestCaseAttempt({ |
| 68 | + cwd, |
| 69 | + testCaseAttempt, |
| 70 | + snippetBuilder, |
| 71 | + supportCodeLibrary, |
| 72 | + }) |
| 73 | + |
| 74 | + // Assert |
| 75 | + expect(output.testSteps[0].result.status).to.eq( |
| 76 | + messages.TestStepResultStatus.PASSED |
| 77 | + ) |
| 78 | + }) |
| 79 | + }) |
| 80 | + }) |
| 81 | +}) |
0 commit comments