Skip to content

Commit

Permalink
fix: Remove erroneous <br> tags from error messages (#28496)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifer-shehane authored Dec 12, 2023
1 parent 57ef4b8 commit c061fd8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
8 changes: 8 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
## 13.6.2

_Released 12/19/2023 (PENDING)_

**Bugfixes:**

- Fixed a regression in [`12.4.0`](https://docs.cypress.io/guides/references/changelog/12.4.0) where erroneous `<br>` tags were displaying in error messages in the Command Log making them less readable. Fixes [#28452](https://github.com/cypress-io/cypress/issues/28452).

## 13.6.1

_Released 12/5/2023_
Expand Down
9 changes: 9 additions & 0 deletions packages/reporter/cypress/e2e/test_errors.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ describe('test errors', () => {
cy.wrap(runner.emit).should('be.calledWith', 'external:open', 'https://on.cypress.io/type')
})

// https://github.com/cypress-io/cypress/issues/28452
it('does not show br tags in formatted error message', () => {
setError(commandErr)

cy.spy(runner, 'emit')

cy.get('.runnable-err-message').find('br').should('not.exist')
})

// NOTE: still needs to be implemented
it.skip('renders and escapes markdown with leading/trailing whitespace', () => {
setError(commandErr)
Expand Down
2 changes: 1 addition & 1 deletion packages/reporter/cypress/fixtures/command_error.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CommandError",
"message": "`foo` \\`bar\\` **baz** *fizz* ** buzz **",
"message": "`foo` \\`bar\\` \n**baz** *fizz* ** buzz **",
"stack": "Some Error\n at foo.bar (my/app.js:2:7)\n at baz.qux (cypress/integration/foo_spec.js:5:2)\n at space (cypress/integration/a b.js:34:99)\n From previous event:\n at bar.baz (my/app.js:8:11)\n ",
"parsedStack": [
{
Expand Down
10 changes: 6 additions & 4 deletions packages/reporter/src/commands/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import HiddenIcon from '@packages/frontend-shared/src/assets/icons/general-eye-c
import PinIcon from '@packages/frontend-shared/src/assets/icons/object-pin_x16.svg'
import RunningIcon from '@packages/frontend-shared/src/assets/icons/status-running_x16.svg'

const md = new Markdown({ breaks: true })

const displayName = (model: CommandModel) => model.displayName || model.name
const nameClassName = (name: string) => name.replace(/(\s+)/g, '-')

export const formattedMessage = (message: string) => {
const mdBreaks = new Markdown({ breaks: true })
const md = new Markdown()

export const formattedMessage = (message: string, type: string) => {
if (!message) return ''

const searchText = ['to match', 'to equal']
Expand All @@ -38,7 +39,8 @@ export const formattedMessage = (message: string) => {
const matchingText = searchText.find((text) => message.includes(text))
const textToConvert = [split[0].trim(), ...(matchingText ? [matchingText] : [])].join(' ')
const spaceEscapedText = textToConvert.replace(/^ +/gm, (initialSpaces) => '&#32;'.repeat(initialSpaces.length)) // &#32 is the HTML entity for a space
const converted = md.renderInline(spaceEscapedText)
// we don't want <br> in our error messages, but allow it in Cypress.log
const converted = type === 'error' ? md.renderInline(spaceEscapedText) : mdBreaks.renderInline(spaceEscapedText)
const assertion = (split[1] && [`<strong>${split[1].trim()}</strong>`]) || []

return [converted, ...assertion].join(' ')
Expand Down
2 changes: 1 addition & 1 deletion packages/reporter/src/errors/test-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const TestError = (props: TestErrorProps) => {
{groupPlaceholder}
<div className='runnable-err-content'>
<div className='runnable-err-message'>
<span dangerouslySetInnerHTML={{ __html: formattedMessage(err.message) }} />
<span dangerouslySetInnerHTML={{ __html: formattedMessage(err.message, 'error') }} />
<DocsUrl url={err.docsUrl} />
</div>
{codeFrame && <ErrorCodeFrame codeFrame={codeFrame} />}
Expand Down

4 comments on commit c061fd8

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c061fd8 Dec 12, 2023

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.2/linux-x64/develop-c061fd8900b7cdd3ac54cee5d80a6d4ab2fa1d71/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c061fd8 Dec 12, 2023

Choose a reason for hiding this comment

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

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.2/linux-arm64/develop-c061fd8900b7cdd3ac54cee5d80a6d4ab2fa1d71/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c061fd8 Dec 12, 2023

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.2/darwin-x64/develop-c061fd8900b7cdd3ac54cee5d80a6d4ab2fa1d71/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c061fd8 Dec 12, 2023

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.2/win32-x64/develop-c061fd8900b7cdd3ac54cee5d80a6d4ab2fa1d71/cypress.tgz

Please sign in to comment.