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

feat(js-runtime,wpt): improve conformance #835

Merged
merged 24 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/mean-cherries-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@lagon/cli': patch
'@lagon/serverless': patch
'@lagon/js-runtime': patch
---

Improve implementation of Headers, Request, Response and URLSearchParams
5 changes: 5 additions & 0 deletions .changeset/spicy-insects-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lagon/wpt-runner': patch
---

Add not completed tests to results
863 changes: 260 additions & 603 deletions crates/wpt-runner/current-results.md

Large diffs are not rendered by default.

47 changes: 34 additions & 13 deletions crates/wpt-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ const ENCODING_TABLE: &str = r#"const encodings_table =
}
]"#;
const REQUEST_CACHE: &str = include_str!("../../../tools/wpt/fetch/api/request/request-cache.js");
const REQUEST_ERROR: &str = include_str!("../../../tools/wpt/fetch/api/request/request-error.js");
const REQUEST_UTILS: &str = include_str!("../../../tools/wpt/fetch/api/resources/utils.js");
const SUBSET_TESTS: &str = include_str!("../../../tools/wpt/common/subset-tests.js");
const DECODING_HELPERS: &str =
include_str!("../../../tools/wpt/encoding/resources/decoding-helpers.js");
const SUPPORT_BLOB: &str = include_str!("../../../tools/wpt/FileAPI/support/Blob.js");
const SUPPORT_FORMDATA: &str =
include_str!("../../../tools/wpt/FileAPI/support/send-file-formdata-helper.js");
const STREAM_DISTURBED_UTIL: &str =
include_str!("../../../tools/wpt/fetch/api/response/response-stream-disturbed-util.js");

static RESULT: Lazy<Mutex<(usize, usize, usize)>> = Lazy::new(|| Mutex::new((0, 0, 0)));
static TEST_HARNESS: Lazy<String> = Lazy::new(|| {
Expand All @@ -48,28 +52,35 @@ static TEST_HARNESS: Lazy<String> = Lazy::new(|| {
.replace("debug: false", "debug: true")
});

const SKIP_TESTS: [&str; 16] = [
// request
"request-error.any.js", // "badRequestArgTests is not defined"
"request-init-stream.any.js", // "request.body.getReader is not a function"
"request-consume-empty.any.js", // "Unexpected end of JSON input"
"request-consume.any.js", // "Unexpected end of JSON input"
"request-init-priority.any.js", // "idx is not defined"
const SKIP_TESTS: [&str; 22] = [
// response
"response-cancel-stream.any.js", // "undefined"
"response-error-from-stream.any.js", // "Start error"
"response-stream-with-broken-then.any.js", // "Cannot destructure property 'done' of 'undefined' as it is undefine"
"response-stream-disturbed-4.any.js",
// request
"request-cache-default-conditional.any.js", // fetch a python server
"request-cache-default.any.js", // fetch a python server
"request-cache-force-cache.any.js", // fetch a python server
"request-cache-no-cache.any.js", // fetch a python server
"request-cache-no-store.any.js", // fetch a python server
"request-cache-only-if-cached.any.js", // fetch a python server
"request-cache-reload.any.js", // fetch a python server
// url
"idlharness.any.js", // load webidl stuff, not supported
"url-setters.any.js", // fetch an json file, find a way to run it
"idlharness.any.js", // load webidl stuff, not supported
"url-setters.any.js", // fetch an json file, find a way to run it
"url-setters-stripping.any.js", // stripping every field is not supported
// encoding
"textdecoder-utf16-surrogates.any.js", // we only support utf-8
"textencoder-utf16-surrogates.any.js", // we only support utf-8
"iso-2022-jp-decoder.any.js", // we only support utf-8
"encodeInto.any.js", // TextEncoder#encodeInto isn't implemented yet
"textdecoder-fatal-single-byte.any.js", // have a random number of tests?
"textdecoder-fatal-single-byte.any.js", // lots of test that we don't really need
"unsupported-encodings.any.js", // we only support utf-8
// event
"EventTarget-removeEventListener.any.js", // removeEventListener does not exists on the global object
// headers
"header-values-normalize.any.js", // XMLHttpRequest isn't supported
];

async fn run_test(path: &Path) {
Expand All @@ -95,15 +106,19 @@ async fn run_test(path: &Path) {
isWindow: () => false,
}}
globalThis.location = {{}}
globalThis.idx = undefined;

export function handler() {{
{}
{ENCODING_TABLE}
{REQUEST_CACHE}
{REQUEST_ERROR}
{REQUEST_UTILS}
{SUBSET_TESTS}
{DECODING_HELPERS}
{SUPPORT_BLOB}
{SUPPORT_FORMDATA}
{STREAM_DISTURBED_UTIL}
{code}
return new Response()
}}",
Expand Down Expand Up @@ -135,6 +150,8 @@ export function handler() {{
println!("{}", style(content).red());
} else if content.starts_with("TEST START") {
RESULT.lock().unwrap().0 += 1;
} else {
// println!("{}", content);
}
}
});
Expand Down Expand Up @@ -209,16 +226,20 @@ async fn main() {
let result = RESULT.lock().unwrap();
println!();
println!(
"{} tests, {} passed, {} failed",
"{} tests, {} passed, {} failed ({} not completed)",
result.0,
style(result.1.to_string()).green(),
style(result.2.to_string()).red()
style(result.2.to_string()).red(),
result.0 - (result.1 + result.2)
);

if result.2 == 0 {
println!(" -> 100% conformance");
} else {
println!(" -> {}% conformance", (result.1 * 100) / result.0);
println!(
" -> {}% conformance",
(result.1 * 100) / (result.1 + result.2)
);
}

runtime.dispose();
Expand Down
2 changes: 1 addition & 1 deletion packages/js-runtime/src/runtime/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

const contentTypeHeader = headers.get('content-type');

if (contentTypeHeader === APPLICATION_X_WWW_FORM_URLENCODED) {
if (contentTypeHeader?.startsWith(APPLICATION_X_WWW_FORM_URLENCODED)) {
const params = new URLSearchParams(body);

for (const [key, value] of params) {
Expand Down
2 changes: 1 addition & 1 deletion packages/js-runtime/src/runtime/global/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
}

readAsBinaryString(blob: Blob) {
this.read(blob.arrayBuffer());
this.read(blob.text());
}

readAsDataURL(blob: Blob) {
Expand Down
7 changes: 5 additions & 2 deletions packages/js-runtime/src/runtime/http/Headers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(globalThis => {
const SET_COOKIE = 'set-cookie';
// eslint-disable-next-line no-control-regex
const NORMALIZE_VALUE_REGEX = new RegExp('^[\x0A\x0D\x09\x20]+|[\x0A\x0D\x09\x20]+$', 'g');

globalThis.Headers = class {
private readonly h: Map<string, string[]> = new Map();
Expand Down Expand Up @@ -41,7 +43,8 @@

private addValue(name: string, value: string) {
name = name.toLowerCase();
value = String(value);
value = String(value).replace(NORMALIZE_VALUE_REGEX, '');

const values = this.h.get(name);

if (values) {
Expand Down Expand Up @@ -107,7 +110,7 @@
}

name = name.toLowerCase();
value = String(value);
value = String(value).replace(NORMALIZE_VALUE_REGEX, '');
this.h.set(name, [value]);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/js-runtime/src/runtime/http/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import { RequestResponseBody } from './body';
}

if (init?.status) {
if (init.status < 200 || init.status > 599) {
throw new RangeError('Invalid status code');
}

this.ok = init.status >= 200 && init.status < 300;
} else {
this.ok = true;
Expand Down
Loading