Skip to content

Commit e2231c9

Browse files
committed
review
1 parent 0c78779 commit e2231c9

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

features/error_formatting.feature

+4-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ Feature: Error formatting
5454
"""
5555
import {Given} from 'cucumber'
5656
57-
Given(/^a basic step$/, function() { this.attach('Basic info.') })
58-
Given(/^a step with a doc string$/, function(str) {})
57+
Given(/^a basic step$/, function() { this.attach('Some info.') })
58+
Given(/^a step with a doc string$/, function(str) { this.attach('Other info.') })
5959
Given(/^a pending step$/, function() { return 'pending' })
6060
"""
6161
When I run cucumber-js
@@ -65,11 +65,12 @@ Feature: Error formatting
6565
6666
1) Scenario: some scenario # features/a.feature:3
6767
✔ Given a basic step # features/step_definitions/cucumber_steps.js:3
68-
Attachment (text/plain): Basic info.
68+
Attachment (text/plain): Some info.
6969
✔ And a step with a doc string # features/step_definitions/cucumber_steps.js:4
7070
\"\"\"
7171
my doc string
7272
\"\"\"
73+
Attachment (text/plain): Other info.
7374
? And a pending step # features/step_definitions/cucumber_steps.js:5
7475
Pending
7576
"""

src/formatter/helpers/issue_helpers.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,6 @@ function formatStep({
9393
}
9494
text += '\n'
9595

96-
if (testStep.attachments) {
97-
testStep.attachments
98-
.filter(({ media }) => media.type === 'text/plain')
99-
.forEach(({ data }) => {
100-
text += indentString('Attachment (text/plain): ' + data, 4) + '\n'
101-
})
102-
}
103-
10496
if (pickleStep) {
10597
let str
10698
const iterator = buildStepArgumentIterator({
@@ -112,6 +104,14 @@ function formatStep({
112104
text += indentString(`${colorFn(str)}\n`, 4)
113105
}
114106
}
107+
108+
if (testStep.attachments) {
109+
testStep.attachments.forEach(({ media, data }) => {
110+
const message = media.type === 'text/plain' ? `: ${data}` : ''
111+
text += indentString(`Attachment (${media.type})${message}\n`, 4)
112+
})
113+
}
114+
115115
const message = getStepMessage({
116116
colorFns,
117117
keywordType,

src/formatter/helpers/issue_helpers_spec.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -241,21 +241,21 @@ describe('IssueHelpers', () => {
241241
this.testCase.steps[0].result = this.passedStepResult
242242
this.testCase.steps[0].attachments = [
243243
{
244-
data: 'First info.',
244+
data: 'Some info.',
245245
media: {
246246
type: 'text/plain',
247247
},
248248
},
249249
{
250-
data: 'Nop',
250+
data: '{"name": "some JSON"}',
251251
media: {
252-
type: 'text/special',
252+
type: 'application/json',
253253
},
254254
},
255255
{
256-
data: 'Second info.',
256+
data: Buffer.from([]),
257257
media: {
258-
type: 'text/plain',
258+
type: 'image/png',
259259
},
260260
},
261261
]
@@ -269,7 +269,7 @@ describe('IssueHelpers', () => {
269269
}
270270
this.testCase.steps[1].attachments = [
271271
{
272-
data: 'Third info.',
272+
data: 'Other info.',
273273
media: {
274274
type: 'text/plain',
275275
},
@@ -283,10 +283,11 @@ describe('IssueHelpers', () => {
283283
expect(this.formattedIssue).to.eql(
284284
'1) Scenario: my scenario # a.feature:2\n' +
285285
` ${figures.tick} Given step1 # steps.js:2\n` +
286-
` Attachment (text/plain): First info.\n` +
287-
` Attachment (text/plain): Second info.\n` +
286+
` Attachment (text/plain): Some info.\n` +
287+
` Attachment (application/json)\n` +
288+
` Attachment (image/png)\n` +
288289
` ${figures.cross} When step2 # steps.js:3\n` +
289-
` Attachment (text/plain): Third info.\n` +
290+
` Attachment (text/plain): Other info.\n` +
290291
' error\n' +
291292
' - Then step3 # steps.js:4\n\n'
292293
)

0 commit comments

Comments
 (0)