-
Notifications
You must be signed in to change notification settings - Fork 12
feat: support TestStepResult.exception #345
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This edits are due to upstream changes in the CCK sources. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { TestStepResultStatus } from '@cucumber/messages' | ||
import { expect } from 'chai' | ||
import React from 'react' | ||
|
||
import { render } from '../../../test-utils/index.js' | ||
import { TestStepResultDetails } from './TestStepResultDetails.js' | ||
|
||
describe('TestStepResultDetails', () => { | ||
it('should render nothing if no message or exception', () => { | ||
const { container } = render( | ||
<TestStepResultDetails | ||
duration={{ seconds: 1, nanos: 0 }} | ||
status={TestStepResultStatus.PASSED} | ||
/> | ||
) | ||
|
||
expect(container).to.be.empty | ||
}) | ||
|
||
it('should render the message for a legacy message', () => { | ||
const { container } = render( | ||
<TestStepResultDetails | ||
duration={{ seconds: 1, nanos: 0 }} | ||
status={TestStepResultStatus.FAILED} | ||
message="Oh no a bad thing happened" | ||
/> | ||
) | ||
|
||
expect(container).to.include.text('Oh no a bad thing happened') | ||
}) | ||
|
||
it('should render the message for a typed exception', () => { | ||
const { container } = render( | ||
<TestStepResultDetails | ||
duration={{ seconds: 1, nanos: 0 }} | ||
status={TestStepResultStatus.FAILED} | ||
message="Dont use the legacy field" | ||
exception={{ | ||
type: 'Whoopsie', | ||
message: 'Bad things happened', | ||
}} | ||
/> | ||
) | ||
|
||
expect(container).to.include.text('Whoopsie Bad things happened') | ||
expect(container).not.to.include.text('Dont use the legacy field') | ||
}) | ||
|
||
it('should render a stack trace where present', () => { | ||
const { container } = render( | ||
<TestStepResultDetails | ||
duration={{ seconds: 1, nanos: 0 }} | ||
status={TestStepResultStatus.FAILED} | ||
message="Dont use the legacy field" | ||
exception={{ | ||
type: 'Whoopsie', | ||
message: 'Bad things happened', | ||
stackTrace: 'at /some/file.js:1:2', | ||
}} | ||
/> | ||
) | ||
|
||
expect(container).to.include.text('at /some/file.js:1:2') | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { TestStepResult, TestStepResultStatus } from '@cucumber/messages' | ||
import { Story } from '@ladle/react' | ||
import React from 'react' | ||
|
||
import { CucumberReact } from '../CucumberReact.js' | ||
import { TestStepResultDetails } from './TestStepResultDetails.js' | ||
|
||
export default { | ||
title: 'Results/TestStepResultDetails', | ||
} | ||
|
||
type TemplateArgs = { | ||
result: TestStepResult | ||
} | ||
|
||
const Template: Story<TemplateArgs> = ({ result }) => { | ||
return ( | ||
<CucumberReact> | ||
<TestStepResultDetails {...result} /> | ||
</CucumberReact> | ||
) | ||
} | ||
|
||
export const Legacy = Template.bind({}) | ||
Legacy.args = { | ||
result: { | ||
status: TestStepResultStatus.FAILED, | ||
message: 'Oh no a bad thing happened!', | ||
}, | ||
} | ||
|
||
export const NothingToSee = Template.bind({}) | ||
NothingToSee.args = { | ||
result: { | ||
status: TestStepResultStatus.PASSED, | ||
}, | ||
} | ||
|
||
export const TypedException = Template.bind({}) | ||
TypedException.args = { | ||
result: { | ||
status: TestStepResultStatus.FAILED, | ||
message: | ||
"TypeError: Cannot read properties of null (reading 'type')\n at TodosPage.addItem (/Users/somebody/Projects/my-project/support/pages/TodosPage.ts:39:21)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\n at CustomWorld.<anonymous> (/Users/somebody/Projects/my-project/support/steps/steps.ts:20:5)", | ||
exception: { | ||
type: 'TypeError', | ||
message: "Cannot read properties of null (reading 'type')", | ||
}, | ||
}, | ||
} | ||
|
||
export const WithStackTrace = Template.bind({}) | ||
WithStackTrace.args = { | ||
result: { | ||
status: TestStepResultStatus.FAILED, | ||
message: | ||
"TypeError: Cannot read properties of null (reading 'type')\n at TodosPage.addItem (/Users/somebody/Projects/my-project/support/pages/TodosPage.ts:39:21)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\n at CustomWorld.<anonymous> (/Users/somebody/Projects/my-project/support/steps/steps.ts:20:5)", | ||
exception: { | ||
type: 'TypeError', | ||
message: "Cannot read properties of null (reading 'type')", | ||
stackTrace: | ||
' at TodosPage.addItem (/Users/somebody/Projects/my-project/support/pages/TodosPage.ts:39:21)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\n at CustomWorld.<anonymous> (/Users/somebody/Projects/my-project/support/steps/steps.ts:20:5)', | ||
}, | ||
}, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { TestStepResult } from '@cucumber/messages' | ||
import React, { FC } from 'react' | ||
|
||
import { ErrorMessage } from '../gherkin/index.js' | ||
|
||
export const TestStepResultDetails: FC<TestStepResult> = ({ message, exception }) => { | ||
if (exception) { | ||
return ( | ||
<ErrorMessage> | ||
<strong>{exception.type}</strong> {exception.message} | ||
{exception.stackTrace && <div>{exception.stackTrace}</div>} | ||
</ErrorMessage> | ||
) | ||
} | ||
if (message) { | ||
return <ErrorMessage>{message}</ErrorMessage> | ||
} | ||
return null | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './TestStepResultDetails.js' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in a backwards-compatible way to allow content as
children
instead of a string prop - we need this to use in our new component.