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 formatting in Command Log test results. #5619

Merged
merged 8 commits into from
Nov 12, 2019

Conversation

sainthkh
Copy link
Contributor

@sainthkh sainthkh commented Nov 7, 2019

I fixed these 3 issues together because implementing one logic can affect other issues.

User facing changelog

  • Formats number strings in test results in quotes. In other words, 25 -> '25'.
  • Formats keys properly.
  • Formats when there are empty spaces between ** and **.

Additional details

Why was this change necessary:

Issue #25

The ASSERT error (in red background) on the commands UI does not signify whether my value is a string or not.

Issue #753

All versions of Cypress when making this assertion

it('expect - assert shape of an object', function(){
  const person = {
    name: 'Joe',
    age: 20
  }
  expect(person).to.have.all.keys('name', 'age')
})

Look at the reporter message - looks very weird

Issue #1360

Command Log for assertion chain includes confusing asterisks. I suspect it may be replacing \n with **.

What is affected by this change?

Not much. I added a few tests to show this case clearly.

Any implementation details to explain?

Not much. Just fixed some regexes.

How has the user experience changed?

Before: above.

After:

Screenshot from 2019-11-07 10-56-15

Screenshot from 2019-11-11 11-36-39

PR Tasks

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 7, 2019

Thanks for the contribution! Below are some guidelines Cypress uses when doing PR reviews.

  • Please write [WIP] in the title of your Pull Request if your PR is not ready for review - someone will review your PR as soon as the [WIP] is removed.
  • Please familiarize yourself with the PR Review Checklist and feel free to make updates on your PR based on these guidelines.

PR Review Checklist

If any of the following requirements can't be met, leave a comment in the review selecting 'Request changes', otherwise 'Approve'.

User Experience

  • The feature/bugfix is self-documenting from within the product.
  • The change provides the end user with a way to fix their problem (no dead ends).

Functionality

  • The code works and performs its intended function with the correct logic.
  • Performance has been factored in (for example, the code cleans up after itself to not cause memory leaks).
  • The code guards against edge cases and invalid input and has tests to cover it.

Maintainability

  • The code is readable (too many nested 'if's are a bad sign).
  • Names used for variables, methods, etc, clearly describe their function.
  • The code is easy to understood and there are relevant comments explaining.
  • New algorithms are documented in the code with link(s) to external docs (flowcharts, w3c, chrome, firefox).
  • There are comments containing link(s) to the addressed issue (in tests and code).

Quality

  • The change does not reimplement code.
  • There's not a module from the ecosystem that should be used instead.
  • There is no redundant or duplicate code.
  • There are no irrelevant comments left in the code.
  • Tests are testing the code’s intended functionality in the best way possible.

Internal

  • The original issue has been tagged with a release in ZenHub.

@brian-mann
Copy link
Member

Let's get some eyes on this and get this out in 3.6.1 @cypress-io/test-runner team

@jennifer-shehane jennifer-shehane changed the title Fix formatting in test results. Fix formatting in Command Log test results. Nov 8, 2019
@kuceb
Copy link
Contributor

kuceb commented Nov 8, 2019

We'll need actual assertions on the output during the tests that have been added. Right now there's no way for them to fail

Comment on lines 998 to 1028
it('preserves quotation marks in empty string', function () {
try {
expect(42).to.eq('')
} catch (error) {} /* eslint-disable-line no-empty */
})

it('preserves quotation marks if escaped', function () {
expect('\'cypress\'').to.eq('\'cypress\'')
})

it('removes quotation marks in DOM elements', function () {
cy.get('body').should('contain', 'div')
})

it('removes quotation marks in strings', function () {
expect('cypress').to.eq('cypress')
})

it('removes quotation marks in objects', function () {
expect({ foo: 'bar' }).to.deep.eq({ foo: 'bar' })
})

it('formats keys properly for "have.all.keys"', function () {
const person = {
name: 'Joe',
age: 20,
}

expect(person).to.have.all.keys('name', 'age')
})
})
Copy link
Contributor

Choose a reason for hiding this comment

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

would these have failed before the src changes? We should add assertions on the log output to turn these into valid tests

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. We need tests that actually verify this behavior. It might be worthwhile to move out and expose the removeOrKeepSingleQuotesBetweenStars and replaceArgMessages so they can be tested unit-style.

Copy link
Contributor Author

@sainthkh sainthkh Nov 11, 2019

Choose a reason for hiding this comment

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

I've checked the tests in assertions_spec.js and mimicked the tests it uses to validate message fixes I've done.

age: 20,
}

expect(person).to.have.all.keys('name', 'age')
Copy link
Contributor

Choose a reason for hiding this comment

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

this one's showing up for me without the bold
image

Copy link
Contributor Author

@sainthkh sainthkh Nov 11, 2019

Choose a reason for hiding this comment

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

I've added tests for "boldness". If the tests failed and something like that happens, please tell me.

p.s. I doubt it has something to do with the font setting. When I look at them closely, name and age are a little bit bolder than other texts, I guess. (When we compare a in name of the object and a in have keys. We can see that the former a is a bit darker than the latter a.

It would be great if we have other messages to compare the boldness.

@sainthkh
Copy link
Contributor Author

  1. Added one more issue: asterisks displaying instead of single quotes in Command Log assertion #1360. Because I thought it is also related with this PR.
  2. build-binary failed because of tar.extract. It seems that it's unrelated to this PR.

it('preserves quotation marks if escaped', (done) => {
expectMarkdown(
() => expect(`\'cypress\'`).to.eq(`\'cypress\'`),
// ****'cypress'**** -> ** for emphasizing result string + ** for emphasizing the entire result.
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for adding this comment 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, when I saw this, I was too wondering why this happened.

And thought many developers who will read this code later would be confused when they saw ****. That's why I've added this comment.

@kuceb
Copy link
Contributor

kuceb commented Nov 12, 2019

Awesome job @sainthkh!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants