From 5292135d4f1042861c56708c2ec604c4d961d459 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Thu, 7 Jan 2021 21:44:40 +0100 Subject: [PATCH 01/15] tests: enable wpt for url --- cli/tests/integration_tests.rs | 68 +++- cli/tests/wpt.jsonc | 407 ++++++++++++++++++++ cli/tests/wpt_testharnessconsolereporter.js | 4 +- test_util/wpt | 2 +- 4 files changed, 475 insertions(+), 6 deletions(-) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index aabeb1f77b4dfd..38a4b94abdfe87 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -5,6 +5,7 @@ use deno_core::serde_json; use deno_core::url; use deno_runtime::deno_fetch::reqwest; use deno_runtime::deno_websocket::tokio_tungstenite; +use std::io::BufReader; use std::io::{BufRead, Write}; use std::path::Path; use std::path::PathBuf; @@ -5113,6 +5114,22 @@ fn jsonc_to_serde(j: jsonc_parser::JsonValue) -> serde_json::Value { } } +struct WPTServer(std::process::Child); + +impl Drop for WPTServer { + fn drop(&mut self) { + // TODO(lucacasonato): This should be a more graceful kill where child procs of the proc are also killed. + match self.0.try_wait() { + Ok(None) => { + self.0.kill().expect("failed to kill 'wpt serve'"); + let _ = self.0.wait(); + } + Ok(Some(status)) => panic!("'wpt serve' exited unexpectedly {}", status), + Err(e) => panic!("'wpt serve' error: {}", e), + } + } +} + #[test] fn web_platform_tests() { use deno_core::serde::Deserialize; @@ -5134,6 +5151,43 @@ fn web_platform_tests() { let config: std::collections::HashMap> = deno_core::serde_json::from_value(jsonc_to_serde(jsonc)).unwrap(); + let mut proc = Command::new("python3") + .current_dir(util::wpt_path()) + .arg("wpt") + .arg("serve") + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap(); + + let stderr = proc.stderr.as_mut().unwrap(); + let mut stderr = BufReader::new(stderr).lines(); + let mut ready_8000 = false; + let mut ready_8443 = false; + let mut ready_8444 = false; + let mut ready_9000 = false; + while let Ok(line) = stderr.next().unwrap() { + if !line.starts_with("DEBUG:") { + eprintln!("{}", line); + } + if line.contains("web-platform.test:8000") { + ready_8000 = true; + } + if line.contains("web-platform.test:8443") { + ready_8443 = true; + } + if line.contains("web-platform.test:8444") { + ready_8444 = true; + } + if line.contains("web-platform.test:9000") { + ready_9000 = true; + } + if ready_8000 && ready_8443 && ready_8444 && ready_9000 { + break; + } + } + + let _wpt_server = WPTServer(proc); + for (suite_name, includes) in config.into_iter() { let suite_path = util::wpt_path().join(suite_name); let dir = WalkDir::new(&suite_path) @@ -5198,14 +5252,15 @@ fn web_platform_tests() { }) .collect(); - let mut variants: Vec<&str> = test_file_text + let mut variants: Vec = test_file_text .split('\n') .into_iter() .filter_map(|t| t.strip_prefix("// META: variant=")) + .map(|t| format!("?{}", t)) .collect(); if variants.is_empty() { - variants.push(""); + variants.push("".to_string()); } for variant in variants { @@ -5228,11 +5283,18 @@ fn web_platform_tests() { let bundle = concat_bundle(files, file.path(), "".to_string()); file.write_all(bundle.as_bytes()).unwrap(); + let self_path = test_file_path.strip_prefix(util::wpt_path()).unwrap(); + let child = util::deno_cmd() .current_dir(test_file_path.parent().unwrap()) .arg("run") .arg("--location") - .arg(&format!("http://web-platform-tests/?{}", variant)) + .arg(&format!( + "http://web-platform.test:8000/{}{}", + self_path.to_str().unwrap(), variant + )) + .arg("--cert") + .arg(util::wpt_path().join("tools/certs/cacert.pem")) .arg("-A") .arg(file.path()) .arg(deno_core::serde_json::to_string(&expect_fail).unwrap()) diff --git a/cli/tests/wpt.jsonc b/cli/tests/wpt.jsonc index 3099d3b48e00dc..2e6d758765a3eb 100644 --- a/cli/tests/wpt.jsonc +++ b/cli/tests/wpt.jsonc @@ -179,5 +179,412 @@ ] }, "user_timing_exists" + ], + "url": [ + "historical", + { + "name": "url-constructor", + "expectFail": [ + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <:#> against ", + "Parsing: <#> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: < File:c|////foo\\bar.html> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <\u0000\u001b\u0004\u0012 http://example.com/\u001f \r > against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <#> against ", + "Parsing: <#> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <../i> against ", + "Parsing: <../i> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <\\/localhost//pig> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <\\\\\\.\\Y:> against ", + "Parsing: <\\\\\\.\\y:> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <#x> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <..//path> against ", + "Parsing: against ", + "Parsing: <> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against " + ] + }, + { + "name": "url-origin", + "expectFail": [ + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: <\u0000\u001b\u0004\u0012 http://example.com/\u001f \r > against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: <../i> against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: <#i> against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: <#x> against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against " + ] + }, + { + "name": "url-searchparams", + "expectFail": [ + "URL.searchParams updating, clearing", + "URL.searchParams and URL.search setters, update propagation" + ] + }, + { + "name": "url-setters-stripping", + "expectFail": [ + "Setting protocol with leading U+0000 (https:)", + "Setting protocol with U+0000 before inserted colon (https:)", + "Setting host with leading U+0000 (https:)", + "Setting host with middle U+0000 (https:)", + "Setting host with trailing U+0000 (https:)", + "Setting port with middle U+0000 (https:)", + "Setting port with trailing U+0000 (https:)", + "Setting protocol with leading U+0009 (https:)", + "Setting protocol with U+0009 before inserted colon (https:)", + "Setting host with leading U+0009 (https:)", + "Setting hostname with leading U+0009 (https:)", + "Setting host with middle U+0009 (https:)", + "Setting hostname with middle U+0009 (https:)", + "Setting host with trailing U+0009 (https:)", + "Setting hostname with trailing U+0009 (https:)", + "Setting port with leading U+0009 (https:)", + "Setting port with middle U+0009 (https:)", + "Setting port with trailing U+0009 (https:)", + "Setting pathname with leading U+0009 (https:)", + "Setting pathname with middle U+0009 (https:)", + "Setting pathname with trailing U+0009 (https:)", + "Setting search with leading U+0009 (https:)", + "Setting search with middle U+0009 (https:)", + "Setting search with trailing U+0009 (https:)", + "Setting hash with leading U+0009 (https:)", + "Setting hash with middle U+0009 (https:)", + "Setting hash with trailing U+0009 (https:)", + "Setting protocol with leading U+000A (https:)", + "Setting protocol with U+000A before inserted colon (https:)", + "Setting host with leading U+000A (https:)", + "Setting hostname with leading U+000A (https:)", + "Setting host with middle U+000A (https:)", + "Setting hostname with middle U+000A (https:)", + "Setting host with trailing U+000A (https:)", + "Setting hostname with trailing U+000A (https:)", + "Setting port with leading U+000A (https:)", + "Setting port with middle U+000A (https:)", + "Setting port with trailing U+000A (https:)", + "Setting pathname with leading U+000A (https:)", + "Setting pathname with middle U+000A (https:)", + "Setting pathname with trailing U+000A (https:)", + "Setting search with leading U+000A (https:)", + "Setting search with middle U+000A (https:)", + "Setting search with trailing U+000A (https:)", + "Setting hash with leading U+000A (https:)", + "Setting hash with middle U+000A (https:)", + "Setting hash with trailing U+000A (https:)", + "Setting protocol with leading U+000D (https:)", + "Setting protocol with U+000D before inserted colon (https:)", + "Setting host with leading U+000D (https:)", + "Setting hostname with leading U+000D (https:)", + "Setting host with middle U+000D (https:)", + "Setting hostname with middle U+000D (https:)", + "Setting host with trailing U+000D (https:)", + "Setting hostname with trailing U+000D (https:)", + "Setting port with leading U+000D (https:)", + "Setting port with middle U+000D (https:)", + "Setting port with trailing U+000D (https:)", + "Setting pathname with leading U+000D (https:)", + "Setting pathname with middle U+000D (https:)", + "Setting pathname with trailing U+000D (https:)", + "Setting search with leading U+000D (https:)", + "Setting search with middle U+000D (https:)", + "Setting search with trailing U+000D (https:)", + "Setting hash with leading U+000D (https:)", + "Setting hash with middle U+000D (https:)", + "Setting hash with trailing U+000D (https:)", + "Setting protocol with leading U+001F (https:)", + "Setting protocol with U+001F before inserted colon (https:)", + "Setting host with leading U+001F (https:)", + "Setting host with middle U+001F (https:)", + "Setting host with trailing U+001F (https:)", + "Setting port with middle U+001F (https:)", + "Setting port with trailing U+001F (https:)", + "Setting protocol with leading U+0000 (wpt++:)", + "Setting protocol with U+0000 before inserted colon (wpt++:)", + "Setting host with leading U+0000 (wpt++:)", + "Setting host with middle U+0000 (wpt++:)", + "Setting host with trailing U+0000 (wpt++:)", + "Setting port with middle U+0000 (wpt++:)", + "Setting port with trailing U+0000 (wpt++:)", + "Setting pathname with leading U+0000 (wpt++:)", + "Setting pathname with middle U+0000 (wpt++:)", + "Setting pathname with trailing U+0000 (wpt++:)", + "Setting protocol with leading U+0009 (wpt++:)", + "Setting protocol with U+0009 before inserted colon (wpt++:)", + "Setting host with leading U+0009 (wpt++:)", + "Setting hostname with leading U+0009 (wpt++:)", + "Setting host with middle U+0009 (wpt++:)", + "Setting hostname with middle U+0009 (wpt++:)", + "Setting host with trailing U+0009 (wpt++:)", + "Setting hostname with trailing U+0009 (wpt++:)", + "Setting port with leading U+0009 (wpt++:)", + "Setting port with middle U+0009 (wpt++:)", + "Setting port with trailing U+0009 (wpt++:)", + "Setting pathname with leading U+0009 (wpt++:)", + "Setting pathname with middle U+0009 (wpt++:)", + "Setting pathname with trailing U+0009 (wpt++:)", + "Setting search with leading U+0009 (wpt++:)", + "Setting search with middle U+0009 (wpt++:)", + "Setting search with trailing U+0009 (wpt++:)", + "Setting hash with leading U+0009 (wpt++:)", + "Setting hash with middle U+0009 (wpt++:)", + "Setting hash with trailing U+0009 (wpt++:)", + "Setting protocol with leading U+000A (wpt++:)", + "Setting protocol with U+000A before inserted colon (wpt++:)", + "Setting host with leading U+000A (wpt++:)", + "Setting hostname with leading U+000A (wpt++:)", + "Setting host with middle U+000A (wpt++:)", + "Setting hostname with middle U+000A (wpt++:)", + "Setting host with trailing U+000A (wpt++:)", + "Setting hostname with trailing U+000A (wpt++:)", + "Setting port with leading U+000A (wpt++:)", + "Setting port with middle U+000A (wpt++:)", + "Setting port with trailing U+000A (wpt++:)", + "Setting pathname with leading U+000A (wpt++:)", + "Setting pathname with middle U+000A (wpt++:)", + "Setting pathname with trailing U+000A (wpt++:)", + "Setting search with leading U+000A (wpt++:)", + "Setting search with middle U+000A (wpt++:)", + "Setting search with trailing U+000A (wpt++:)", + "Setting hash with leading U+000A (wpt++:)", + "Setting hash with middle U+000A (wpt++:)", + "Setting hash with trailing U+000A (wpt++:)", + "Setting protocol with leading U+000D (wpt++:)", + "Setting protocol with U+000D before inserted colon (wpt++:)", + "Setting host with leading U+000D (wpt++:)", + "Setting hostname with leading U+000D (wpt++:)", + "Setting host with middle U+000D (wpt++:)", + "Setting hostname with middle U+000D (wpt++:)", + "Setting host with trailing U+000D (wpt++:)", + "Setting hostname with trailing U+000D (wpt++:)", + "Setting port with leading U+000D (wpt++:)", + "Setting port with middle U+000D (wpt++:)", + "Setting port with trailing U+000D (wpt++:)", + "Setting pathname with leading U+000D (wpt++:)", + "Setting pathname with middle U+000D (wpt++:)", + "Setting pathname with trailing U+000D (wpt++:)", + "Setting search with leading U+000D (wpt++:)", + "Setting search with middle U+000D (wpt++:)", + "Setting search with trailing U+000D (wpt++:)", + "Setting hash with leading U+000D (wpt++:)", + "Setting hash with middle U+000D (wpt++:)", + "Setting hash with trailing U+000D (wpt++:)", + "Setting protocol with leading U+001F (wpt++:)", + "Setting protocol with U+001F before inserted colon (wpt++:)", + "Setting host with leading U+001F (wpt++:)", + "Setting host with middle U+001F (wpt++:)", + "Setting host with trailing U+001F (wpt++:)", + "Setting port with middle U+001F (wpt++:)", + "Setting port with trailing U+001F (wpt++:)", + "Setting pathname with leading U+001F (wpt++:)", + "Setting pathname with middle U+001F (wpt++:)", + "Setting pathname with trailing U+001F (wpt++:)" + ] + }, + "url-tojson", + { + "name": "urlencoded-parser", + "expectFail": [ + "URLSearchParams constructed with: %EF%BB%BFtest=%EF%BB%BF", + "request.formData() with input: test=", + "response.formData() with input: test=", + "request.formData() with input: %FE%FF", + "response.formData() with input: %FE%FF", + "request.formData() with input: %FF%FE", + "response.formData() with input: %FF%FE", + "request.formData() with input: %C2", + "response.formData() with input: %C2", + "request.formData() with input: %C2x", + "response.formData() with input: %C2x", + "request.formData() with input: _charset_=windows-1252&test=%C2x", + "response.formData() with input: _charset_=windows-1252&test=%C2x", + "request.formData() with input: %=a", + "response.formData() with input: %=a", + "request.formData() with input: %a=a", + "response.formData() with input: %a=a", + "request.formData() with input: %a_=a", + "response.formData() with input: %a_=a", + "request.formData() with input: id=0&value=%", + "response.formData() with input: id=0&value=%", + "request.formData() with input: b=%2sf%2a", + "response.formData() with input: b=%2sf%2a", + "request.formData() with input: b=%2%2af%2a", + "response.formData() with input: b=%2%2af%2a", + "request.formData() with input: b=%%2a", + "response.formData() with input: b=%%2a" + ] + }, + "urlsearchparams-append", + { + "name": "urlsearchparams-constructor", + "expectFail": [ + "URLSearchParams constructor, DOMException as argument", + "URLSearchParams constructor, empty string as argument", + "Construct with 2 unpaired surrogates (no trailing)", + "Construct with 3 unpaired surrogates (no leading)", + "Construct with object with NULL, non-ASCII, and surrogate keys" + ] + }, + "urlsearchparams-delete", + { + "name": "urlsearchparams-foreach", + "expectFail": [ + "For-of Check", + "delete next param during iteration", + "delete current param during iteration", + "delete every param seen during iteration" + ] + }, + "urlsearchparams-get", + "urlsearchparams-getall", + "urlsearchparams-has", + "urlsearchparams-set", + "urlsearchparams-sort", + "urlsearchparams-stringifier" ] } diff --git a/cli/tests/wpt_testharnessconsolereporter.js b/cli/tests/wpt_testharnessconsolereporter.js index 5c217f29e1071c..695747a7e6331e 100644 --- a/cli/tests/wpt_testharnessconsolereporter.js +++ b/cli/tests/wpt_testharnessconsolereporter.js @@ -108,13 +108,13 @@ window.add_completion_callback((tests, harnessStatus) => { console.log(`\nfailures:\n`); } for (const result of failed) { - console.log(` ${result.name}`); + console.log(` ${JSON.stringify(result.name)}`); } if (expectedFailedButPassedCount > 0) { console.log(`\nexpected failures that passed:\n`); } for (const result of expectedFailedButPassed) { - console.log(` ${result.name}`); + console.log(` ${JSON.stringify(result.name)}`); } console.log( `\ntest result: ${ diff --git a/test_util/wpt b/test_util/wpt index 835839463c5270..f69ecab2220e16 160000 --- a/test_util/wpt +++ b/test_util/wpt @@ -1 +1 @@ -Subproject commit 835839463c5270731a6a57885caff34cac7725e5 +Subproject commit f69ecab2220e1684e7058e3c9657064808316f93 From fdc9e24c024e96be8c7ae94900c99cedc5c7d5cc Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Thu, 7 Jan 2021 23:41:01 +0100 Subject: [PATCH 02/15] graceful shutdown and docs --- cli/tests/integration_tests.rs | 14 +++++++--- docs/contributing/building_from_source.md | 32 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 38a4b94abdfe87..985bfaeae70a8b 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -5118,10 +5118,17 @@ struct WPTServer(std::process::Child); impl Drop for WPTServer { fn drop(&mut self) { - // TODO(lucacasonato): This should be a more graceful kill where child procs of the proc are also killed. match self.0.try_wait() { Ok(None) => { - self.0.kill().expect("failed to kill 'wpt serve'"); + if cfg!(target_os = "linux") { + println!("libc kill"); + unsafe { + libc::kill(self.0.id() as i32, libc::SIGTERM); + } + } else { + println!("std kill"); + self.0.kill().expect("killing 'wpt serve' failed"); + } let _ = self.0.wait(); } Ok(Some(status)) => panic!("'wpt serve' exited unexpectedly {}", status), @@ -5291,7 +5298,8 @@ fn web_platform_tests() { .arg("--location") .arg(&format!( "http://web-platform.test:8000/{}{}", - self_path.to_str().unwrap(), variant + self_path.to_str().unwrap(), + variant )) .arg("--cert") .arg(util::wpt_path().join("tools/certs/cacert.pem")) diff --git a/docs/contributing/building_from_source.md b/docs/contributing/building_from_source.md index 227b424188650e..325e149fa54bf8 100644 --- a/docs/contributing/building_from_source.md +++ b/docs/contributing/building_from_source.md @@ -109,3 +109,35 @@ cargo clean && cargo build -vv # Run: ./target/debug/deno run cli/tests/002_hello.ts ``` + +### Testing + +> :warning: **IMPORTANT**: Our test suite relies on certain entries to be configured in your /etc/hosts file. +> If these entries are not present in your /etc/hosts file, the `web_platform_tests` test **will** fail. To +> configure these entries, run the following command: +> +> ```shell +> # macOS / Linux +> cd test_utils/wpt/ +> ./wpt make-hosts-file | sudo tee -a /etc/hosts +> ``` +> +> ```powershell +> # Windows (use powershell!) +> cd test_utils/wpt/ +> python wpt make-hosts-file | Out-File $env:SystemRoot\System32\drivers\etc\hosts -Encoding ascii -Append +> ``` +> +> If you use WSL, be aware that WSL may attempt to override /etc/hosts each time it is launched, which would +> then require you to re-run hosts this setup. This behavior [can be configured](https://docs.microsoft.com/en-us/windows/wsl/wsl-config#network). + +```shell +# Run the full test suite: +cargo test + +# Run a specific test: +cargo test web_platform_tests + +# Run a specific test, and don't swallow test output: +cargo test web_platform_tests -- --nocapture +``` From 902ebb997346a6923ff719e6c0bfc13f6356e72f Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 11 Jan 2021 11:46:01 +0100 Subject: [PATCH 03/15] ci --- .github/workflows/ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7df48aca8cb96e..236ac8e1aadcae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -220,6 +220,16 @@ jobs: echo $(git rev-parse HEAD) > canary-latest.txt gsutil cp canary-latest.txt gs://dl.deno.land/canary-latest.txt + - name: Configure hosts file for WPT (unix) + if: runner.os != 'Windows' + run: ./wpt make-hosts-file | sudo tee -a /etc/hosts + working-directory: test_util/wpt/ + + - name: Configure hosts file for WPT (windows) + if: runner.os == 'Windows' + working-directory: test_util/wpt/ + run: python wpt make-hosts-file | Out-File $env:SystemRoot\System32\drivers\etc\hosts -Encoding ascii -Append + - name: Test release if: matrix.kind == 'test_release' run: cargo test --release --locked --all-targets From a1d65430cd18e913e7559fdeaf23b5be470718c7 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 11 Jan 2021 12:01:58 +0100 Subject: [PATCH 04/15] fmt --- docs/contributing/building_from_source.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/contributing/building_from_source.md b/docs/contributing/building_from_source.md index 325e149fa54bf8..7801d1b1504e10 100644 --- a/docs/contributing/building_from_source.md +++ b/docs/contributing/building_from_source.md @@ -112,24 +112,27 @@ cargo clean && cargo build -vv ### Testing -> :warning: **IMPORTANT**: Our test suite relies on certain entries to be configured in your /etc/hosts file. -> If these entries are not present in your /etc/hosts file, the `web_platform_tests` test **will** fail. To -> configure these entries, run the following command: -> +> :warning: **IMPORTANT**: Our test suite relies on certain entries to be +> configured in your /etc/hosts file. If these entries are not present in your +> /etc/hosts file, the `web_platform_tests` test **will** fail. To configure +> these entries, run the following command: + > ```shell > # macOS / Linux > cd test_utils/wpt/ > ./wpt make-hosts-file | sudo tee -a /etc/hosts > ``` -> + > ```powershell > # Windows (use powershell!) > cd test_utils/wpt/ > python wpt make-hosts-file | Out-File $env:SystemRoot\System32\drivers\etc\hosts -Encoding ascii -Append > ``` -> -> If you use WSL, be aware that WSL may attempt to override /etc/hosts each time it is launched, which would -> then require you to re-run hosts this setup. This behavior [can be configured](https://docs.microsoft.com/en-us/windows/wsl/wsl-config#network). + +> If you use WSL, be aware that WSL may attempt to override /etc/hosts each time +> it is launched, which would then require you to re-run hosts this setup. This +> behavior +> [can be configured](https://docs.microsoft.com/en-us/windows/wsl/wsl-config#network). ```shell # Run the full test suite: From cb869e626e6e3f7977b1d64057513f5502e7cc99 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 11 Jan 2021 13:53:54 +0100 Subject: [PATCH 05/15] change used ports --- cli/tests/unit/net_test.ts | 4 ++-- std/http/file_server_test.ts | 2 +- std/http/testdata/file_server_as_library.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/tests/unit/net_test.ts b/cli/tests/unit/net_test.ts index 62b00e43c5c3f9..930b2ea3955ce3 100644 --- a/cli/tests/unit/net_test.ts +++ b/cli/tests/unit/net_test.ts @@ -424,7 +424,7 @@ unitTest( unitTest( { perms: { net: true } }, async function netTcpListenCloseWhileIterating(): Promise { - const listener = Deno.listen({ port: 8000 }); + const listener = Deno.listen({ port: 8001 }); const nextWhileClosing = listener[Symbol.asyncIterator]().next(); listener.close(); assertEquals(await nextWhileClosing, { value: undefined, done: true }); @@ -437,7 +437,7 @@ unitTest( unitTest( { perms: { net: true } }, async function netUdpListenCloseWhileIterating(): Promise { - const socket = Deno.listenDatagram({ port: 8000, transport: "udp" }); + const socket = Deno.listenDatagram({ port: 8001, transport: "udp" }); const nextWhileClosing = socket[Symbol.asyncIterator]().next(); socket.close(); assertEquals(await nextWhileClosing, { value: undefined, done: true }); diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts index beb0c830d7039b..200426ea7c18aa 100644 --- a/std/http/file_server_test.ts +++ b/std/http/file_server_test.ts @@ -335,7 +335,7 @@ Deno.test("contentType", async () => { Deno.test("file_server running as library", async function (): Promise { await startFileServerAsLibrary(); try { - const res = await fetch("http://localhost:8000"); + const res = await fetch("http://localhost:4504"); assertEquals(res.status, 200); const _ = await res.text(); } finally { diff --git a/std/http/testdata/file_server_as_library.ts b/std/http/testdata/file_server_as_library.ts index cd4bf68dbf0264..87ff31584eddbc 100644 --- a/std/http/testdata/file_server_as_library.ts +++ b/std/http/testdata/file_server_as_library.ts @@ -1,7 +1,7 @@ import { serve } from "../server.ts"; import { serveFile } from "../file_server.ts"; -const server = serve({ port: 8000 }); +const server = serve({ port: 4504 }); console.log("Server running..."); From 0991baf02e97033367f6a4f9ee480a8aa3a7c9b2 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 11 Jan 2021 14:53:13 +0100 Subject: [PATCH 06/15] retrigger ci From 4730b07f2714bc8544960773a59f4a307a8096e3 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Wed, 13 Jan 2021 20:41:47 +0100 Subject: [PATCH 07/15] use #[cfg --- cli/tests/integration_tests.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index d93899f0c24ce6..e4cc58461011bb 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -5204,12 +5204,15 @@ impl Drop for WPTServer { fn drop(&mut self) { match self.0.try_wait() { Ok(None) => { - if cfg!(target_os = "linux") { + #[cfg(target_os = "linux")] + { println!("libc kill"); unsafe { libc::kill(self.0.id() as i32, libc::SIGTERM); } - } else { + } + #[cfg(not(target_os = "linux"))] + { println!("std kill"); self.0.kill().expect("killing 'wpt serve' failed"); } From 66eba654f819e899b7cfc2f848e8dd1b90366666 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Thu, 7 Jan 2021 21:44:40 +0100 Subject: [PATCH 08/15] tests: enable wpt for url --- .github/workflows/ci.yml | 10 + cli/tests/integration_tests.rs | 79 +++- cli/tests/unit/net_test.ts | 4 +- cli/tests/wpt.jsonc | 407 ++++++++++++++++++++ cli/tests/wpt_testharnessconsolereporter.js | 4 +- docs/contributing/building_from_source.md | 35 ++ std/http/file_server_test.ts | 2 +- std/http/testdata/file_server_as_library.ts | 2 +- 8 files changed, 534 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb3a9e440ffcdd..f5fc1aa81ed4ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -224,6 +224,16 @@ jobs: echo $(git rev-parse HEAD) > canary-latest.txt gsutil cp canary-latest.txt gs://dl.deno.land/canary-latest.txt + - name: Configure hosts file for WPT (unix) + if: runner.os != 'Windows' + run: ./wpt make-hosts-file | sudo tee -a /etc/hosts + working-directory: test_util/wpt/ + + - name: Configure hosts file for WPT (windows) + if: runner.os == 'Windows' + working-directory: test_util/wpt/ + run: python wpt make-hosts-file | Out-File $env:SystemRoot\System32\drivers\etc\hosts -Encoding ascii -Append + - name: Test release if: matrix.kind == 'test_release' run: cargo test --release --locked --all-targets diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 80a7222e53e815..013a1e54199378 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -5,6 +5,7 @@ use deno_core::serde_json; use deno_core::url; use deno_runtime::deno_fetch::reqwest; use deno_runtime::deno_websocket::tokio_tungstenite; +use std::io::BufReader; use std::io::{BufRead, Write}; use std::path::Path; use std::path::PathBuf; @@ -5236,6 +5237,32 @@ fn jsonc_to_serde(j: jsonc_parser::JsonValue) -> serde_json::Value { } } +struct WPTServer(std::process::Child); + +impl Drop for WPTServer { + fn drop(&mut self) { + match self.0.try_wait() { + Ok(None) => { + #[cfg(target_os = "linux")] + { + println!("libc kill"); + unsafe { + libc::kill(self.0.id() as i32, libc::SIGTERM); + } + } + #[cfg(not(target_os = "linux"))] + { + println!("std kill"); + self.0.kill().expect("killing 'wpt serve' failed"); + } + let _ = self.0.wait(); + } + Ok(Some(status)) => panic!("'wpt serve' exited unexpectedly {}", status), + Err(e) => panic!("'wpt serve' error: {}", e), + } + } +} + #[test] fn web_platform_tests() { use deno_core::serde::Deserialize; @@ -5257,6 +5284,43 @@ fn web_platform_tests() { let config: std::collections::HashMap> = deno_core::serde_json::from_value(jsonc_to_serde(jsonc)).unwrap(); + let mut proc = Command::new("python3") + .current_dir(util::wpt_path()) + .arg("wpt") + .arg("serve") + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap(); + + let stderr = proc.stderr.as_mut().unwrap(); + let mut stderr = BufReader::new(stderr).lines(); + let mut ready_8000 = false; + let mut ready_8443 = false; + let mut ready_8444 = false; + let mut ready_9000 = false; + while let Ok(line) = stderr.next().unwrap() { + if !line.starts_with("DEBUG:") { + eprintln!("{}", line); + } + if line.contains("web-platform.test:8000") { + ready_8000 = true; + } + if line.contains("web-platform.test:8443") { + ready_8443 = true; + } + if line.contains("web-platform.test:8444") { + ready_8444 = true; + } + if line.contains("web-platform.test:9000") { + ready_9000 = true; + } + if ready_8000 && ready_8443 && ready_8444 && ready_9000 { + break; + } + } + + let _wpt_server = WPTServer(proc); + for (suite_name, includes) in config.into_iter() { let suite_path = util::wpt_path().join(suite_name); let dir = WalkDir::new(&suite_path) @@ -5337,14 +5401,15 @@ fn web_platform_tests() { }) .collect(); - let mut variants: Vec<&str> = test_file_text + let mut variants: Vec = test_file_text .split('\n') .into_iter() .filter_map(|t| t.strip_prefix("// META: variant=")) + .map(|t| format!("?{}", t)) .collect(); if variants.is_empty() { - variants.push(""); + variants.push("".to_string()); } for variant in variants { @@ -5367,11 +5432,19 @@ fn web_platform_tests() { let bundle = concat_bundle(files, file.path(), "".to_string()); file.write_all(bundle.as_bytes()).unwrap(); + let self_path = test_file_path.strip_prefix(util::wpt_path()).unwrap(); + let child = util::deno_cmd() .current_dir(test_file_path.parent().unwrap()) .arg("run") .arg("--location") - .arg(&format!("http://web-platform-tests/?{}", variant)) + .arg(&format!( + "http://web-platform.test:8000/{}{}", + self_path.to_str().unwrap(), + variant + )) + .arg("--cert") + .arg(util::wpt_path().join("tools/certs/cacert.pem")) .arg("-A") .arg(file.path()) .arg(deno_core::serde_json::to_string(&expect_fail).unwrap()) diff --git a/cli/tests/unit/net_test.ts b/cli/tests/unit/net_test.ts index 99af959cc3cefd..f69745ea5d6705 100644 --- a/cli/tests/unit/net_test.ts +++ b/cli/tests/unit/net_test.ts @@ -424,7 +424,7 @@ unitTest( unitTest( { perms: { net: true } }, async function netTcpListenCloseWhileIterating(): Promise { - const listener = Deno.listen({ port: 8000 }); + const listener = Deno.listen({ port: 8001 }); const nextWhileClosing = listener[Symbol.asyncIterator]().next(); listener.close(); assertEquals(await nextWhileClosing, { value: undefined, done: true }); @@ -437,7 +437,7 @@ unitTest( unitTest( { perms: { net: true } }, async function netUdpListenCloseWhileIterating(): Promise { - const socket = Deno.listenDatagram({ port: 8000, transport: "udp" }); + const socket = Deno.listenDatagram({ port: 8001, transport: "udp" }); const nextWhileClosing = socket[Symbol.asyncIterator]().next(); socket.close(); assertEquals(await nextWhileClosing, { value: undefined, done: true }); diff --git a/cli/tests/wpt.jsonc b/cli/tests/wpt.jsonc index 8774ca793be584..8b2e51280d0efd 100644 --- a/cli/tests/wpt.jsonc +++ b/cli/tests/wpt.jsonc @@ -261,5 +261,412 @@ "does not inherit from Error: class-side" ] } + ], + "url": [ + "historical", + { + "name": "url-constructor", + "expectFail": [ + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <:#> against ", + "Parsing: <#> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: < File:c|////foo\\bar.html> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <\u0000\u001b\u0004\u0012 http://example.com/\u001f \r > against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <#> against ", + "Parsing: <#> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <../i> against ", + "Parsing: <../i> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <\\/localhost//pig> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <\\\\\\.\\Y:> against ", + "Parsing: <\\\\\\.\\y:> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <#x> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: <..//path> against ", + "Parsing: against ", + "Parsing: <> against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against ", + "Parsing: against " + ] + }, + { + "name": "url-origin", + "expectFail": [ + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: <\u0000\u001b\u0004\u0012 http://example.com/\u001f \r > against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: <../i> against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: <#i> against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: <#x> against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against ", + "Origin parsing: against " + ] + }, + { + "name": "url-searchparams", + "expectFail": [ + "URL.searchParams updating, clearing", + "URL.searchParams and URL.search setters, update propagation" + ] + }, + { + "name": "url-setters-stripping", + "expectFail": [ + "Setting protocol with leading U+0000 (https:)", + "Setting protocol with U+0000 before inserted colon (https:)", + "Setting host with leading U+0000 (https:)", + "Setting host with middle U+0000 (https:)", + "Setting host with trailing U+0000 (https:)", + "Setting port with middle U+0000 (https:)", + "Setting port with trailing U+0000 (https:)", + "Setting protocol with leading U+0009 (https:)", + "Setting protocol with U+0009 before inserted colon (https:)", + "Setting host with leading U+0009 (https:)", + "Setting hostname with leading U+0009 (https:)", + "Setting host with middle U+0009 (https:)", + "Setting hostname with middle U+0009 (https:)", + "Setting host with trailing U+0009 (https:)", + "Setting hostname with trailing U+0009 (https:)", + "Setting port with leading U+0009 (https:)", + "Setting port with middle U+0009 (https:)", + "Setting port with trailing U+0009 (https:)", + "Setting pathname with leading U+0009 (https:)", + "Setting pathname with middle U+0009 (https:)", + "Setting pathname with trailing U+0009 (https:)", + "Setting search with leading U+0009 (https:)", + "Setting search with middle U+0009 (https:)", + "Setting search with trailing U+0009 (https:)", + "Setting hash with leading U+0009 (https:)", + "Setting hash with middle U+0009 (https:)", + "Setting hash with trailing U+0009 (https:)", + "Setting protocol with leading U+000A (https:)", + "Setting protocol with U+000A before inserted colon (https:)", + "Setting host with leading U+000A (https:)", + "Setting hostname with leading U+000A (https:)", + "Setting host with middle U+000A (https:)", + "Setting hostname with middle U+000A (https:)", + "Setting host with trailing U+000A (https:)", + "Setting hostname with trailing U+000A (https:)", + "Setting port with leading U+000A (https:)", + "Setting port with middle U+000A (https:)", + "Setting port with trailing U+000A (https:)", + "Setting pathname with leading U+000A (https:)", + "Setting pathname with middle U+000A (https:)", + "Setting pathname with trailing U+000A (https:)", + "Setting search with leading U+000A (https:)", + "Setting search with middle U+000A (https:)", + "Setting search with trailing U+000A (https:)", + "Setting hash with leading U+000A (https:)", + "Setting hash with middle U+000A (https:)", + "Setting hash with trailing U+000A (https:)", + "Setting protocol with leading U+000D (https:)", + "Setting protocol with U+000D before inserted colon (https:)", + "Setting host with leading U+000D (https:)", + "Setting hostname with leading U+000D (https:)", + "Setting host with middle U+000D (https:)", + "Setting hostname with middle U+000D (https:)", + "Setting host with trailing U+000D (https:)", + "Setting hostname with trailing U+000D (https:)", + "Setting port with leading U+000D (https:)", + "Setting port with middle U+000D (https:)", + "Setting port with trailing U+000D (https:)", + "Setting pathname with leading U+000D (https:)", + "Setting pathname with middle U+000D (https:)", + "Setting pathname with trailing U+000D (https:)", + "Setting search with leading U+000D (https:)", + "Setting search with middle U+000D (https:)", + "Setting search with trailing U+000D (https:)", + "Setting hash with leading U+000D (https:)", + "Setting hash with middle U+000D (https:)", + "Setting hash with trailing U+000D (https:)", + "Setting protocol with leading U+001F (https:)", + "Setting protocol with U+001F before inserted colon (https:)", + "Setting host with leading U+001F (https:)", + "Setting host with middle U+001F (https:)", + "Setting host with trailing U+001F (https:)", + "Setting port with middle U+001F (https:)", + "Setting port with trailing U+001F (https:)", + "Setting protocol with leading U+0000 (wpt++:)", + "Setting protocol with U+0000 before inserted colon (wpt++:)", + "Setting host with leading U+0000 (wpt++:)", + "Setting host with middle U+0000 (wpt++:)", + "Setting host with trailing U+0000 (wpt++:)", + "Setting port with middle U+0000 (wpt++:)", + "Setting port with trailing U+0000 (wpt++:)", + "Setting pathname with leading U+0000 (wpt++:)", + "Setting pathname with middle U+0000 (wpt++:)", + "Setting pathname with trailing U+0000 (wpt++:)", + "Setting protocol with leading U+0009 (wpt++:)", + "Setting protocol with U+0009 before inserted colon (wpt++:)", + "Setting host with leading U+0009 (wpt++:)", + "Setting hostname with leading U+0009 (wpt++:)", + "Setting host with middle U+0009 (wpt++:)", + "Setting hostname with middle U+0009 (wpt++:)", + "Setting host with trailing U+0009 (wpt++:)", + "Setting hostname with trailing U+0009 (wpt++:)", + "Setting port with leading U+0009 (wpt++:)", + "Setting port with middle U+0009 (wpt++:)", + "Setting port with trailing U+0009 (wpt++:)", + "Setting pathname with leading U+0009 (wpt++:)", + "Setting pathname with middle U+0009 (wpt++:)", + "Setting pathname with trailing U+0009 (wpt++:)", + "Setting search with leading U+0009 (wpt++:)", + "Setting search with middle U+0009 (wpt++:)", + "Setting search with trailing U+0009 (wpt++:)", + "Setting hash with leading U+0009 (wpt++:)", + "Setting hash with middle U+0009 (wpt++:)", + "Setting hash with trailing U+0009 (wpt++:)", + "Setting protocol with leading U+000A (wpt++:)", + "Setting protocol with U+000A before inserted colon (wpt++:)", + "Setting host with leading U+000A (wpt++:)", + "Setting hostname with leading U+000A (wpt++:)", + "Setting host with middle U+000A (wpt++:)", + "Setting hostname with middle U+000A (wpt++:)", + "Setting host with trailing U+000A (wpt++:)", + "Setting hostname with trailing U+000A (wpt++:)", + "Setting port with leading U+000A (wpt++:)", + "Setting port with middle U+000A (wpt++:)", + "Setting port with trailing U+000A (wpt++:)", + "Setting pathname with leading U+000A (wpt++:)", + "Setting pathname with middle U+000A (wpt++:)", + "Setting pathname with trailing U+000A (wpt++:)", + "Setting search with leading U+000A (wpt++:)", + "Setting search with middle U+000A (wpt++:)", + "Setting search with trailing U+000A (wpt++:)", + "Setting hash with leading U+000A (wpt++:)", + "Setting hash with middle U+000A (wpt++:)", + "Setting hash with trailing U+000A (wpt++:)", + "Setting protocol with leading U+000D (wpt++:)", + "Setting protocol with U+000D before inserted colon (wpt++:)", + "Setting host with leading U+000D (wpt++:)", + "Setting hostname with leading U+000D (wpt++:)", + "Setting host with middle U+000D (wpt++:)", + "Setting hostname with middle U+000D (wpt++:)", + "Setting host with trailing U+000D (wpt++:)", + "Setting hostname with trailing U+000D (wpt++:)", + "Setting port with leading U+000D (wpt++:)", + "Setting port with middle U+000D (wpt++:)", + "Setting port with trailing U+000D (wpt++:)", + "Setting pathname with leading U+000D (wpt++:)", + "Setting pathname with middle U+000D (wpt++:)", + "Setting pathname with trailing U+000D (wpt++:)", + "Setting search with leading U+000D (wpt++:)", + "Setting search with middle U+000D (wpt++:)", + "Setting search with trailing U+000D (wpt++:)", + "Setting hash with leading U+000D (wpt++:)", + "Setting hash with middle U+000D (wpt++:)", + "Setting hash with trailing U+000D (wpt++:)", + "Setting protocol with leading U+001F (wpt++:)", + "Setting protocol with U+001F before inserted colon (wpt++:)", + "Setting host with leading U+001F (wpt++:)", + "Setting host with middle U+001F (wpt++:)", + "Setting host with trailing U+001F (wpt++:)", + "Setting port with middle U+001F (wpt++:)", + "Setting port with trailing U+001F (wpt++:)", + "Setting pathname with leading U+001F (wpt++:)", + "Setting pathname with middle U+001F (wpt++:)", + "Setting pathname with trailing U+001F (wpt++:)" + ] + }, + "url-tojson", + { + "name": "urlencoded-parser", + "expectFail": [ + "URLSearchParams constructed with: %EF%BB%BFtest=%EF%BB%BF", + "request.formData() with input: test=", + "response.formData() with input: test=", + "request.formData() with input: %FE%FF", + "response.formData() with input: %FE%FF", + "request.formData() with input: %FF%FE", + "response.formData() with input: %FF%FE", + "request.formData() with input: %C2", + "response.formData() with input: %C2", + "request.formData() with input: %C2x", + "response.formData() with input: %C2x", + "request.formData() with input: _charset_=windows-1252&test=%C2x", + "response.formData() with input: _charset_=windows-1252&test=%C2x", + "request.formData() with input: %=a", + "response.formData() with input: %=a", + "request.formData() with input: %a=a", + "response.formData() with input: %a=a", + "request.formData() with input: %a_=a", + "response.formData() with input: %a_=a", + "request.formData() with input: id=0&value=%", + "response.formData() with input: id=0&value=%", + "request.formData() with input: b=%2sf%2a", + "response.formData() with input: b=%2sf%2a", + "request.formData() with input: b=%2%2af%2a", + "response.formData() with input: b=%2%2af%2a", + "request.formData() with input: b=%%2a", + "response.formData() with input: b=%%2a" + ] + }, + "urlsearchparams-append", + { + "name": "urlsearchparams-constructor", + "expectFail": [ + "URLSearchParams constructor, DOMException as argument", + "URLSearchParams constructor, empty string as argument", + "Construct with 2 unpaired surrogates (no trailing)", + "Construct with 3 unpaired surrogates (no leading)", + "Construct with object with NULL, non-ASCII, and surrogate keys" + ] + }, + "urlsearchparams-delete", + { + "name": "urlsearchparams-foreach", + "expectFail": [ + "For-of Check", + "delete next param during iteration", + "delete current param during iteration", + "delete every param seen during iteration" + ] + }, + "urlsearchparams-get", + "urlsearchparams-getall", + "urlsearchparams-has", + "urlsearchparams-set", + "urlsearchparams-sort", + "urlsearchparams-stringifier" ] } diff --git a/cli/tests/wpt_testharnessconsolereporter.js b/cli/tests/wpt_testharnessconsolereporter.js index 2e0e06c020225e..24979ce52bef24 100644 --- a/cli/tests/wpt_testharnessconsolereporter.js +++ b/cli/tests/wpt_testharnessconsolereporter.js @@ -111,13 +111,13 @@ window.add_completion_callback((tests, harnessStatus) => { console.log(`\nfailures:\n`); } for (const result of failed) { - console.log(` ${result.name}`); + console.log(` ${JSON.stringify(result.name)}`); } if (expectedFailedButPassedCount > 0) { console.log(`\nexpected failures that passed:\n`); } for (const result of expectedFailedButPassed) { - console.log(` ${result.name}`); + console.log(` ${JSON.stringify(result.name)}`); } console.log( `\ntest result: ${ diff --git a/docs/contributing/building_from_source.md b/docs/contributing/building_from_source.md index 227b424188650e..7801d1b1504e10 100644 --- a/docs/contributing/building_from_source.md +++ b/docs/contributing/building_from_source.md @@ -109,3 +109,38 @@ cargo clean && cargo build -vv # Run: ./target/debug/deno run cli/tests/002_hello.ts ``` + +### Testing + +> :warning: **IMPORTANT**: Our test suite relies on certain entries to be +> configured in your /etc/hosts file. If these entries are not present in your +> /etc/hosts file, the `web_platform_tests` test **will** fail. To configure +> these entries, run the following command: + +> ```shell +> # macOS / Linux +> cd test_utils/wpt/ +> ./wpt make-hosts-file | sudo tee -a /etc/hosts +> ``` + +> ```powershell +> # Windows (use powershell!) +> cd test_utils/wpt/ +> python wpt make-hosts-file | Out-File $env:SystemRoot\System32\drivers\etc\hosts -Encoding ascii -Append +> ``` + +> If you use WSL, be aware that WSL may attempt to override /etc/hosts each time +> it is launched, which would then require you to re-run hosts this setup. This +> behavior +> [can be configured](https://docs.microsoft.com/en-us/windows/wsl/wsl-config#network). + +```shell +# Run the full test suite: +cargo test + +# Run a specific test: +cargo test web_platform_tests + +# Run a specific test, and don't swallow test output: +cargo test web_platform_tests -- --nocapture +``` diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts index 638121b45ae9d2..94d97cc374480e 100644 --- a/std/http/file_server_test.ts +++ b/std/http/file_server_test.ts @@ -335,7 +335,7 @@ Deno.test("contentType", async () => { Deno.test("file_server running as library", async function (): Promise { await startFileServerAsLibrary(); try { - const res = await fetch("http://localhost:8000"); + const res = await fetch("http://localhost:4504"); assertEquals(res.status, 200); const _ = await res.text(); } finally { diff --git a/std/http/testdata/file_server_as_library.ts b/std/http/testdata/file_server_as_library.ts index cd4bf68dbf0264..87ff31584eddbc 100644 --- a/std/http/testdata/file_server_as_library.ts +++ b/std/http/testdata/file_server_as_library.ts @@ -1,7 +1,7 @@ import { serve } from "../server.ts"; import { serveFile } from "../file_server.ts"; -const server = serve({ port: 8000 }); +const server = serve({ port: 4504 }); console.log("Server running..."); From 73148c714a0a25a94761b61ff6bc64a7cca9efa6 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 15 Jan 2021 13:11:03 +0100 Subject: [PATCH 09/15] squash! remove since-fixed expectFail --- cli/tests/wpt.jsonc | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/tests/wpt.jsonc b/cli/tests/wpt.jsonc index 8b2e51280d0efd..8be1642facca48 100644 --- a/cli/tests/wpt.jsonc +++ b/cli/tests/wpt.jsonc @@ -645,7 +645,6 @@ { "name": "urlsearchparams-constructor", "expectFail": [ - "URLSearchParams constructor, DOMException as argument", "URLSearchParams constructor, empty string as argument", "Construct with 2 unpaired surrogates (no trailing)", "Construct with 3 unpaired surrogates (no leading)", From ea7d6b593ecd3b788f3b7b14d8fec0db05c6d315 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 20 Jan 2021 11:54:23 +0100 Subject: [PATCH 10/15] squash! use /usr/bin/python on macos --- cli/tests/integration_tests.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 013a1e54199378..3c79c1bb7443ad 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -5284,7 +5284,15 @@ fn web_platform_tests() { let config: std::collections::HashMap> = deno_core::serde_json::from_value(jsonc_to_serde(jsonc)).unwrap(); - let mut proc = Command::new("python3") + // Observation: `python3 wpt serve` hangs with the python3 from homebrew + // but works okay with /usr/bin/python, which is python 2.7.10. Observed + // with homebrew python 3.8.5, 3.8.7 and 3.9.1. + let python = match cfg!(target_os = "macos") { + true => "python", + false => "python3", + }; + + let mut proc = Command::new(python) .current_dir(util::wpt_path()) .arg("wpt") .arg("serve") @@ -5314,6 +5322,10 @@ fn web_platform_tests() { if line.contains("web-platform.test:9000") { ready_9000 = true; } + // WPT + python2 doesn't support HTTP/2.0. + if line.contains("Cannot start HTTP/2.0 server") { + ready_9000 = true; + } if ready_8000 && ready_8443 && ready_8444 && ready_9000 { break; } From 5c8156c849f323d7c153d96f4d9f6da9564cf497 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 20 Jan 2021 22:02:51 +0100 Subject: [PATCH 11/15] squash! python.exe on windows? --- cli/tests/integration_tests.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 3c79c1bb7443ad..f6179f9f77d5ca 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -5287,9 +5287,10 @@ fn web_platform_tests() { // Observation: `python3 wpt serve` hangs with the python3 from homebrew // but works okay with /usr/bin/python, which is python 2.7.10. Observed // with homebrew python 3.8.5, 3.8.7 and 3.9.1. - let python = match cfg!(target_os = "macos") { - true => "python", - false => "python3", + let python = match true { + _ if cfg!(target_os = "windows") => "python.exe", + _ if cfg!(target_os = "macos") => "python", + _ => "python3", }; let mut proc = Command::new(python) From dd0000c3b94967cdc5f0d60efcd947c4466ecefa Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 21 Jan 2021 10:39:08 +0100 Subject: [PATCH 12/15] squash! disable wpt tests on windows ci --- cli/tests/integration_tests.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index f6179f9f77d5ca..5ea40f5f0ee121 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -5284,6 +5284,12 @@ fn web_platform_tests() { let config: std::collections::HashMap> = deno_core::serde_json::from_value(jsonc_to_serde(jsonc)).unwrap(); + // The windows-2019 buildbots are too slow to finish the WPT tests within + // the 1 hour time limit. + if cfg!(target_os = "windows") && std::env::var("CI").is_ok() { + return; + } + // Observation: `python3 wpt serve` hangs with the python3 from homebrew // but works okay with /usr/bin/python, which is python 2.7.10. Observed // with homebrew python 3.8.5, 3.8.7 and 3.9.1. From d4eb20ecdecfed68557c196d2d47414322be11e2 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Sun, 24 Jan 2021 12:30:22 +0100 Subject: [PATCH 13/15] merge artifact --- cli/tests/integration_tests.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index e603ca702fbada..5ea40f5f0ee121 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -5329,13 +5329,10 @@ fn web_platform_tests() { if line.contains("web-platform.test:9000") { ready_9000 = true; } -<<<<<<< HEAD -======= // WPT + python2 doesn't support HTTP/2.0. if line.contains("Cannot start HTTP/2.0 server") { ready_9000 = true; } ->>>>>>> dd0000c3b94967cdc5f0d60efcd947c4466ecefa if ready_8000 && ready_8443 && ready_8444 && ready_9000 { break; } From 7ae5695d90998116df68496e1288239bd9bc41e4 Mon Sep 17 00:00:00 2001 From: Luca Date: Sun, 24 Jan 2021 13:38:38 +0100 Subject: [PATCH 14/15] wpt on windows --- cli/tests/integration_tests.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 5ea40f5f0ee121..968b0486143c6a 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -5284,12 +5284,6 @@ fn web_platform_tests() { let config: std::collections::HashMap> = deno_core::serde_json::from_value(jsonc_to_serde(jsonc)).unwrap(); - // The windows-2019 buildbots are too slow to finish the WPT tests within - // the 1 hour time limit. - if cfg!(target_os = "windows") && std::env::var("CI").is_ok() { - return; - } - // Observation: `python3 wpt serve` hangs with the python3 from homebrew // but works okay with /usr/bin/python, which is python 2.7.10. Observed // with homebrew python 3.8.5, 3.8.7 and 3.9.1. @@ -5299,9 +5293,11 @@ fn web_platform_tests() { _ => "python3", }; + eprintln!("If the wpt server fails or gets stuck, please set up your /etc/hosts file like specified in //docs/contributing/building_from_source.md."); + let mut proc = Command::new(python) .current_dir(util::wpt_path()) - .arg("wpt") + .arg("wpt.py") .arg("serve") .stderr(std::process::Stdio::piped()) .spawn() @@ -5317,6 +5313,9 @@ fn web_platform_tests() { if !line.starts_with("DEBUG:") { eprintln!("{}", line); } + if cfg!(target_os = "windows") && line.contains("Using ports") { + break; + } if line.contains("web-platform.test:8000") { ready_8000 = true; } From 7683e4a40c0002d403e99696ed684449afe44428 Mon Sep 17 00:00:00 2001 From: Luca Date: Sun, 24 Jan 2021 14:05:13 +0100 Subject: [PATCH 15/15] fmt --- cli/tests/integration_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 968b0486143c6a..403458a14db388 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -5294,7 +5294,7 @@ fn web_platform_tests() { }; eprintln!("If the wpt server fails or gets stuck, please set up your /etc/hosts file like specified in //docs/contributing/building_from_source.md."); - + let mut proc = Command::new(python) .current_dir(util::wpt_path()) .arg("wpt.py")