Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 13, 2021
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
)
})
})
})
})