-
Notifications
You must be signed in to change notification settings - Fork 277
feat(compiler): Add fixedOrder option to expectDiagnostics #7453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(compiler): Add fixedOrder option to expectDiagnostics #7453
Conversation
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use something else than changeset for this repo called chronus. Either follow the comment that should get added soon or use pnpm chronus add
❌ There is undocummented changes. Run The following packages have changes but are not documented.
Show changes |
expectation.code, | ||
`Diagnostic at index ${i} has non matching code.\n${message}`, | ||
|
||
if (fixedOrder) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach we decided here was to sort the diagnostics so they diff can still be used.
The reason I didn't want to add this at it was was exactly because it made the test experience worse when it didn't find the match and in general it was bad pattern to have multiple diagnostics tested at the same time. We decided that sorting the diagnositcs and expectation would still provide the benefits while not loosing the diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, I think unfortunately we'd prefer to go with a bit of a different approach for this.
Have you found yourself needing this feature?
Thanks for your feedback @timotheeguerin! I understand your preference for sorting the diagnostics instead of the I implemented this feature based on the issue description which suggested adding a Regarding the changeset, I tried to create one manually but wasn't familiar with Chronus. I'll try using Would you like me to:
Thanks for the guidance! |
You can keep modifying this PR, and yeah sorry about the issue description we have not been doing a good job of relecting our internal discussions on them For chronus you can also just use that comment which has a link to add it #7453 (comment) |
Resolves #5818
Description
Added a new
fixedOrder
option to theexpectDiagnostics
function that allows testing diagnostics regardless of the order they appear in. This makes tests more resilient to code changes that might alter diagnostic order without changing the actual diagnostic content.Problem
Tests that use
expectDiagnostics
would fail when diagnostic order changes, even though this should not be considered a breaking change. Library test authors had to create wrappers to pre-sort diagnostics collections.Solution
fixedOrder
option toexpectDiagnostics
(defaults totrue
for backward compatibility)fixedOrder: false
, diagnostics can match in any orderTesting
All existing tests pass, confirming that backward compatibility is maintained.
Changes