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)
- Lint for versioned directories? HOT 1
- Template code contains duplication
- CSS animation test flakiness specific to Chrome for Testing (Dev & Canary) HOT 1
- ./wpt serve fails with Python 3.12 (default on fedora39) HOT 2
- Trusted types tests timeout in failure case HOT 1
- `./wpt run firefox` runs Firefox release instead of Nightly HOT 3
- Running wdspec directly via pytest is unable to collect all tests HOT 3
- XColumns class in anchor test?
- Passing a basename (alone) to manifest.load_and_update causes a FileNotFoundError
- paint-context-001.svg has incorrect expectation
- Chrome and Firefox are not installed with `--install-browser` flag for integration tests
- Race condition in css-contain/container-queries/font-relative-units-dynamic.html for `cap` & `rcap`?
- Trouble following "Chrome for Android" documentation
- Phuoc Nguyen
- update-expectations using fallback HOT 4
- html-aam/roles-contextual.html includes scenario that is recommended against by html-aria spec HOT 1
- `ImageData(buffer, w, opt h), Uint8ClampedArray argument type check` test fails for all browsers HOT 1
- Tests that compete for globally shared resources are flaky when run in parallel HOT 2
- Wrong expectations for percentage interpolation in text-decoration-thickness-interpolation.html
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.