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

74 - Add diff renderer and improve reporting #113

Merged
merged 21 commits into from
Dec 27, 2023
Merged

Conversation

Derpius
Copy link
Member

@Derpius Derpius commented Dec 23, 2023

Issue

Resolves #74

Changes

  • Repurposed prettyValue into serialiseValue, which recursively prints tables that do not have an overridden tostring
    • This is aligned with Jest
  • Added a new renderDiff function which is used to generate a diff between any two values, optionally performing a "deep" recursive diff
  • Updated all code using prettyValue to use serialiseValue
  • Changed require paths to remove the need for src.lua. in every require()
    • Paths should be changed in any files that would be included in the diff regardless
  • Fixed matcher assertions printing the stack trace twice
  • Changed the test result error to not colour its message body
    • This allows matchers to colour their own message (needed for renderDiff)
  • Changed the expect print to not serialise the values into expect(...).matcherName(...) to avoid duplicating information

Impact

  • Significantly improves the user experience of Lest by allowing users to immediately see deep inequalities in tables through the diff
  • Improves the reporting for non-deep equality tests to better highlight expected and received values
  • All existing test failure messages will change colour from red to white
  • DevX improved by removing the need to import from src.lua manually, and automatically importing index.lua files when a directory path is given

Testing

Fairly well covered by automated tests, but should try the following:

  • toBe failure messages display serialised expected and received with no table diff rendering
  • toEqual failure messages match toBe if one or both values are not a table
  • toEqual failure messages for two tables
    • handles cyclic references
    • shows correct expected and received counts for the number of differences
    • correctly chooses whether a value can be added to the table as an array item ({1, 2, 3}), symbol key ({foo = "bar"}) or expression key ({["end"] = "bar"})
    • correctly marks fields as either unchanged, added, removed or changed (added and removed adjacent for same key)
  • never.toBe and never.toEqual failure messages always show the serialised expected value in the format Expected: not %s

Helpful Links

API Docs

Project Board

Discord

@Derpius Derpius requested a review from a team December 23, 2023 18:52
@Derpius Derpius linked an issue Dec 23, 2023 that may be closed by this pull request
@yogwoggf
Copy link
Contributor

If @Vurv78 doesn't pick this up later today then I'll probably start a review

Copy link
Contributor

@yogwoggf yogwoggf left a comment

Choose a reason for hiding this comment

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

LGTM 👍

local function isLuaSymbol(value)
return type(value) == "string"
and not KEYWORDS[value]
and not not string.match(value, "^[_%a][_%a%d]*$")
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to confirm, this is a boolean coercion right? Looks sort of strange

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, to avoid returning a non-boolean here

@Derpius Derpius merged commit c0f015c into master Dec 27, 2023
13 checks passed
@Derpius Derpius deleted the 74-diff-renderer branch December 27, 2023 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Diff generator
2 participants