-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Tooltip: improve tests #57345
Tooltip: improve tests #57345
Conversation
@@ -209,7 +209,7 @@ function UnforwardedModal( | |||
|
|||
if ( | |||
shouldCloseOnEsc && | |||
event.code === 'Escape' && | |||
( event.code === 'Escape' || event.key === 'Escape' ) && |
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.
@ariakit/test
keyboard events use event.key
, so I had to add this check in order for the Modal
component to react to those simulated user events
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 can implement code
in @ariakit/test
. I'm just not sure how to transform keys into code, and I'd prefer to sidestep the need to maintain a full map of values.
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.
I guess we can keep this change to the Modal
component for now (cc @mirka )
|
||
render( | ||
<> | ||
it( 'should not show tooltip if the mouse leaves the tooltip anchor before set delay', async () => { |
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.
@diegohaz This test keeps failing when the whole suite runs, but passes when run in isolation.
It looks like there is still some "leak" across tests even after using @ariakit/test
, but I can't understand what it is — do you have any ideas?
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.
Tooltips appear instantly if another tooltip has just been hidden. This is controlled by a global state, which is probably shared among multiple tests within the same file. These tests don't exactly run in total isolation.
If this is the issue, you might need to introduce a delay at the start to ensure tooltips from other tests aren't interfering with this one.
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.
Tooltips appear instantly if another tooltip has just been hidden. This is controlled by a global state, which is probably shared among multiple tests within the same file. These tests don't exactly run in total isolation.
That seems to be the issue, since the test passes if I set the skipTimeout: 0
(although I'd prefer to leave the skipTimeout
delay around if possible).
If this is the issue, you might need to introduce a delay at the start to ensure tooltips from other tests aren't interfering with this one.
I tried adding a delay specifically for that test, but I keep getting failures. The only way to reliably have all tests pass seems to be to add
afterEach( async () => {
await sleep( 300 );
} );
although I'd prefer to avoid slowing down the whole suite if possible. Do you have any suggestions?
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.
Another option is to run those tests fully in parallel. I know Vitest offers this feature, but I'm not sure about Jest.
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.
For now, I'll have to resort to waiting those extra 300ms
at the end of each test to make sure that the "skip timeout" behaviour is not triggered.
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.
FYI, this await sleep(300)
might not be required anymore with @ariakit/[email protected]
.
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.
PR to remove it: #60897
Flaky tests detected in ac4d28f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7301468581
|
ac4d28f
to
613bd0d
Compare
1036668
to
21d2c0e
Compare
@@ -66,7 +66,7 @@ function Tooltip( props: TooltipProps ) { | |||
|
|||
const tooltipStore = Ariakit.useTooltipStore( { | |||
placement: computedPlacement, | |||
timeout: delay, | |||
showTimeout: delay, |
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.
Looking at the delay
prop, it looks like it was always intended to only be applied to the "show" timeout, and not affect the "hide" timeout.
@diegohaz @WordPress/gutenberg-components this PR is ready for another round of review |
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.
Nice improvements! And thanks for the cleanly separated commits, it was easy to go through 👍
Related to #57206 and #57204
What?
Improve Tooltip tests:
Why?
The conversation in #57206 brought up some added nuance to
Tooltip
's behavior that we should add to our unit testsHow?
@ariakit/test
Testing Instructions
Note: I recommend reviewing code changes commit by commit