-
Notifications
You must be signed in to change notification settings - Fork 984
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
Improve test failure readability #18049
Conversation
Jenkins BuildsClick to see older builds (11)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, looks great! Had to do the diffing manually once and it wasn't pleasant
774f46e
to
e2adeb7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving only Nix related changes.
The namespace matcher-combinators.test must be required in namespaces using "match?"
e2adeb7
to
47ec1be
Compare
77% of end-end tests have passed
Failed tests (4)Click to expandClass TestOneToOneChatMultipleSharedDevicesNewUi:
Class TestCommunityMultipleDeviceMergedTwo:
Class TestCommunityOneDeviceMerged:
Expected to fail tests (7)Click to expandClass TestOneToOneChatMultipleSharedDevicesNewUi:
Class TestCommunityMultipleDeviceMerged:
Class TestOneToOneChatMultipleSharedDevicesNewUiTwo:
Class TestCommunityOneDeviceMerged:
Class TestGroupChatMultipleDeviceMergedNewUI:
Passed tests (37)Click to expandClass TestActivityMultipleDevicePRTwo:
Class TestDeepLinksOneDevice:
Class TestOneToOneChatMultipleSharedDevicesNewUi:
Class TestCommunityMultipleDeviceMerged:
Class TestActivityCenterContactRequestMultipleDevicePR:
Class TestCommunityMultipleDeviceMergedTwo:
Class TestGroupChatMultipleDeviceMergedNewUI:
Class TestCommunityOneDeviceMerged:
Class TestActivityMultipleDevicePR:
Class TestOneToOneChatMultipleSharedDevicesNewUiTwo:
|
Problem: failed equality checks as in "(is (= expected actual))" will give a single, long line of output that for anything but the simplest data structures is unreadable by humans, and the output doesn't give a useful diff. Solution: use library https://github.com/nubank/matcher-combinators and its test directive "match?" which will pinpoint where two data structures differ. Then, instead of "(is (= ...", use "(is (match? expected actual)". It works beautifully. The library offers other nice matchers, but the majority of the time match? is sufficient. Can we use another test runner like Kaocha? kaocha-cljs2 (https://github.com/lambdaisland/kaocha-cljs2) would be able to print better test errors out of the box, among other features, but I have no clue if it would work well or at all in our stack (in theory yes, but it's a larger piece of work).
Summary
This PR is one of those you regret not opening before, way before. Problem: failed equality checks as in
(is (= expected actual))
will give a single, long line of output that for anything but the simplest data structures is unreadable by humans, and the output doesn't give a useful diff. For me, unit testing so far in status-mobile has been one of the most insufferable experiences ever because of that alone.The solution is simple: use library https://github.com/nubank/matcher-combinators which will define a directive
match?
which will pinpoint where two data structures differ. Then, instead of(is (= ...
, use(is (match? expected actual)
. It works beautifully.No need to require any extra namespace, the directives are injected once in(false, in the CI the ClojureScript compiler couldn't find thestatus-im.test-runner
match?
directive).Without this PR, if a test fails, I often had to copy the output, format it with zprint and diff two buffers and still manually scan the output hunting for a diff. It could be automated more, but it's just not worth it and it doesn't solve the problem for other devs.
Note
Guidelines were updated too: https://github.com/status-im/status-mobile/blob/ilmotta/improve-readability-of-test-failures/doc/new-guidelines.md#prefer-match-over--when-comparing-data-structures.
The library offers other nice matchers, but the majority of the time
match?
is sufficient.Can we use another test runner like Kaocha?
kaocha-cljs2 would be able to print better test errors out of the box, among other features, but I have no clue if it would work well or at all in our stack (in theory yes, but it's a larger piece of work).
Demo
Areas that maybe impacted
None, just a few test namespaces were changed from using
(is (= ...)
to(is (match? ...)
status: ready