summaryrefslogtreecommitdiff
path: root/cli/tests/integration/coverage_tests.rs
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2023-09-11 15:53:42 +0200
committerGitHub <noreply@github.com>2023-09-11 13:53:42 +0000
commit9d1385896f3c170cf4e0cb744cc2e88e12af50ab (patch)
tree6951113a3a23b135cce753850df4901d8aabf40e /cli/tests/integration/coverage_tests.rs
parent4460336fdae3a6c0c8ebe8e6b8842604743cf985 (diff)
fix: exclude internal JS files from coverage (#20448)
Diffstat (limited to 'cli/tests/integration/coverage_tests.rs')
-rw-r--r--cli/tests/integration/coverage_tests.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/cli/tests/integration/coverage_tests.rs b/cli/tests/integration/coverage_tests.rs
index a8b3ec3a1..d8a11a624 100644
--- a/cli/tests/integration/coverage_tests.rs
+++ b/cli/tests/integration/coverage_tests.rs
@@ -1,8 +1,10 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+use deno_core::serde_json;
use std::fs;
use test_util as util;
use test_util::TempDir;
+use util::assert_starts_with;
use util::env_vars_for_npm_tests;
use util::TestContext;
use util::TestContextBuilder;
@@ -439,3 +441,66 @@ fn no_transpiled_lines() {
output.assert_exit_code(0);
}
+
+#[test]
+fn no_internal_code() {
+ 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(),
+ format!("--coverage={}", tempdir),
+ "coverage/no_internal_code_test.ts".to_string(),
+ ])
+ .run();
+
+ output.assert_exit_code(0);
+ output.skip_output_check();
+
+ // Check that coverage files contain no internal urls
+ let paths = fs::read_dir(tempdir).unwrap();
+ for path in paths {
+ let unwrapped = path.unwrap().path();
+ let data = fs::read_to_string(&unwrapped.clone()).unwrap();
+
+ 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 no_internal_node_code() {
+ 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_internal_node_code_test.ts".to_string(),
+ ])
+ .run();
+
+ output.assert_exit_code(0);
+ output.skip_output_check();
+
+ // Check that coverage files contain no internal urls
+ let paths = fs::read_dir(tempdir).unwrap();
+ for path in paths {
+ let unwrapped = path.unwrap().path();
+ let data = fs::read_to_string(&unwrapped.clone()).unwrap();
+
+ let value: serde_json::Value = serde_json::from_str(&data).unwrap();
+ let url = value["url"].as_str().unwrap();
+ assert_starts_with!(url, "file:");
+ }
+}