Skip to content
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

[anchor-position] Support testing of polyfill #47156

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jamesnw
Copy link
Contributor

@jamesnw jamesnw commented Jul 16, 2024

I'm contributing to the polyfill for anchor position, which we test against the WPT. When testing the polyfill, we need to add a bit of delay to ensure the polyfill is applied before testing.

In #38442, a checkLayoutForAnchorPos wrapper for checkLayout was added to support a way to add a delay only for the polyfill while not impacting other tests. We don't have a similar method for test, so we have some false negatives when testing the polyfill.

testForAnchorPos is intended to replace all instances of test and promise_test in the Anchor Position tests. It likely would work for async_test as well, but I'm not seeing any instances of that in the Anchor Position tests. Like checkLayoutForAnchorPos, this only adds a delay if a global CHECK_LAYOUT_DELAY is true AND we are testing with --injected-script. This should have no impact on non-polyfill tests.

I've applied this to css/css-anchor-position/pseudo-element-anchor.html, and if this strategy is acceptable, I will transition the other tests as well.

@wpt-pr-bot
Copy link
Collaborator

There are no reviewers for this pull request. Please reach out on the chat room to get help with this. Thank you!

@jamesnw
Copy link
Contributor Author

jamesnw commented Jul 16, 2024

@mfreed7 or @bfgeek - it looks like were involved in the initial addition of checkLayoutForAnchorPos- would you be able to take a look and let me know if this is a suitable strategy? If so, I'll port the other tests over. Thanks!

@nt1m
Copy link
Member

nt1m commented Jul 19, 2024

Seems odd to do any kind of WPT change for this. This should probably done at the level of your test runner (perhaps finding a way to run the polyfill really early (WebKit has bootstrap scripts that run before everything else in the Web Inspector for instance).

@mfreed7
Copy link
Contributor

mfreed7 commented Jul 24, 2024

Seems odd to do any kind of WPT change for this. This should probably done at the level of your test runner (perhaps finding a way to run the polyfill really early (WebKit has bootstrap scripts that run before everything else in the Web Inspector for instance).

Adding this (checkLayoutForAnchorPos) did always feel like a brittle hack, and could only be done point-by-point. So if it's possible to modify the test harness to inject scripts early(er) and perhaps even have the test runner wait for the resolution of a promise (e.g. polyfillScriptsLoaded or similar) that'd be much better. If that's not an option at all, it'd be good to understand it. But if there's some good reason, I'm not against adding a few more such cases to WPT, since they're localized and don't really hinder the readability of usability of the tests.

@jamesnw
Copy link
Contributor Author

jamesnw commented Aug 7, 2024

Yeah, I agree that changing the tests for the nuances of a single implementation is not ideal.

The key complication is that currently the polyfill only affects elements in the DOM when the polyfill is loaded, which we are tracking here- oddbird/css-anchor-positioning#91. The WPT scripts mix the arrange and assertion steps, so there isn't a way to cleanly insert the polyfill between those steps, and running earlier before all WPT scripts wouldn't work. I don't think it's worth rewriting the runner before the polyfill supports dynamic elements, as that will change/lessen the requirements there.

At that point, there will be a difference between "the polyfill is loaded" and "the polyfill has been applied". The polyfill will still likely take several animation frames to get elements positioned when the polyfill has been applied, so the change in this PR will still be useful.

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

Successfully merging this pull request may close these issues.

4 participants