Skip to content
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

Print attachment step text on error format #1041

Merged
merged 7 commits into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/support_files/attachments.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,20 @@ After(function (testCase) {
}
});
```

Attachments are also printed by the progress, progress-bar and summary formatter.
They appears right after the step and only `text/plain` content is visible.
It can be used to debug scenarios, especially in parallel mode.

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please use javascript syntax highlighting here? The result format could be entirely commented out or put in its own block

// Step definition
Given(/^a basic step$/, function() {
this.attach('Some info.')
this.attach('{"some", "JSON"}}', 'application/json')
})

// Result format
✔ Given a basic step # path:line
Attachment (text/plain): Some info.
Attachment (application/json)
```
6 changes: 4 additions & 2 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() {})
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('{"name": "some JSON"}', 'application/json') })
Given(/^a pending step$/, function() { return 'pending' })
"""
When I run cucumber-js
Expand All @@ -65,10 +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): Some info.
✔ And a step with a doc string # features/step_definitions/cucumber_steps.js:4
\"\"\"
my doc string
\"\"\"
Attachment (application/json)
? And a pending step # features/step_definitions/cucumber_steps.js:5
Pending
"""
Expand Down
8 changes: 8 additions & 0 deletions src/formatter/helpers/issue_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,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
58 changes: 58 additions & 0 deletions src/formatter/helpers/issue_helpers_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,63 @@ describe('IssueHelpers', () => {
)
})
})

describe('step with attachment text', () => {
beforeEach(function() {
this.testCase.steps[0].result = this.passedStepResult
this.testCase.steps[0].attachments = [
{
data: 'Some info.',
media: {
type: 'text/plain',
},
},
{
data: '{"name": "some JSON"}',
media: {
type: 'application/json',
},
},
{
data: Buffer.from([]),
media: {
type: 'image/png',
},
},
]
this.testCase.steps[1] = {
actionLocation: { line: 3, uri: 'steps.js' },
sourceLocation: { line: 4, uri: 'a.feature' },
result: {
exception: 'error',
status: Status.FAILED,
},
}
this.testCase.steps[1].attachments = [
{
data: 'Other info.',
media: {
type: 'text/plain',
},
},
]
this.testCase.steps[2].result = this.skippedStepResult
this.formattedIssue = formatIssue(this.options)
})

it('prints the scenario', function() {
expect(this.formattedIssue).to.eql(
'1) Scenario: my scenario # a.feature:2\n' +
` ${figures.tick} Given step1 # steps.js:2\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): Other info.\n` +
' error\n' +
' - Then step3 # steps.js:4\n\n'
)
})
})
})
})