Skip to content

Commit

Permalink
fix(coverage): skip generating coverage json for http(s) scripts (den…
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed May 28, 2024
1 parent 1f913f2 commit e9cc8a2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cli/tools/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions tests/integration/coverage_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,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
Expand Down
5 changes: 5 additions & 0 deletions tests/testdata/coverage/no_http_coverage_data_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "http:https://localhost:4546/run/001_hello.js";

Deno.test("hello", () => {
console.log("hello");
});

0 comments on commit e9cc8a2

Please sign in to comment.