2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-06-27 13:27:36 -04:00
|
|
|
|
|
|
|
use crate::itest;
|
2022-05-02 15:43:03 -04:00
|
|
|
use deno_core::url::Url;
|
2021-06-27 13:27:36 -04:00
|
|
|
use test_util as util;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_color() {
|
|
|
|
let (out, _) = util::run_and_collect_output(
|
|
|
|
false,
|
2021-06-29 09:40:16 -04:00
|
|
|
"test test/no_color.ts",
|
2021-06-27 13:27:36 -04:00
|
|
|
None,
|
|
|
|
Some(vec![("NO_COLOR".to_owned(), "true".to_owned())]),
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
// ANSI escape codes should be stripped.
|
2022-04-11 12:27:17 -04:00
|
|
|
assert!(out.contains("success ... ok"));
|
|
|
|
assert!(out.contains("fail ... FAILED"));
|
|
|
|
assert!(out.contains("ignored ... ignored"));
|
2021-06-27 13:27:36 -04:00
|
|
|
assert!(out.contains("test result: FAILED. 1 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out"));
|
|
|
|
}
|
|
|
|
|
feat(test): Add more overloads for "Deno.test" (#12749)
This commit adds 4 more overloads to "Deno.test()" API.
```
// Deno.test(function testName() { });
export function test(fn: (t: TestContext) => void | Promise<void>): void;
// Deno.test("test name", { only: true }, function() { });
export function test(
name: string,
options: Omit<TestDefinition, "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ name: "test name" }, function() { });
export function test(
options: Omit<TestDefinition, "fn">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ only: true }, function testName() { });
export function test(
options: Omit<TestDefinition, "fn" | "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
```
2021-11-23 08:57:51 -05:00
|
|
|
itest!(overloads {
|
|
|
|
args: "test test/overloads.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/overloads.out",
|
|
|
|
});
|
|
|
|
|
2021-07-26 08:05:44 -04:00
|
|
|
itest!(meta {
|
|
|
|
args: "test test/meta.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/meta.out",
|
|
|
|
});
|
|
|
|
|
2021-06-29 09:40:16 -04:00
|
|
|
itest!(pass {
|
|
|
|
args: "test test/pass.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/pass.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(ignore {
|
|
|
|
args: "test test/ignore.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/ignore.out",
|
|
|
|
});
|
|
|
|
|
2021-07-05 12:36:43 -04:00
|
|
|
itest!(ignore_permissions {
|
|
|
|
args: "test --unstable test/ignore_permissions.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/ignore_permissions.out",
|
|
|
|
});
|
|
|
|
|
2021-06-29 09:40:16 -04:00
|
|
|
itest!(fail {
|
|
|
|
args: "test test/fail.ts",
|
2021-06-27 13:27:36 -04:00
|
|
|
exit_code: 1,
|
2021-06-29 09:40:16 -04:00
|
|
|
output: "test/fail.out",
|
2021-06-27 13:27:36 -04:00
|
|
|
});
|
|
|
|
|
2021-08-24 11:23:29 -04:00
|
|
|
itest!(collect {
|
|
|
|
args: "test --ignore=test/collect/ignore test/collect",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/collect.out",
|
|
|
|
});
|
|
|
|
|
2021-08-15 07:54:44 -04:00
|
|
|
itest!(load_unload {
|
|
|
|
args: "test test/load_unload.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/load_unload.out",
|
|
|
|
});
|
|
|
|
|
2021-09-04 14:19:26 -04:00
|
|
|
itest!(interval {
|
|
|
|
args: "test test/interval.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/interval.out",
|
|
|
|
});
|
|
|
|
|
2021-06-27 13:27:36 -04:00
|
|
|
itest!(doc {
|
|
|
|
args: "test --doc --allow-all test/doc.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/doc.out",
|
|
|
|
});
|
|
|
|
|
2021-09-01 05:31:56 -04:00
|
|
|
itest!(doc_only {
|
|
|
|
args: "test --doc --allow-all test/doc_only",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/doc_only.out",
|
|
|
|
});
|
|
|
|
|
2021-08-12 14:10:14 -04:00
|
|
|
itest!(markdown {
|
|
|
|
args: "test --doc --allow-all test/markdown.md",
|
2021-07-29 15:03:06 -04:00
|
|
|
exit_code: 1,
|
2021-08-12 14:10:14 -04:00
|
|
|
output: "test/markdown.out",
|
|
|
|
});
|
|
|
|
|
2021-11-15 09:58:04 -05:00
|
|
|
itest!(markdown_windows {
|
|
|
|
args: "test --doc --allow-all test/markdown_windows.md",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/markdown_windows.out",
|
|
|
|
});
|
|
|
|
|
2022-03-07 20:10:40 -05:00
|
|
|
itest!(markdown_full_block_names {
|
|
|
|
args: "test --doc --allow-all test/markdown_full_block_names.md",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/markdown_full_block_names.out",
|
|
|
|
});
|
|
|
|
|
2022-03-10 20:14:32 -05:00
|
|
|
itest!(markdown_ignore_html_comment {
|
|
|
|
args: "test --doc --allow-all test/markdown_with_comment.md",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/markdown_with_comment.out",
|
|
|
|
});
|
|
|
|
|
2021-08-12 14:10:14 -04:00
|
|
|
itest!(text {
|
|
|
|
args: "test --doc --allow-all test/text.md",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/text.out",
|
2021-07-29 15:03:06 -04:00
|
|
|
});
|
|
|
|
|
2021-06-29 09:40:16 -04:00
|
|
|
itest!(quiet {
|
|
|
|
args: "test --quiet test/quiet.ts",
|
2021-06-27 13:27:36 -04:00
|
|
|
exit_code: 0,
|
2021-06-29 09:40:16 -04:00
|
|
|
output: "test/quiet.out",
|
2021-06-27 13:27:36 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(fail_fast {
|
2021-06-29 09:40:16 -04:00
|
|
|
args: "test --fail-fast test/fail_fast.ts",
|
2021-06-27 13:27:36 -04:00
|
|
|
exit_code: 1,
|
2021-06-29 09:40:16 -04:00
|
|
|
output: "test/fail_fast.out",
|
2021-06-27 13:27:36 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(only {
|
2021-06-29 09:40:16 -04:00
|
|
|
args: "test test/only.ts",
|
2021-06-27 13:27:36 -04:00
|
|
|
exit_code: 1,
|
2021-06-29 09:40:16 -04:00
|
|
|
output: "test/only.out",
|
2021-06-27 13:27:36 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(no_check {
|
2021-06-29 09:40:16 -04:00
|
|
|
args: "test --no-check test/no_check.ts",
|
2021-06-27 13:27:36 -04:00
|
|
|
exit_code: 1,
|
2021-06-29 09:40:16 -04:00
|
|
|
output: "test/no_check.out",
|
2021-06-27 13:27:36 -04:00
|
|
|
});
|
|
|
|
|
2021-06-29 09:40:16 -04:00
|
|
|
itest!(no_run {
|
|
|
|
args: "test --unstable --no-run test/no_run.ts",
|
|
|
|
output: "test/no_run.out",
|
2021-06-27 13:27:36 -04:00
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
2021-06-29 09:40:16 -04:00
|
|
|
itest!(allow_all {
|
|
|
|
args: "test --unstable --allow-all test/allow_all.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/allow_all.out",
|
2021-06-27 13:27:36 -04:00
|
|
|
});
|
|
|
|
|
2021-06-29 09:40:16 -04:00
|
|
|
itest!(allow_none {
|
|
|
|
args: "test --unstable test/allow_none.ts",
|
2021-06-27 13:27:36 -04:00
|
|
|
exit_code: 1,
|
2021-06-29 09:40:16 -04:00
|
|
|
output: "test/allow_none.out",
|
2021-06-27 13:27:36 -04:00
|
|
|
});
|
|
|
|
|
2021-10-11 11:00:33 -04:00
|
|
|
itest!(ops_sanitizer_unstable {
|
2022-02-25 10:14:46 -05:00
|
|
|
args: "test --unstable --trace-ops test/ops_sanitizer_unstable.ts",
|
2021-10-11 11:00:33 -04:00
|
|
|
exit_code: 1,
|
|
|
|
output: "test/ops_sanitizer_unstable.out",
|
|
|
|
});
|
|
|
|
|
2021-11-29 19:27:30 -05:00
|
|
|
itest!(ops_sanitizer_timeout_failure {
|
|
|
|
args: "test test/ops_sanitizer_timeout_failure.ts",
|
|
|
|
output: "test/ops_sanitizer_timeout_failure.out",
|
|
|
|
});
|
|
|
|
|
2021-12-07 07:39:58 -05:00
|
|
|
itest!(ops_sanitizer_multiple_timeout_tests {
|
2022-02-25 10:14:46 -05:00
|
|
|
args: "test --trace-ops test/ops_sanitizer_multiple_timeout_tests.ts",
|
2021-12-07 07:39:58 -05:00
|
|
|
exit_code: 1,
|
|
|
|
output: "test/ops_sanitizer_multiple_timeout_tests.out",
|
|
|
|
});
|
|
|
|
|
2022-02-25 10:14:46 -05:00
|
|
|
itest!(ops_sanitizer_multiple_timeout_tests_no_trace {
|
|
|
|
args: "test test/ops_sanitizer_multiple_timeout_tests.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/ops_sanitizer_multiple_timeout_tests_no_trace.out",
|
|
|
|
});
|
|
|
|
|
2022-04-19 10:41:31 -04:00
|
|
|
// TODO(@littledivy): re-enable this test, recent optimizations made output non deterministic.
|
|
|
|
// https://github.com/denoland/deno/issues/14268
|
|
|
|
//
|
|
|
|
// itest!(ops_sanitizer_missing_details {
|
|
|
|
// args: "test --allow-write --allow-read test/ops_sanitizer_missing_details.ts",
|
|
|
|
// exit_code: 1,
|
|
|
|
// output: "test/ops_sanitizer_missing_details.out",
|
|
|
|
// });
|
2022-03-22 19:24:45 -04:00
|
|
|
|
2021-11-29 19:27:30 -05:00
|
|
|
itest!(ops_sanitizer_nexttick {
|
|
|
|
args: "test test/ops_sanitizer_nexttick.ts",
|
|
|
|
output: "test/ops_sanitizer_nexttick.out",
|
|
|
|
});
|
|
|
|
|
2022-01-25 11:03:38 -05:00
|
|
|
itest!(resource_sanitizer {
|
|
|
|
args: "test --allow-read test/resource_sanitizer.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/resource_sanitizer.out",
|
|
|
|
});
|
|
|
|
|
2021-06-27 13:27:36 -04:00
|
|
|
itest!(exit_sanitizer {
|
2021-06-29 09:40:16 -04:00
|
|
|
args: "test test/exit_sanitizer.ts",
|
|
|
|
output: "test/exit_sanitizer.out",
|
2021-06-27 13:27:36 -04:00
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
2021-07-14 13:47:47 -04:00
|
|
|
itest!(clear_timeout {
|
|
|
|
args: "test test/clear_timeout.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/clear_timeout.out",
|
|
|
|
});
|
|
|
|
|
2021-06-29 09:40:16 -04:00
|
|
|
itest!(finally_timeout {
|
|
|
|
args: "test test/finally_timeout.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/finally_timeout.out",
|
2021-06-27 13:27:36 -04:00
|
|
|
});
|
|
|
|
|
2021-06-29 09:40:16 -04:00
|
|
|
itest!(unresolved_promise {
|
|
|
|
args: "test test/unresolved_promise.ts",
|
2021-06-27 13:27:36 -04:00
|
|
|
exit_code: 1,
|
2021-06-29 09:40:16 -04:00
|
|
|
output: "test/unresolved_promise.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(unhandled_rejection {
|
|
|
|
args: "test test/unhandled_rejection.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/unhandled_rejection.out",
|
2021-06-27 13:27:36 -04:00
|
|
|
});
|
2021-07-05 21:20:33 -04:00
|
|
|
|
2021-08-13 05:33:18 -04:00
|
|
|
itest!(filter {
|
|
|
|
args: "test --filter=foo test/filter",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/filter.out",
|
|
|
|
});
|
|
|
|
|
2021-07-05 21:20:33 -04:00
|
|
|
itest!(shuffle {
|
|
|
|
args: "test --shuffle test/shuffle",
|
|
|
|
exit_code: 0,
|
|
|
|
output_str: Some("[WILDCARD]"),
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(shuffle_with_seed {
|
|
|
|
args: "test --shuffle=42 test/shuffle",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/shuffle.out",
|
|
|
|
});
|
2021-09-30 15:54:56 -04:00
|
|
|
|
|
|
|
itest!(aggregate_error {
|
2022-04-15 10:08:09 -04:00
|
|
|
args: "test --quiet test/aggregate_error.ts",
|
2021-09-30 15:54:56 -04:00
|
|
|
exit_code: 1,
|
|
|
|
output: "test/aggregate_error.out",
|
|
|
|
});
|
2021-10-11 09:45:02 -04:00
|
|
|
|
|
|
|
itest!(steps_passing_steps {
|
2022-01-18 15:02:56 -05:00
|
|
|
args: "test test/steps/passing_steps.ts",
|
2021-10-11 09:45:02 -04:00
|
|
|
exit_code: 0,
|
|
|
|
output: "test/steps/passing_steps.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(steps_passing_steps_concurrent {
|
2022-01-18 15:02:56 -05:00
|
|
|
args: "test --jobs=2 test/steps/passing_steps.ts",
|
2021-10-11 09:45:02 -04:00
|
|
|
exit_code: 0,
|
|
|
|
output: "test/steps/passing_steps.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(steps_failing_steps {
|
2022-01-18 15:02:56 -05:00
|
|
|
args: "test test/steps/failing_steps.ts",
|
2021-10-11 09:45:02 -04:00
|
|
|
exit_code: 1,
|
|
|
|
output: "test/steps/failing_steps.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(steps_ignored_steps {
|
2022-01-18 15:02:56 -05:00
|
|
|
args: "test test/steps/ignored_steps.ts",
|
2021-10-11 09:45:02 -04:00
|
|
|
exit_code: 0,
|
|
|
|
output: "test/steps/ignored_steps.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(steps_invalid_usage {
|
2022-01-18 15:02:56 -05:00
|
|
|
args: "test test/steps/invalid_usage.ts",
|
2021-10-11 09:45:02 -04:00
|
|
|
exit_code: 1,
|
|
|
|
output: "test/steps/invalid_usage.out",
|
|
|
|
});
|
2022-02-26 08:49:50 -05:00
|
|
|
|
2022-04-15 08:24:41 -04:00
|
|
|
itest!(steps_output_within {
|
|
|
|
args: "test test/steps/output_within.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/steps/output_within.out",
|
|
|
|
});
|
|
|
|
|
2022-02-26 08:49:50 -05:00
|
|
|
itest!(no_prompt_by_default {
|
2022-04-18 15:08:30 -04:00
|
|
|
args: "test --quiet test/no_prompt_by_default.ts",
|
2022-02-26 08:49:50 -05:00
|
|
|
exit_code: 1,
|
|
|
|
output: "test/no_prompt_by_default.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(no_prompt_with_denied_perms {
|
2022-04-18 15:08:30 -04:00
|
|
|
args: "test --quiet --allow-read test/no_prompt_with_denied_perms.ts",
|
2022-02-26 08:49:50 -05:00
|
|
|
exit_code: 1,
|
|
|
|
output: "test/no_prompt_with_denied_perms.out",
|
|
|
|
});
|
2022-04-17 11:47:24 -04:00
|
|
|
|
2022-05-01 14:44:55 -04:00
|
|
|
#[test]
|
|
|
|
fn captured_output() {
|
|
|
|
let output = util::deno_cmd()
|
|
|
|
.current_dir(util::testdata_path())
|
|
|
|
.arg("test")
|
|
|
|
.arg("--allow-run")
|
|
|
|
.arg("--allow-read")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("test/captured_output.ts")
|
|
|
|
.env("NO_COLOR", "1")
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait_with_output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let output_start = "------- output -------";
|
|
|
|
let output_end = "----- output end -----";
|
|
|
|
assert!(output.status.success());
|
|
|
|
let output_text = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let start = output_text.find(output_start).unwrap() + output_start.len();
|
|
|
|
let end = output_text.find(output_end).unwrap();
|
|
|
|
let output_text = output_text[start..end].trim();
|
|
|
|
let mut lines = output_text.lines().collect::<Vec<_>>();
|
|
|
|
// the output is racy on either stdout or stderr being flushed
|
|
|
|
// from the runtime into the rust code, so sort it... the main
|
|
|
|
// thing here to ensure is that we're capturing the output in
|
|
|
|
// this block on stdout
|
|
|
|
lines.sort_unstable();
|
|
|
|
assert_eq!(lines.join(" "), "0 1 2 3 4 5 6 7 8 9");
|
|
|
|
}
|
2022-04-26 14:46:49 -04:00
|
|
|
|
2022-04-17 11:47:24 -04:00
|
|
|
#[test]
|
|
|
|
fn recursive_permissions_pledge() {
|
|
|
|
let output = util::deno_cmd()
|
|
|
|
.current_dir(util::testdata_path())
|
|
|
|
.arg("test")
|
|
|
|
.arg("test/recursive_permissions_pledge.js")
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait_with_output()
|
|
|
|
.unwrap();
|
|
|
|
assert!(!output.status.success());
|
|
|
|
assert!(String::from_utf8(output.stderr).unwrap().contains(
|
|
|
|
"pledge test permissions called before restoring previous pledge"
|
|
|
|
));
|
|
|
|
}
|
2022-05-02 15:43:03 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn file_protocol() {
|
|
|
|
let file_url =
|
|
|
|
Url::from_file_path(util::testdata_path().join("test/file_protocol.ts"))
|
|
|
|
.unwrap()
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
(util::CheckOutputIntegrationTest {
|
|
|
|
args_vec: vec!["test", &file_url],
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/file_protocol.out",
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.run();
|
|
|
|
}
|
2022-05-09 05:44:50 -04:00
|
|
|
|
|
|
|
itest!(uncaught_errors {
|
|
|
|
args: "test --quiet test/uncaught_errors_1.ts test/uncaught_errors_2.ts test/uncaught_errors_3.ts",
|
|
|
|
output: "test/uncaught_errors.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
2022-05-17 17:53:42 -04:00
|
|
|
|
|
|
|
itest!(check_local_by_default {
|
|
|
|
args: "test --quiet test/check_local_by_default.ts",
|
|
|
|
output: "test/check_local_by_default.out",
|
|
|
|
http_server: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(check_local_by_default2 {
|
|
|
|
args: "test --quiet test/check_local_by_default2.ts",
|
|
|
|
output: "test/check_local_by_default2.out",
|
|
|
|
http_server: true,
|
|
|
|
exit_code: 1,
|
|
|
|
});
|