summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2024-05-28 20:25:46 +0900
committerGitHub <noreply@github.com>2024-05-28 20:25:46 +0900
commite9cc8a2b53ee43289ab964539cca4753e700b6c3 (patch)
treec754d725aa13c5c7dcac6176fb7d0a4b4ee730bf
parent1f913f2eb6a2b958a6dadaf67283726ae1321236 (diff)
fix(coverage): skip generating coverage json for http(s) scripts (#24008)
closes #21784
-rw-r--r--cli/tools/coverage/mod.rs4
-rw-r--r--tests/integration/coverage_tests.rs33
-rw-r--r--tests/testdata/coverage/no_http_coverage_data_test.ts5
3 files changed, 41 insertions, 1 deletions
diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs
index e1c5d9eb4..699d4a583 100644
--- a/cli/tools/coverage/mod.rs
+++ b/cli/tools/coverage/mod.rs
@@ -68,9 +68,11 @@ impl crate::worker::CoverageCollector for CoverageCollector {
let script_coverages = self.take_precise_coverage().await?.result;
for script_coverage in script_coverages {
- // Filter out internal JS files from being included in coverage reports
+ // Filter out internal and http/https JS files from being included in coverage reports
if script_coverage.url.starts_with("ext:")
|| script_coverage.url.starts_with("[ext:")
+ || script_coverage.url.starts_with("http:")
+ || script_coverage.url.starts_with("https:")
|| script_coverage.url.starts_with("node:")
{
continue;
diff --git a/tests/integration/coverage_tests.rs b/tests/integration/coverage_tests.rs
index c1e5055da..51b82af07 100644
--- a/tests/integration/coverage_tests.rs
+++ b/tests/integration/coverage_tests.rs
@@ -440,6 +440,39 @@ fn no_internal_node_code() {
}
#[test]
+fn no_http_coverage_data() {
+ let _http_server_guard = test_util::http_server();
+ let context = TestContext::default();
+ let tempdir = context.temp_dir();
+ let tempdir = tempdir.path().join("cov");
+
+ let output = context
+ .new_command()
+ .args_vec(vec![
+ "test".to_string(),
+ "--quiet".to_string(),
+ "--no-check".to_string(),
+ format!("--coverage={}", tempdir),
+ "coverage/no_http_coverage_data_test.ts".to_string(),
+ ])
+ .run();
+
+ output.assert_exit_code(0);
+ output.skip_output_check();
+
+ // Check that coverage files contain no http urls
+ let paths = tempdir.read_dir();
+ for path in paths {
+ let unwrapped = PathRef::new(path.unwrap().path());
+ let data = unwrapped.read_to_string();
+
+ let value: serde_json::Value = serde_json::from_str(&data).unwrap();
+ let url = value["url"].as_str().unwrap();
+ assert_starts_with!(url, "file:");
+ }
+}
+
+#[test]
fn test_html_reporter() {
// This test case generates a html coverage report of test cases in /tests/testdata/coverage/multisource
// You can get the same reports in ./cov_html by running the following command:
diff --git a/tests/testdata/coverage/no_http_coverage_data_test.ts b/tests/testdata/coverage/no_http_coverage_data_test.ts
new file mode 100644
index 000000000..c196e9aba
--- /dev/null
+++ b/tests/testdata/coverage/no_http_coverage_data_test.ts
@@ -0,0 +1,5 @@
+import "http://localhost:4546/run/001_hello.js";
+
+Deno.test("hello", () => {
+ console.log("hello");
+});