Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 21, 2026

Test failure output shows actual and expected values in the same color, making mismatches hard to spot:

Expected 'aaba' to equal specified value: 'ba'

Changes

  • Parse lab failure output to extract actual/expected values from multiple @hapi/code assertion patterns:
    • Expected <actual> to equal specified value: <expected>
    • Expected <actual> to include <expected>
    • Expected <actual> to contain <expected> (displays as "include")
  • Set TestMessage properties actualOutput and expectedOutput to trigger VS Code's native diff view with red/green highlighting
  • Handle edge cases including quote removal (only paired quotes), ANSI stripping, and non-comparison errors

Implementation

Added FailureInfo interface and enhanced parseErrorMessage():

interface FailureInfo {
  message: string;
  actualOutput?: string;
  expectedOutput?: string;
}

const testMessage = new vscode.TestMessage(failureInfo.message);
if (failureInfo.actualOutput && failureInfo.expectedOutput) {
  testMessage.actualOutput = failureInfo.actualOutput;
  testMessage.expectedOutput = failureInfo.expectedOutput;
}

Applies to inline editor decorations, Test Explorer tooltips, and the Test Results panel.

Original prompt

This section details on the original issue you should resolve

<issue_title>No colour differentiation for actual/expected values in test failure output</issue_title>
<issue_description>When a test fails due to an expectation mismatch, the actual and expected values are displayed without colour differentiation, making them hard to distinguish at a glance.

Current behaviour

Failure output shows:
```
actual expected

'aaba'

Expected 'aa' to equal specified value: 'ba'
```
All text appears in the same colour.

Suggested behaviour

Apply colour coding to differentiate:

  • Actual value (e.g., red)
  • Expected value (e.g., green)

This should apply to:

  1. The inline failure message in the editor
  2. The tooltip next to the test name

Feedback from Kevin Paxton</issue_description>

<agent_instructions>ensure commits are in semantic release format</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 21, 2026 17:36
…ilures

- Parse @hapi/lab failure output to extract actual and expected values
- Set TestMessage actualOutput and expectedOutput properties to enable VS Code's diff view
- Add comprehensive tests for parseErrorMessage function
- Export parseErrorMessage for testing purposes

Co-authored-by: mtharrison <916064+mtharrison@users.noreply.github.com>
- Update cleanValue function to only remove quotes when they appear at both start and end
- Prevents incorrect quote removal from mismatched or single-sided quotes
- Addresses code review feedback

Co-authored-by: mtharrison <916064+mtharrison@users.noreply.github.com>
Copilot AI changed the title [WIP] Add colour differentiation for actual and expected values in test output feat: add color differentiation for actual/expected values in test failures Jan 21, 2026
Copilot AI requested a review from mtharrison January 21, 2026 17:42
@mtharrison
Copy link
Owner

Screenshot 2026-01-21 at 18 22 23 @copilot I would like to see colour coded comparison between expected and actual assertion in the tooltip next to the test name

- Update regex to match "to include" and "to contain" patterns in addition to "to equal"
- Add tests for include and contain assertion failures
- Fixes color differentiation for @hapi/code assertions like "expect(x).to.include(y)"

Co-authored-by: mtharrison <916064+mtharrison@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 21, 2026

Screenshot 2026-01-21 at 18 22 23 @copilot I would like to see colour code...

Updated the regex pattern in commit 81c4dc6 to support "to include" and "to contain" assertions in addition to "to equal".

The extension now extracts actual and expected values from assertions like:

  • Expected { a: 1 } to include { b: 1 }
  • Expected 'hello' to include 'world'
  • Expected 'foo' to equal specified value: 'bar'

When both actualOutput and expectedOutput are set on the TestMessage, VS Code automatically displays them in a color-coded diff view (red for actual, green for expected) in the tooltip next to the test name, inline editor decorations, and the Test Results panel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No colour differentiation for actual/expected values in test failure output

2 participants