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

Improves the terse messages in jest-editor #3615

Merged
merged 5 commits into from
May 22, 2017

Conversation

orta
Copy link
Member

@orta orta commented May 19, 2017

Summary

The terse messages sometimes were not terse, as they're built for showing inline they definitely needed cutting down to size in some places. So I made a list of some common failing assertions and added some tests against each of them.

screen shot 2017-05-19 at 14 54 46

I turned the results of this into a fixture, and started working from that.

Test plan

This has unit tests 👍

@@ -1,5 +1,5 @@
{
"jest.pathToJest": "npm run jest --",
"jest.pathToJest": "yarn jest --",
Copy link
Member Author

Choose a reason for hiding this comment

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

Works nicely, but it should be yarn to fit with the rest of the dev recommendations

screen shot 2017-05-19 at 16 02 17

if (string.includes("New snapshot was not written")) {
return "New snapshot is ready to write"
}

Copy link
Member Author

Choose a reason for hiding this comment

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

These are some special cases, you can't show anything of value for these two cases in a tweet-sized message, so I've added them as special cases.

.replace('Difference:', ' Difference:');
.replace(/\s\s+/g, ' ')
.replace('Received:', ', Received:')
.split('Difference:')[0];
Copy link
Member Author

Choose a reason for hiding this comment

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

Turned out the two replaces above had some invisible control characters too:

screen shot 2017-05-19 at 15 58 49

message = "Expected value to be truthy, instead received null"
testName = "truthy"
expect(terseForTest(testName).terseMessage).toEqual(message)
})
Copy link
Member Author

Choose a reason for hiding this comment

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

didn't think it was worth having all the work split across multiple its - it slows down the tests needlessly with all the JSON parsing + string manipulation.

@@ -108,15 +108,24 @@ module.exports = class TestReconciler {

// Do everything we can to try make a one-liner from the error report
sanitizeShortErrorMessage(string: string): string {
if (string.includes("does not match stored snapshot")) {
Copy link
Member

Choose a reason for hiding this comment

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

We need more structured data around this so that it won't break going forward.

Copy link
Member Author

@orta orta May 19, 2017

Choose a reason for hiding this comment

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

I had a look at this, but the way things are pieced together is like this:

screen shot 2017-05-19 at 16 24 28

There is a this test which incidentally covers this case, I could add comments to it?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, adding a comment for now would be very nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool - added

@@ -52,3 +52,41 @@ Expected value to be falsy, instead received
});
});
});

describe('Terse Messages', () => {
it("handles shrinking a snapshot message", () => {
Copy link
Member

Choose a reason for hiding this comment

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

single quote please (did you run prettier on this file?)

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like it wasn't set up to run, I've fixed that - good catch.

@cpojer
Copy link
Member

cpojer commented May 19, 2017

@orta mind making sure that yarn lint is successful?

@orta orta force-pushed the better_terse_messages branch from 5c1e572 to 8359083 Compare May 19, 2017 23:54
@orta
Copy link
Member Author

orta commented May 20, 2017

🥗

@cpojer cpojer merged commit 7e2e2b6 into jestjs:master May 22, 2017
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
* Improves the terse messages in jest-editor

* Adds a note about wording for jest-editor inside a test that matches the error it is implicity relying on

* Adds a note about wording for jest-editor inside a test that matches the error it is implicity relying on
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants