Skip to content

test_runner: support custom message for expectFailure - #61563

Merged
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
sangwook-dev:test-runner/support-getxfail-message
Feb 26, 2026
Merged

nodejs-github-bot merged 2 commits into
nodejs:mainfrom
sangwook-dev:test-runner/support-getxfail-message

Conversation

@sangwook-dev

@sangwook-dev sangwook-dev commented Jan 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR enhances the expectFailure option in the test runner to accept different types of values, enabling both custom failure labels and robust error validation. This implementation is referenced from and inspired by nodejs/test-runner#10.

Changes

The expectFailure option now supports the following types:

  • String: Treated as a failure label (reason).

    test('bug', { expectFailure: 'Investigating' }, ...);
  • RegExp / Function / Error Class: Treated as a matcher to validate the thrown error (similar to assert.throws).

    test('regex', { expectFailure: /error message/ }, ...);
    test('class', { expectFailure: RangeError }, ...);
  • Object:

    • If it contains label or match properties, it's treated as a configuration object.
      test('config', {
        expectFailure: {
          label: 'Known issue',
          match: /specific error/
        }
      }, ...);
    • Otherwise, it's treated as an object matcher (properties matching).
  • Inheritance:

    • Tests now inherit expectFailure from their parent suite. This allows marking an entire suite as expected to fail.
      test('suite', { expectFailure: true }, async (t) => {
        await t.test('subtest', () => { throw new Error(); }); // Passes (expected failure)
      });

References

Resolves: #61570

@nodejs-github-bot

ghost commented Jan 28, 2026

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Jan 28, 2026
Comment thread doc/api/test.md Resolved

ghost left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We already have a plan for the value of expectFail: it will soon accept a regular expression to match against.

@sangwook-dev

ghost commented Jan 28, 2026

Copy link
Copy Markdown
Contributor Author

We already gave a plan for the value of expectFail: it will soon accept a regular expression to match against.

@JakobJingleheimer
Ah, thanks for the context! I missed that there was an existing plan for error matching.

In that case, I'd be happy to pivot this PR to implement the expectFailure validation logic (accepting a string/regex to match the error) instead of just a message. Does that sound good, or is there someone else already working on it?"

@JakobJingleheimer

ghost commented Jan 28, 2026

Copy link
Copy Markdown
Member

@vassudanagunta you were part of the original discussion; did you happen to start an implementation?

To my knowledge though, no-one has started.

I had planned to pick it up next week, but if you would like to do, go ahead.

If you do, I think it would probably be better to start a new PR than to pivot this one. So open a draft and I'll add it to the test-runner team's kanban board so it gets proper visibility.

@codecov

ghost commented Jan 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.95181% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.75%. Comparing base (da5efc4) to head (4c7bb37).
⚠️ Report is 26 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/test_runner/test.js 87.80% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61563      +/-   ##
==========================================
+ Coverage   88.84%   89.75%   +0.91%     
==========================================
  Files         674      674              
  Lines      204957   205682     +725     
  Branches    39309    39438     +129     
==========================================
+ Hits       182087   184607    +2520     
+ Misses      15088    13316    -1772     
+ Partials     7782     7759      -23     
Files with missing lines Coverage Δ
lib/internal/test_runner/reporter/tap.js 94.88% <100.00%> (ø)
lib/internal/test_runner/test.js 96.85% <87.80%> (-0.49%) ⬇️

... and 182 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vassudanagunta

ghost commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

@JakobJingleheimer nope, haven't started this, though I had long ago implemented it in node-test-extra (not yet released).

I think it's important to get the requirements nailed. IMHO, #61570.

@JakobJingleheimer

ghost commented Jan 28, 2026

Copy link
Copy Markdown
Member

As I said, let's put together a proposal in the nodejs/test_runner repo 🙂

@vassudanagunta

This comment was marked as resolved.

@ljharb

ghost commented Jan 28, 2026

Copy link
Copy Markdown
Member

reviewed before reading the discussion; imo a string should work as in this PR whether or not it also supports accepting a regex.

@JakobJingleheimer

ghost commented Jan 28, 2026

Copy link
Copy Markdown
Member

It could do. My concern is supporting this without considering the intended regex feature accidentally precluding that intended feature, or inadvertently creating a breaking change, or creating heavily conflicting PRs (very frustrating for the implementators).

I think we can likely get both; we can easily avoid those problems with a quick proposal so everyone is on the same page 🙂


I should start a discussion in that repo?

Please start a proposal like the ones already in that repo 🙂 https://github.com/nodejs/test-runner/tree/main/proposals we can discuss it in that PR

@ljharb

ghost commented Jan 28, 2026

Copy link
Copy Markdown
Member

conflicts fair; as long as the "should expect failure" uses truthiness (does an empty string count as true or false, though?), i can't foresee any semantic collision.

@sangwook-dev

ghost commented Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

@ljharb @vassudanagunta

I've opened a proposal PR in the test-runner repository as suggested by @JakobJingleheimer.
It would be great to continue the discussion on the spec details there:
nodejs/test-runner#10

Comment thread doc/api/test.md Resolved
@sangwook-dev
sangwook-dev marked this pull request as draft January 31, 2026 07:56
@sangwook-dev sangwook-dev reopened this Feb 3, 2026
@sangwook-dev
sangwook-dev marked this pull request as ready for review February 3, 2026 22:45
@sangwook-dev
sangwook-dev force-pushed the test-runner/support-getxfail-message branch from 061f049 to 346ec8f Compare February 4, 2026 00:49

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this needs to be documented a little better for the user.

Comment thread doc/api/test.md Resolved
Comment thread doc/api/test.md Resolved
Comment thread doc/api/test.md Resolved
Comment thread doc/api/test.md Resolved
Comment thread doc/api/test.md Resolved
@JakobJingleheimer

ghost commented Feb 4, 2026 •

Copy link
Copy Markdown
Member

@Han5991 the proposal isn't finished / accepted yet (still hasn't been reviewed by the rest of the test-runner team), so I think it's premature to resume this (the proposal isn't a requirement, but I think it's a good idea and will reduce churn, needless re-reviews, etc—and indeed, there was just earlier today another adjustment to align terms). I do appreciate the enthusiasm 😁

It's added to the team's agenda, so it'll get raised at the next meeting.

@JakobJingleheimer JakobJingleheimer added the commit-queue-squash PRs the Commit Queue should land as one squashed commit. label Feb 26, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Feb 26, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

ghost commented Feb 26, 2026

Copy link
Copy Markdown
Collaborator

@JakobJingleheimer JakobJingleheimer added commit-queue PRs queued for automated landing through the Commit Queue. and removed commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. labels Feb 26, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Feb 26, 2026
@nodejs-github-bot

ghost commented Feb 26, 2026

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/61563
✔  Done loading data for nodejs/node/pull/61563
----------------------------------- PR info ------------------------------------
Title      test_runner: support custom message for expectFailure (#61563)
Author     sangwook <rewq5991@gmail.com> (@Han5991)
Branch     Han5991:test-runner/support-getxfail-message -> nodejs:main
Labels     needs-ci, commit-queue-squash, test_runner
Commits    2
 - test_runner: expose expectFailure message
 - test_runner: fix empty object test assert logic
Committers 1
 - sangwook <rewq5991@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/61563
Fixes: https://github.com/nodejs/node/issues/61570
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Jacob Smith <jacob@frende.me>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/61563
Fixes: https://github.com/nodejs/node/issues/61570
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Jacob Smith <jacob@frende.me>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Wed, 28 Jan 2026 14:50:42 GMT
   ✔  Approvals: 3
   ✔  - Jordan Harband (@ljharb): https://github.com/nodejs/node/pull/61563#pullrequestreview-3719402319
   ✔  - Aviv Keller (@avivkeller): https://github.com/nodejs/node/pull/61563#pullrequestreview-3723610081
   ✔  - Jacob Smith (@JakobJingleheimer): https://github.com/nodejs/node/pull/61563#pullrequestreview-3857218091
   ✘  Last GitHub CI failed
   ℹ  Last Full PR CI on 2026-02-26T09:15:39Z: https://ci.nodejs.org/job/node-test-pull-request/71464/
- Querying data for job/node-test-pull-request/71464/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/22437607383

@sangwook-dev

ghost commented Feb 26, 2026

Copy link
Copy Markdown
Contributor Author

@JakobJingleheimer

It seems like github ci failed. Should I try running it again with rebase?

@JakobJingleheimer

ghost commented Feb 26, 2026

Copy link
Copy Markdown
Member

CI didn't actually fail though. Earlier this morning I asked one of the CI maintainers; I'm waiting to hear back.

@JakobJingleheimer JakobJingleheimer added commit-queue PRs queued for automated landing through the Commit Queue. and removed commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. labels Feb 26, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Feb 26, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 2e1265a into nodejs:main Feb 26, 2026
@nodejs-github-bot

ghost commented Feb 26, 2026

Copy link
Copy Markdown
Collaborator

Landed in 2e1265a

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

Labels

commit-queue-squash PRs the Commit Queue should land as one squashed commit. needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_runner: expectFailure should support a reason (like todo/skip) and a specific expected failure

7 participants