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

fix: Add optional regex check for comma preceding 'but' in assertions for command formatting #29517

Merged
merged 5 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ _Released 5/21/2024 (PENDING)_
**Bugfixes:**

- Fixed an issue where Cypress was unable to search in the Specs list for files or folders containing numbers. Fixes [#29034](https://github.com/cypress-io/cypress/issues/29034).
- Fixed the display of some command assertions. Fixed in [#29517](https://github.com/cypress-io/cypress/pull/29517).

**Dependency Updates:**

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 @@ -71,6 +71,13 @@ describe('formattedMessage', () => {
expect(result).to.equal('expected <strong>span</strong> to have CSS property <strong>background-color</strong> with the value <strong>rgb(0, 0, 0)</strong>, but the value was <strong>rgba(0, 0, 0, 0)</strong>')
})

it('bolds asterisks with "but" without comma', () => {
const specialMessage = 'expected **foo** to have length above **1** but got **0**'
const result = formattedMessage(specialMessage)

expect(result).to.equal('expected <strong>foo</strong> to have length above <strong>1</strong> but got <strong>0</strong>')
})

it('bolds asterisks with simple assertions', () => {
const specialMessage = 'expected **dom** to be visible'
const result = formattedMessage(specialMessage, 'assert')
Expand Down
3 changes: 2 additions & 1 deletion packages/reporter/src/commands/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ 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)**`
// `expected **foo** to have length above **1** but got **0**`
// `Custom message expected **<span>** to exist in the DOM`
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)
Expand Down
Loading