Skip to content

Improve error messages from compareArray #4595

@ptomato

Description

@ptomato

The assert.compareArray function produces error messages like this:

Actual [up, up, down, down, left, right, left, b, a, start] and expected [up, up, down, down, left, right, left, right, b, a, start] should have the same contents.

Difficult to spot the difference at a glance. When debugging tests with long lists I've resorted to hacks like:

  • Paste the error message into a text editor, turn off word wrapping, and align the opening square brackets of the actual and expected arrays on consecutive lines so I can visually see where the two arrays diverge, e.g.
    [up, up, down, down, left, right, left, b, a, start]
    [up, up, down, down, left, right, left, right, b, a, start]
    
  • If running tests using Node.js as a host, patching assert.deepStrictEqual into the harness file, which produces a much more debuggable error message:
    Expected values to be strictly deep-equal:
    + actual - expected
    ... Skipped lines
    
      [
        'up',
        'up',
        'down',
        'down',
    ...
        'left',
    -   'right',
        'b',
        'a',
        'start'
      ]
    

I have no specific improvement in mind, but I'm opening this issue to follow up from our discussion in the maintainers meeting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions