Skip to content

Commit 85a845e

Browse files
committed
add tests
1 parent 8bf25e5 commit 85a845e

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

cli/tests/integration/coverage_tests.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ fn no_snaps() {
2626
no_snaps_included("no_snaps_included", "ts");
2727
}
2828

29+
#[test]
30+
fn no_tests() {
31+
no_tests_included("foo", "mts");
32+
no_tests_included("foo", "ts");
33+
no_tests_included("foo", "js");
34+
}
35+
2936
#[test]
3037
fn error_if_invalid_cache() {
3138
let context = TestContextBuilder::new().use_temp_cwd().build();
@@ -277,6 +284,53 @@ fn no_snaps_included(test_name: &str, extension: &str) {
277284
output.assert_exit_code(0);
278285
}
279286

287+
fn no_tests_included(test_name: &str, extension: &str) {
288+
let context = TestContext::default();
289+
let tempdir = context.deno_dir();
290+
let tempdir = tempdir.path().join("cov");
291+
292+
let output = context
293+
.new_command()
294+
.args_vec(vec![
295+
"test".to_string(),
296+
"--quiet".to_string(),
297+
"--allow-read".to_string(),
298+
format!("--coverage={}", tempdir.to_str().unwrap()),
299+
format!("coverage/no_tests_included/{test_name}.test.{extension}"),
300+
])
301+
.run();
302+
303+
output.assert_exit_code(0);
304+
output.skip_output_check();
305+
306+
let output = context
307+
.new_command()
308+
.args_vec(vec![
309+
"coverage".to_string(),
310+
format!("{}/", tempdir.to_str().unwrap()),
311+
])
312+
.split_output()
313+
.run();
314+
315+
// Verify there's no "Check" being printed
316+
assert!(output.stderr().is_empty());
317+
318+
let actual = util::strip_ansi_codes(output.stdout()).to_string();
319+
320+
let expected = fs::read_to_string(
321+
util::testdata_path().join("coverage/no_tests_included/expected.out"),
322+
)
323+
.unwrap();
324+
325+
if !util::wildcard_match(&expected, &actual) {
326+
println!("OUTPUT\n{actual}\nOUTPUT");
327+
println!("EXPECTED\n{expected}\nEXPECTED");
328+
panic!("pattern match failed");
329+
}
330+
331+
output.assert_exit_code(0);
332+
}
333+
280334
#[test]
281335
fn no_npm_cache_coverage() {
282336
let context = TestContext::default();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cover [WILDCARD]/no_tests_included/foo.ts ... 100.000% (3/3)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { add_numbers } from './foo.ts';
2+
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
3+
4+
Deno.test("add_numbers works", () => {
5+
assertEquals(add_numbers(1, 2), 3);
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { add_numbers } from './foo.ts';
2+
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
3+
4+
Deno.test("add_numbers works", () => {
5+
assertEquals(add_numbers(1, 2), 3);
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { add_numbers } from './foo.ts';
2+
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
3+
4+
Deno.test("add_numbers works", () => {
5+
assertEquals(add_numbers(1, 2), 3);
6+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function add_numbers(a: number, b: number): number {
2+
return a + b;
3+
}

0 commit comments

Comments
 (0)