Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSide committed Mar 20, 2018
1 parent 0c78779 commit e2231c9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
7 changes: 4 additions & 3 deletions features/error_formatting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ Feature: Error formatting
"""
import {Given} from 'cucumber'
Given(/^a basic step$/, function() { this.attach('Basic info.') })
Given(/^a step with a doc string$/, function(str) {})
Given(/^a basic step$/, function() { this.attach('Some info.') })
Given(/^a step with a doc string$/, function(str) { this.attach('Other info.') })
Given(/^a pending step$/, function() { return 'pending' })
"""
When I run cucumber-js
Expand All @@ -65,11 +65,12 @@ Feature: Error formatting
1) Scenario: some scenario # features/a.feature:3
✔ Given a basic step # features/step_definitions/cucumber_steps.js:3
Attachment (text/plain): Basic info.
Attachment (text/plain): Some info.
✔ And a step with a doc string # features/step_definitions/cucumber_steps.js:4
\"\"\"
my doc string
\"\"\"
Attachment (text/plain): Other info.
? And a pending step # features/step_definitions/cucumber_steps.js:5
Pending
"""
Expand Down
16 changes: 8 additions & 8 deletions src/formatter/helpers/issue_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ function formatStep({
}
text += '\n'

if (testStep.attachments) {
testStep.attachments
.filter(({ media }) => media.type === 'text/plain')
.forEach(({ data }) => {
text += indentString('Attachment (text/plain): ' + data, 4) + '\n'
})
}

if (pickleStep) {
let str
const iterator = buildStepArgumentIterator({
Expand All @@ -112,6 +104,14 @@ function formatStep({
text += indentString(`${colorFn(str)}\n`, 4)
}
}

if (testStep.attachments) {
testStep.attachments.forEach(({ media, data }) => {
const message = media.type === 'text/plain' ? `: ${data}` : ''
text += indentString(`Attachment (${media.type})${message}\n`, 4)
})
}

const message = getStepMessage({
colorFns,
keywordType,
Expand Down
19 changes: 10 additions & 9 deletions src/formatter/helpers/issue_helpers_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,21 @@ describe('IssueHelpers', () => {
this.testCase.steps[0].result = this.passedStepResult
this.testCase.steps[0].attachments = [
{
data: 'First info.',
data: 'Some info.',
media: {
type: 'text/plain',
},
},
{
data: 'Nop',
data: '{"name": "some JSON"}',
media: {
type: 'text/special',
type: 'application/json',
},
},
{
data: 'Second info.',
data: Buffer.from([]),
media: {
type: 'text/plain',
type: 'image/png',
},
},
]
Expand All @@ -269,7 +269,7 @@ describe('IssueHelpers', () => {
}
this.testCase.steps[1].attachments = [
{
data: 'Third info.',
data: 'Other info.',
media: {
type: 'text/plain',
},
Expand All @@ -283,10 +283,11 @@ describe('IssueHelpers', () => {
expect(this.formattedIssue).to.eql(
'1) Scenario: my scenario # a.feature:2\n' +
` ${figures.tick} Given step1 # steps.js:2\n` +
` Attachment (text/plain): First info.\n` +
` Attachment (text/plain): Second info.\n` +
` Attachment (text/plain): Some info.\n` +
` Attachment (application/json)\n` +
` Attachment (image/png)\n` +
` ${figures.cross} When step2 # steps.js:3\n` +
` Attachment (text/plain): Third info.\n` +
` Attachment (text/plain): Other info.\n` +
' error\n' +
' - Then step3 # steps.js:4\n\n'
)
Expand Down

0 comments on commit e2231c9

Please sign in to comment.