Skip to content

Commit

Permalink
fix(formatter): Enable calling parseTestCaseAttempt on test cases tha…
Browse files Browse the repository at this point in the history
…t haven't completed (#1531)

* fix(formatter): Enable calling parseTestCaseAttempt on test cases that haven't completed yet

* Instanciate a proper TestStepResult when parsing TestCaseAttempt

* Add unit tests

* Refactor testCaseAttemptParser unit tests

Co-authored-by: Aurélien Reeves <aurelien.reeves@smartbear.com>
Co-authored-by: Aslak Hellesøy <1000+aslakhellesoy@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 13, 2021
1 parent 0fbb0fb commit 6e958f1
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/formatter/helpers/test_case_attempt_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ISupportCodeLibrary } from '../../support_code_library_builder/types'
import { doesHaveValue, valueOrDefault } from '../../value_checker'
import TestCaseHookDefinition from '../../models/test_case_hook_definition'
import { ILineAndUri } from '../../types'
import { TestStepResult } from '@cucumber/messages'

export interface IParsedTestStep {
actionLocation?: ILineAndUri
Expand Down Expand Up @@ -150,9 +151,13 @@ export function parseTestCaseAttempt({
const parsedTestSteps: IParsedTestStep[] = []
let isBeforeHook = true
let previousKeywordType = KeywordType.Precondition

testCase.testSteps.forEach((testStep) => {
const testStepResult = testCaseAttempt.stepResults[testStep.id]
const testStepResult =
testCaseAttempt.stepResults[testStep.id] || new TestStepResult()

isBeforeHook = isBeforeHook && doesHaveValue(testStep.hookId)

let keyword, keywordType, pickleStep
if (doesHaveValue(testStep.pickleStepId)) {
pickleStep = pickleStepMap[testStep.pickleStepId]
Expand Down
81 changes: 81 additions & 0 deletions src/formatter/helpers/test_case_attempt_parser_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { describe, it } from 'mocha'
import { expect } from 'chai'
import * as messages from '@cucumber/messages'
import { parseTestCaseAttempt } from '.'
import { getBaseSupportCodeLibrary } from '../../../test/fixtures/steps'
import StepDefinitionSnippetBuilder from '../step_definition_snippet_builder'
import { ParameterTypeRegistry } from '@cucumber/cucumber-expressions'
import { reindent } from 'reindent-template-literals'
import { getTestCaseAttempts } from '../../../test/formatter_helpers'

describe('TestCaseAttemptParser', () => {
describe('parseTestCaseAttempt', () => {
const cwd = ''
const supportCodeLibrary = getBaseSupportCodeLibrary()
const snippetSyntax = {
build: () => 'snippet',
}

const snippetBuilder = new StepDefinitionSnippetBuilder({
snippetSyntax,
parameterTypeRegistry: new ParameterTypeRegistry(),
})

const source = {
data: reindent(`
Feature: my feature
Scenario: my scenario
Given a passing step
`),
uri: 'a.feature',
}

describe('with no test step result', () => {
it('initialize step result with status UNKNOWN', async () => {
// Arrange
const [testCaseAttempt] = await getTestCaseAttempts({
sources: [source],
supportCodeLibrary,
})

testCaseAttempt.stepResults = {}

// Act
const output = parseTestCaseAttempt({
cwd,
testCaseAttempt,
snippetBuilder,
supportCodeLibrary,
})

// Assert
expect(output.testSteps[0].result.status).to.eq(
messages.TestStepResultStatus.UNKNOWN
)
})
})

describe('with test step result', () => {
it('uses the parsed step result', async () => {
// Arrange
const [testCaseAttempt] = await getTestCaseAttempts({
sources: [source],
supportCodeLibrary,
})

// Act
const output = parseTestCaseAttempt({
cwd,
testCaseAttempt,
snippetBuilder,
supportCodeLibrary,
})

// Assert
expect(output.testSteps[0].result.status).to.eq(
messages.TestStepResultStatus.PASSED
)
})
})
})
})

0 comments on commit 6e958f1

Please sign in to comment.