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

WPT fetch api tests #3662

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

WPT fetch api tests #3662

wants to merge 3 commits into from

Conversation

npaun
Copy link
Member

@npaun npaun commented Mar 6, 2025

This is a giant one (and it's still a draft), so I'd suggest reviewing commit-by-commit.

Improvements to Bazel config for WPT tests:

  • By fiddling with the arguments passed, we can calculate relative paths in a less brittle manner.
  • Add the WPT CA certificate and enable network connections for WPT tests.

Improvements to the test harness:

  • Better relative path logic here too. Trying to make a flat namespace like workerd bindings act like a file system willo always be clunky, but now stuff like '../resources/xhr.js` can be interpreted correctly.
  • Added several new harness functions: assert_greater_than, assert_regexp_match, promise_rejects_js, promise_rejects_exactly, add_cleanup/add_completion_callback.
  • Made tests involving fetching from an external server work properly. We also support relative URLs and give WPT tests a fake sense of location (http://localhost:8000/path/to/test.js, etc.)
  • @anonrig suggested a much nicer way to keep test files from polluting the global scope - just put the source code inside braces to create a scope, then eval.

Added a config file for the fetch/api tests.

We fail most of them. Here's a really quick summary of why:

  • Many of them fail for pretty trivial reasons. e.g. We should set Response.type to basic in a lot of cases, we forget to put a space in multipart/form-data;boundary=whatevs, we force ReadableStreams to explicitly set type: undefined instead of allowing a missing property, and such.
  • Lots of tests are not relevant because they bring in CORS, forbidden headers, etc.
  • A few tests seem to trigger some kind of broken state in libkj 😱. We get spurious Invalid response status line (invalid protocol). messages, and they don't seem to actually be associated with the request that caused them. I'm still looking into this. Curious if ASan sees anything...
  • Please comment on a particular test case if you need more info on why it's failing, or have ideas about what we should prioritize fixing.

Next step

  • I'm testing this by manually standing up a WPT server then calling bazel test. I'll need to use @anonrig's sidecar option to launch the wpt server before the tests are run.
  • Improving sidecar (I'll create an issue for this.)

@npaun npaun requested review from jasnell and anonrig March 6, 2025 23:43
@@ -260,7 +269,10 @@ class Test {
}

public cleanup(): void {
// Actual cleanup support is not yet needed for the WPT modules we support
// TODO(soon): Cleanup functions can also return a promise instead of being synchronous, but we don't need this for any tests currently.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an example which test depends on this?

@npaun npaun force-pushed the npaun/wpt-fetch branch from 3053885 to 64af4f1 Compare March 7, 2025 22:52
@npaun
Copy link
Member Author

npaun commented Mar 7, 2025

...

@npaun npaun force-pushed the npaun/wpt-fetch branch from 64af4f1 to f198390 Compare March 7, 2025 23:24
@npaun npaun force-pushed the npaun/wpt-fetch branch from f198390 to 12b9bf1 Compare March 10, 2025 20:21
@npaun npaun force-pushed the npaun/wpt-fetch branch from 12b9bf1 to 8fbc0aa Compare March 12, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants