Skip to content

Commit

Permalink
fix: Fix issue with display of assertions when using custom messages (#…
Browse files Browse the repository at this point in the history
…29243)

* fix: added optional custom message to regex

* add changelog entry

* Update packages/reporter/cypress/e2e/unit/formatted_message.cy.ts

* moved changelog entry to new cypress version

---------

Co-authored-by: Jennifer Shehane <shehane.jennifer@gmail.com>
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
  • Loading branch information
3 people authored Apr 10, 2024
1 parent 96b14c3 commit 1fa3e7f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ _Released 4/16/2024 (PENDING)_

**Bugfixes:**

- Fixed an issue where asserts with custom messages weren't displaying properly. Fixes [#29167](https://github.com/cypress-io/cypress/issues/29167)
- Fixed and issue where cypress launch arguments were not being escaped correctly with multiple values inside quotes. Fixes [#27454](https://github.com/cypress-io/cypress/issues/27454).


Expand Down
7 changes: 7 additions & 0 deletions packages/reporter/cypress/e2e/unit/formatted_message.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ describe('formattedMessage', () => {

expect(result).to.equal('expected <strong>&lt;button#increment&gt;</strong> to be enabled')
})

it('renders the custom message properly with the assertion message', () => {
const specialMessage = 'My Custom Message: expected **abcdef** to equal **abcdef**'
const result = formattedMessage(specialMessage, 'assert')

expect(result).to.equal('My Custom Message: expected <strong>abcdef</strong> to equal <strong>abcdef</strong>')
})
})

describe('when command that accepts url', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/reporter/src/commands/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ const asterisksRegex = /^\*\*(.+?)\*\*$/gs
// 'expected **<span>** to exist in the DOM'
// `expected **glob*glob** to contain *****`
// `expected **<span>** to have CSS property **background-color** with the value **rgb(0, 0, 0)**, but the value was **rgba(0, 0, 0, 0)**`
const assertionRegex = /expected | to[^\*]+| not[^\*]+| with[^\*]+|, but[^\*]+/g
const assertionRegex = /.*expected | to[^\*]+| not[^\*]+| with[^\*]+|, but[^\*]+/g

// used to format the display of command messages and error messages
// we use markdown syntax within our error messages (code ticks, urls, etc)
// and cy.log and Cypress.log supports markdown formatting
export const formattedMessage = (message: string, name?: string) => {
if (!message) return ''

// the command message is formatted as 'expected <actual> to {assertion} <expected>'
// the command message is formatted as '(Optional Custom Msg:) expected <actual> to {assertion} <expected>'
const assertionArray = message.match(assertionRegex)

const expectedActualArray = () => {
Expand Down

5 comments on commit 1fa3e7f

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1fa3e7f Apr 10, 2024

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.7.3/linux-x64/develop-1fa3e7f8c65d4cc35fb97d11d6d429663f754199/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1fa3e7f Apr 10, 2024

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.7.3/linux-arm64/develop-1fa3e7f8c65d4cc35fb97d11d6d429663f754199/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1fa3e7f Apr 10, 2024

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.7.3/darwin-x64/develop-1fa3e7f8c65d4cc35fb97d11d6d429663f754199/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1fa3e7f Apr 10, 2024

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 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.7.3/darwin-arm64/develop-1fa3e7f8c65d4cc35fb97d11d6d429663f754199/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1fa3e7f Apr 10, 2024

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.7.3/win32-x64/develop-1fa3e7f8c65d4cc35fb97d11d6d429663f754199/cypress.tgz

Please sign in to comment.