Comments (8)
I see, the proposed helper API sounds good to me.
from wpt.
API suggestions
With the idea of a single fixture, we can pass the expected events as a list (because the order will matter).
on_events = wait_for_events([expectation1, expectation2, ...])
Individual items could either be a dict:
on_events = wait_for_events([
{ "event": "browsingContext.contextCreated", "predicate": lambda e: is_event_valid(e) },
{ "event": "network.responseCompleted", "count": 5 },
{ "event": "browsingContext.load" },
])
Or a list (slightly more compact):
on_events = wait_for_events([
["browsingContext.contextCreated", 1, lambda e: is_event_valid(e)],
["network.responseCompleted", 5],
["browsingContext.load", 1], # we could omit the "count" if it's 1 and there is no lambda?
])
Either option sounds fine to me, slight preference for the first one.
Return value
About the return value, the snippets above assume each "expectation" returns its own array of events.
on_events = wait_for_events([
["browsingContext.contextCreated", 1, lambda e: is_event_valid(e)],
["network.responseCompleted", 5],
["browsingContext.load", 1],
])
# do something
[context_created_events, response_completed_events, load_events] = await on_events
Other examples
Some other examples if we want to use this for simpler scenarios.
Wait for N events:
on_events = wait_for_events([
["network.responseCompleted", 5],
])
# do something
[response_completed_events] = await on_events
Wait for 1 event
on_events = wait_for_events([
["network.responseCompleted", 1],
])
# do something
[[response_completed_event]] = await on_events
(although we will probably keep wait_for_event
around anyway)
Checking no event emitted
Currently we are also usually using an array of events when we want to check that no event is emitted. I would suggest to replace those with a simpler:
on_event = wait_for_event(CONTEXT_CREATED_EVENT)
# do something
wait = AsyncPoll(bidi_session, timeout=0.5)
with pytest.raises(TimeoutException):
await wait_for_future_safe(on_event)
I would not try to make that part of the new fixture, seems like it would be hard to follow.
from wpt.
With the idea of a single fixture, we can pass the expected events as a list (because the order will matter).
By the order will matter, you mean that listeners will be consumed in order or that 5 responseCompleted events should come before the single load event?
from wpt.
With the idea of a single fixture, we can pass the expected events as a list (because the order will matter).
By the order will matter, you mean that listeners will be consumed in order or that 5 responseCompleted events should come before the single load event?
The latter. I thought it would be useful to use this to enforce a strict sequence of events, and also I thought that's what the Node API did.
from wpt.
I think Node API only enforces that listeners are processed in order in which they are created. I think being more strict is for the better but I wonder how can one express if a certain set of events needs to arrive at any (relative) order with this proposal?
from wpt.
I think Node API only enforces that listeners are processed in order in which they are created.
Ah, looks like I misunderstood the other API.
I think being more strict is for the better but I wonder how can one express if a certain set of events needs to arrive at any (relative) order with this proposal?
One way would be to call the fixture several times, eg
on_responsecompleted_events = wait_for_events([["network.responseCompleted", 5]])
on_load_events = wait_for_events([["browsingContext.load", 2]])
Or we could make this "strict" behavior optional, and require to pass a flag when calling the fixture to enable it?
from wpt.
What is the behavior if I listen for the same event?:
on_responsecompleted_events = wait_for_events([["network.responseCompleted", 1]])
on_responsecompleted_events2 = wait_for_events([["network.responseCompleted", 2]])
and say only two event are actually arriving?
from wpt.
What is the behavior if I listen for the same event?:
on_responsecompleted_events = wait_for_events([["network.responseCompleted", 1]]) on_responsecompleted_events2 = wait_for_events([["network.responseCompleted", 2]])
and say only two event are actually arriving?
With what I had in mind: for 2 distinct calls both would be resolved if 2 events arrive.
from wpt.
Related Issues (20)
- [css-color] Tests assume old hsl()/hsla() clipping behavior or depend on unclear gamut mapping to sRGB HOT 9
- Add support for testing native find-in-page search results
- Are css/css-contain/contain-layout-baseline-005.html css/css-contain/contain-layout-button-001.html correct? HOT 8
- [css-color] css/css-color/parsing/color-computed-relative-color.html assumes conversion to hwb is lossless HOT 5
- The wpt Writing Tests documentation should be updated HOT 4
- infrastructure/testdriver/click_iframe_crossorigin.sub.html can fail in Firefox HOT 1
- REGRESSION(c3a572d): TypeError: can't compare offset-naive and offset-aware datetimes
- lint for tests with link rel=match and testharness.js
- Do not run tests for PRs still in draft mode HOT 1
- Fa
- Firefox Android runs missing since May 12
- tools/unittests (Python 3.12) are failing
- Lovely
- Azure Pipeline run queued and not restarted HOT 17
- iss
- tytg
- WebVTT rendering tests fail widely because of UA-specific cue backgrounds HOT 2
- Incorrect test added for text-transform HOT 8
- UAX 14 not strictly required by css-text HOT 2
- wpt.live lists files instead of tests HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wpt.