test_runner: support custom message for expectFailure#61563
test_runner: support custom message for expectFailure#61563Han5991 wants to merge 2 commits intonodejs:mainfrom
Conversation
|
Review requested:
|
@JakobJingleheimer 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?" |
|
@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 Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #61563 +/- ##
==========================================
+ Coverage 88.84% 89.71% +0.87%
==========================================
Files 674 672 -2
Lines 204957 204601 -356
Branches 39309 39290 -19
==========================================
+ Hits 182087 183556 +1469
+ Misses 15088 13364 -1724
+ Partials 7782 7681 -101
🚀 New features to boost your workflow:
|
|
@JakobJingleheimer nope, haven't started this, though I had long ago implemented it in I think it's important to get the requirements nailed. IMHO, #61570. |
|
As I said, let's put together a proposal in the nodejs/test_runner repo 🙂 |
This comment was marked as resolved.
This comment was marked as resolved.
|
reviewed before reading the discussion; imo a string should work as in this PR whether or not it also supports accepting a regex. |
|
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 🙂
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 |
|
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. |
1af3584 to
13aedaa
Compare
|
I've opened a proposal PR in the test-runner repository as suggested by @JakobJingleheimer. |
061f049 to
346ec8f
Compare
vassudanagunta
left a comment
There was a problem hiding this comment.
I think this needs to be documented a little better for the user.
|
@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. |
vassudanagunta
left a comment
There was a problem hiding this comment.
Looks like suite-level support for expectFailure was missed the first time around. Should fix this now... I think it will be easy.
891ad18 to
01cf2c4
Compare
01cf2c4 to
b453aca
Compare
b453aca to
80928f7
Compare
|
The PR is ready. Please review it! |
|
We still have the question about whether |
JakobJingleheimer
left a comment
There was a problem hiding this comment.
Awesome—thanks for this 🙌
Just the primordial is a "change needed"; you can take or leave the nits.
| const message = typeof this.expectFailure === 'object' ? | ||
| this.expectFailure.label : | ||
| this.expectFailure; |
There was a problem hiding this comment.
nit:
| const message = typeof this.expectFailure === 'object' ? | |
| this.expectFailure.label : | |
| this.expectFailure; | |
| const message = this.expectFailure?.label || this.expectFailure; |
There was a problem hiding this comment.
If we use || this.expectFailure, the message variable incorrectly becomes an object (e.g., { label: undefined, ... }) instead of a string or undefined. This happens because this.expectFailure is internally normalized to an object even for boolean inputs. The test runner expects a string message, and passing an object causes serialization errors.
There was a problem hiding this comment.
Ohhh 👍 That's weird 🤔
There was a problem hiding this comment.
These sorts of implementation subtleties are prone to unintended behavioral changes as the code evolves. I suggest having more corner case coverage to lock down ambiguities and facilitate further review, e.g. #61563 (review)
There was a problem hiding this comment.
Oh, actually, that's a good point. I think we can avoid any logic here by making this.expectFailure adhere to
either
type ExpectFailure = false | {
label: string, // empty string when user did not provide
matcher: Matcher | nullish,
}or
type ExpectFailure = false | {
label?: string,
match?: Matcher,
}Regardless of how the user provided label and/or match, always set them internally to this.expectFailure.label and this.expectFailure.match.
Ex
test.expectFailure('whatever', () => {…});this.expectFailure = {};test('whatever', { expectFailure: '#42' }, () => {…});this.expectFailure = { label: '#42' };test('whatever', { expectFailure: { label: '#42' } }, () => {…});this.expectFailure = { label: '#42' };80928f7 to
5465c1c
Compare
Thank you for your review. We have updated the update to reflect your requests. |
There was a problem hiding this comment.
How should semantic ambiguities in corner case expectFailure: <object> values be interpreted? Both for behavioral stability1 and to facilitate discussion of desired behavior, I suggest more tests cases such as this one.
Footnotes
-
Behavior is prone to instability as interpretation is distributed in many places, e.g. in
parseExpectFailure(expectFailure)and in https://github.com/Han5991/node/blob/5465c1cf3eb2984aaf9918a65c89bc9125ac74a1/lib/internal/test_runner/test.js#L1437-L1442, and also because the logic can be subtle: https://github.com/nodejs/node/pull/61563#discussion_r2815755827 ↩
I agree with your opinion. |
This change exposes the expectFailure message in the test runner and adds edge cases for expectFailure ambiguity. PR-URL: nodejs#61563 Reviewed-By: vassudanagunta Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
5465c1c to
5e8df72
Compare
This change exposes the expectFailure message in the test runner and adds edge cases for expectFailure ambiguity. PR-URL: nodejs#61563 Reviewed-By: vassudanagunta Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
b8943cd to
8ffb898
Compare
|
@Han5991 please stop force-pushing unless it's absolutely necessary; it totally screws up GitHub's review interface, making it impossible to see a diff of incremental changes (so the entire thing has to get reviewed again, including unchanged lines). The branch will get collapsed into a single commit automatically on merge, so no need to worry that :) |
Thanks for the advice. I'll try not to force pushes. |
JakobJingleheimer
left a comment
There was a problem hiding this comment.
Nice new test cases—thanks! 🙂
LMK if you want to address the nit or leave it. If leave, I'll land this now and address in a little follow-up.
This change exposes the expectFailure message in the test runner and adds edge cases for expectFailure ambiguity.
This change updates the test 'test-runner-xfail.js' so that the validation of empty object exceptions correctly uses assert.throws() with the required two arguments and checks for the 'ok' test status in the output instead of checking for a console log of the caught exception.
22c2d22 to
4c7bb37
Compare
|
@Han5991 thanks for jumping on the nit! 🙌 I just realised https://github.com/nodejs/node/pull/61563/changes#r2849591705 got closed before the discussion was settled. Sorry this is a bit of a never ending story 😖 If you're tired of all the back and forth and if my suggestion adequately addresses the raised concern, I think that can be handled in a follow-up (I'm happy to handle if you don't want to) since it's implementation details that don't affect the public API. But let's give @vassudanagunta a bit of time to read and respond (and hopefully confirm) before jumping on an update if that is handled within this PR. |
|
I totally agree with your suggestion. Since it doesn't affect the public API, please feel free to merge this PR now. I’m happy to let you handle the implementation details in a follow-up as you offered. Thanks for taking it from here! |
Summary
This PR enhances the
expectFailureoption 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
expectFailureoption now supports the following types:String: Treated as a failure label (reason).
RegExp / Function / Error Class: Treated as a matcher to validate the thrown error (similar to
assert.throws).Object:
labelormatchproperties, it's treated as a configuration object.Inheritance:
expectFailurefrom their parent suite. This allows marking an entire suite as expected to fail.References
expectFailurelabel and/or matcher test-runner#10Resolves: #61570