mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
parent
a8ca09f78a
commit
c336755881
8 changed files with 81 additions and 2 deletions
|
@ -26,6 +26,13 @@ fn no_snaps() {
|
||||||
no_snaps_included("no_snaps_included", "ts");
|
no_snaps_included("no_snaps_included", "ts");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_tests() {
|
||||||
|
no_tests_included("foo", "mts");
|
||||||
|
no_tests_included("foo", "ts");
|
||||||
|
no_tests_included("foo", "js");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_if_invalid_cache() {
|
fn error_if_invalid_cache() {
|
||||||
let context = TestContextBuilder::new().use_temp_cwd().build();
|
let context = TestContextBuilder::new().use_temp_cwd().build();
|
||||||
|
@ -277,6 +284,53 @@ fn no_snaps_included(test_name: &str, extension: &str) {
|
||||||
output.assert_exit_code(0);
|
output.assert_exit_code(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn no_tests_included(test_name: &str, extension: &str) {
|
||||||
|
let context = TestContext::default();
|
||||||
|
let tempdir = context.deno_dir();
|
||||||
|
let tempdir = tempdir.path().join("cov");
|
||||||
|
|
||||||
|
let output = context
|
||||||
|
.new_command()
|
||||||
|
.args_vec(vec![
|
||||||
|
"test".to_string(),
|
||||||
|
"--quiet".to_string(),
|
||||||
|
"--allow-read".to_string(),
|
||||||
|
format!("--coverage={}", tempdir.to_str().unwrap()),
|
||||||
|
format!("coverage/no_tests_included/{test_name}.test.{extension}"),
|
||||||
|
])
|
||||||
|
.run();
|
||||||
|
|
||||||
|
output.assert_exit_code(0);
|
||||||
|
output.skip_output_check();
|
||||||
|
|
||||||
|
let output = context
|
||||||
|
.new_command()
|
||||||
|
.args_vec(vec![
|
||||||
|
"coverage".to_string(),
|
||||||
|
format!("{}/", tempdir.to_str().unwrap()),
|
||||||
|
])
|
||||||
|
.split_output()
|
||||||
|
.run();
|
||||||
|
|
||||||
|
// Verify there's no "Check" being printed
|
||||||
|
assert!(output.stderr().is_empty());
|
||||||
|
|
||||||
|
let actual = util::strip_ansi_codes(output.stdout()).to_string();
|
||||||
|
|
||||||
|
let expected = fs::read_to_string(
|
||||||
|
util::testdata_path().join("coverage/no_tests_included/expected.out"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if !util::wildcard_match(&expected, &actual) {
|
||||||
|
println!("OUTPUT\n{actual}\nOUTPUT");
|
||||||
|
println!("EXPECTED\n{expected}\nEXPECTED");
|
||||||
|
panic!("pattern match failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
output.assert_exit_code(0);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_npm_cache_coverage() {
|
fn no_npm_cache_coverage() {
|
||||||
let context = TestContext::default();
|
let context = TestContext::default();
|
||||||
|
|
1
cli/tests/testdata/coverage/no_tests_included/expected.out
vendored
Normal file
1
cli/tests/testdata/coverage/no_tests_included/expected.out
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
cover [WILDCARD]/no_tests_included/foo.ts ... 100.000% (3/3)
|
6
cli/tests/testdata/coverage/no_tests_included/foo.test.js
vendored
Normal file
6
cli/tests/testdata/coverage/no_tests_included/foo.test.js
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { addNumbers } from "./foo.ts";
|
||||||
|
import { assertEquals } from "https://deno.land/std@0.183.0/testing/asserts.ts";
|
||||||
|
|
||||||
|
Deno.test("addNumbers works", () => {
|
||||||
|
assertEquals(addNumbers(1, 2), 3);
|
||||||
|
});
|
6
cli/tests/testdata/coverage/no_tests_included/foo.test.mts
vendored
Normal file
6
cli/tests/testdata/coverage/no_tests_included/foo.test.mts
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { addNumbers } from './foo.ts';
|
||||||
|
import { assertEquals } from "https://deno.land/std@0.183.0/testing/asserts.ts";
|
||||||
|
|
||||||
|
Deno.test("addNumbers works", () => {
|
||||||
|
assertEquals(addNumbers(1, 2), 3);
|
||||||
|
});
|
6
cli/tests/testdata/coverage/no_tests_included/foo.test.ts
vendored
Normal file
6
cli/tests/testdata/coverage/no_tests_included/foo.test.ts
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { addNumbers } from "./foo.ts";
|
||||||
|
import { assertEquals } from "https://deno.land/std@0.183.0/testing/asserts.ts";
|
||||||
|
|
||||||
|
Deno.test("addNumbers works", () => {
|
||||||
|
assertEquals(addNumbers(1, 2), 3);
|
||||||
|
});
|
3
cli/tests/testdata/coverage/no_tests_included/foo.ts
vendored
Normal file
3
cli/tests/testdata/coverage/no_tests_included/foo.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export function addNumbers(a: number, b: number): number {
|
||||||
|
return a + b;
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ use crate::args::Flags;
|
||||||
use crate::colors;
|
use crate::colors;
|
||||||
use crate::proc_state::ProcState;
|
use crate::proc_state::ProcState;
|
||||||
use crate::tools::fmt::format_json;
|
use crate::tools::fmt::format_json;
|
||||||
|
use crate::tools::test::is_supported_test_path;
|
||||||
use crate::util::fs::FileCollector;
|
use crate::util::fs::FileCollector;
|
||||||
use crate::util::text_encoding::source_map_from_code;
|
use crate::util::text_encoding::source_map_from_code;
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ use std::io::BufWriter;
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::io::{self};
|
use std::io::{self};
|
||||||
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use text_lines::TextLines;
|
use text_lines::TextLines;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -602,7 +604,8 @@ fn filter_coverages(
|
||||||
|| e.url.starts_with(npm_root_dir)
|
|| e.url.starts_with(npm_root_dir)
|
||||||
|| e.url.ends_with("__anonymous__")
|
|| e.url.ends_with("__anonymous__")
|
||||||
|| e.url.ends_with("$deno$test.js")
|
|| e.url.ends_with("$deno$test.js")
|
||||||
|| e.url.ends_with(".snap");
|
|| e.url.ends_with(".snap")
|
||||||
|
|| is_supported_test_path(Path::new(e.url.as_str()));
|
||||||
|
|
||||||
let is_included = include.iter().any(|p| p.is_match(&e.url));
|
let is_included = include.iter().any(|p| p.is_match(&e.url));
|
||||||
let is_excluded = exclude.iter().any(|p| p.is_match(&e.url));
|
let is_excluded = exclude.iter().any(|p| p.is_match(&e.url));
|
||||||
|
|
|
@ -1518,7 +1518,7 @@ async fn test_specifiers(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if the path has a basename and extension Deno supports for tests.
|
/// Checks if the path has a basename and extension Deno supports for tests.
|
||||||
fn is_supported_test_path(path: &Path) -> bool {
|
pub(crate) fn is_supported_test_path(path: &Path) -> bool {
|
||||||
if let Some(name) = path.file_stem() {
|
if let Some(name) = path.file_stem() {
|
||||||
let basename = name.to_string_lossy();
|
let basename = name.to_string_lossy();
|
||||||
(basename.ends_with("_test")
|
(basename.ends_with("_test")
|
||||||
|
|
Loading…
Reference in a new issue