test262 icon indicating copy to clipboard operation
test262 copied to clipboard

Improve error messages from compareArray

Open ptomato opened this issue 2 months ago • 0 comments

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.

ptomato avatar Oct 08 '25 16:10 ptomato