-
-
Notifications
You must be signed in to change notification settings - Fork 764
test(linter/plugins): refactor tokens tests #16804
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
test(linter/plugins): refactor tokens tests #16804
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
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.
setup()currently resets state despite comments implying it’s only needed to change the source text, leading to redundant resets and a confusing helper contract.- The
beforeEachcomment refers tosetSourceText, but the helper is namedsetup, creating inconsistency and reducing clarity.
Summary of changes
Summary
Refactors apps/oxlint/test/tokens.test.ts to centralize per-test initialization:
- Introduces a
setup(text: string)helper that callsresetSourceAndAst()and assignssourceText. - Updates the
beforeEachhook to callsetup(SOURCE_TEXT)instead of duplicating reset/assignment logic. - Replaces many direct
sourceText = ...assignments (and several redundantresetSourceAndAst()calls) withsetup(...)in individual test cases. - Keeps behavior the same while reducing repeated boilerplate across token-store tests.
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.
Pull request overview
This PR refactors the token plugin unit tests to improve consistency and maintainability by introducing a setup() function that encapsulates test state initialization. The refactor eliminates code duplication and removes redundant resetSourceAndAst() calls that were already being handled by the beforeEach hook.
Key Changes:
- Introduced a
setup()helper function that combinesresetSourceAndAst()andsourceTextassignment - Replaced all direct
sourceText = "..."assignments withsetup("...")calls throughout the test suite - Removed redundant
resetSourceAndAst()calls since thebeforeEachhook now handles reset viasetup()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c457c5c to
bfbf14d
Compare
8d2b90f to
005982b
Compare
Merge activity
|
Pure refactor of tests. In tokens unit tests, use a `setup` function to set source text for each test, rather than writing to local `sourceText` var. Remove a bunch of unnecessary `resetSourceAndAst()` calls. `beforeEach` hook does this already before each test.
005982b to
5619f9e
Compare
bfbf14d to
d734b86
Compare

Pure refactor of tests.
In tokens unit tests, use a
setupfunction to set source text for each test, rather than writing to localsourceTextvar.Remove a bunch of unnecessary
resetSourceAndAst()calls.beforeEachhook does this already before each test.