2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2024-03-07 20:16:32 -05:00
|
|
|
use deno_core::serde_json::json;
|
2023-01-12 20:59:13 -05:00
|
|
|
use deno_core::url::Url;
|
|
|
|
use test_util as util;
|
2024-02-12 19:13:14 -05:00
|
|
|
use test_util::itest;
|
2023-03-13 09:40:46 -04:00
|
|
|
use util::assert_contains;
|
2023-06-06 17:07:46 -04:00
|
|
|
use util::assert_not_contains;
|
2024-08-30 13:58:58 -04:00
|
|
|
// use util::env_vars_for_npm_tests;
|
2023-03-25 15:32:11 -04:00
|
|
|
use util::wildcard_match;
|
2023-02-27 15:52:49 -05:00
|
|
|
use util::TestContext;
|
2023-05-22 21:39:59 -04:00
|
|
|
use util::TestContextBuilder;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_color() {
|
|
|
|
let (out, _) = util::run_and_collect_output(
|
|
|
|
false,
|
|
|
|
"test test/no_color.ts",
|
|
|
|
None,
|
|
|
|
Some(vec![("NO_COLOR".to_owned(), "true".to_owned())]),
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
// ANSI escape codes should be stripped.
|
|
|
|
assert!(out.contains("success ... ok"));
|
|
|
|
assert!(out.contains("fail ... FAILED"));
|
|
|
|
assert!(out.contains("ignored ... ignored"));
|
|
|
|
assert!(out.contains("FAILED | 1 passed | 1 failed | 1 ignored"));
|
|
|
|
}
|
|
|
|
|
|
|
|
itest!(overloads {
|
|
|
|
args: "test test/overloads.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/overloads.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(meta {
|
|
|
|
args: "test test/meta.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/meta.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
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",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(ignore_permissions {
|
2024-01-23 09:33:07 -05:00
|
|
|
args: "test test/ignore_permissions.ts",
|
2023-01-12 20:59:13 -05:00
|
|
|
exit_code: 0,
|
|
|
|
output: "test/ignore_permissions.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(fail {
|
|
|
|
args: "test test/fail.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/fail.out",
|
|
|
|
});
|
|
|
|
|
2024-05-28 09:34:57 -04:00
|
|
|
// GHA CI seems to have a problem with Emoji
|
|
|
|
// https://github.com/denoland/deno/pull/23200#issuecomment-2134032695
|
|
|
|
#[test]
|
|
|
|
fn fail_with_contain_unicode_filename() {
|
|
|
|
let context = TestContextBuilder::new().use_temp_cwd().build();
|
|
|
|
let temp_dir = context.temp_dir();
|
|
|
|
temp_dir.write(
|
|
|
|
"fail_with_contain_unicode_filename🦕.ts",
|
|
|
|
"Deno.test(\"test 0\", () => {
|
|
|
|
throw new Error();
|
|
|
|
});
|
|
|
|
",
|
|
|
|
);
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args("test fail_with_contain_unicode_filename🦕.ts")
|
|
|
|
.run();
|
|
|
|
output.skip_output_check();
|
|
|
|
output.assert_exit_code(1);
|
|
|
|
output.assert_matches_text(
|
|
|
|
"Check [WILDCARD]/fail_with_contain_unicode_filename🦕.ts
|
|
|
|
running 1 test from ./fail_with_contain_unicode_filename🦕.ts
|
|
|
|
test 0 ... FAILED ([WILDCARD])
|
|
|
|
|
|
|
|
ERRORS
|
|
|
|
|
|
|
|
test 0 => ./fail_with_contain_unicode_filename🦕.ts:[WILDCARD]
|
|
|
|
error: Error
|
|
|
|
throw new Error();
|
|
|
|
^
|
2024-07-24 21:36:34 -04:00
|
|
|
at [WILDCARD]/fail_with_contain_unicode_filename🦕.ts:[WILDCARD]
|
2024-05-28 09:34:57 -04:00
|
|
|
|
|
|
|
FAILURES
|
|
|
|
|
|
|
|
test 0 => ./fail_with_contain_unicode_filename🦕.ts:[WILDCARD]
|
|
|
|
|
|
|
|
FAILED | 0 passed | 1 failed ([WILDCARD])
|
|
|
|
|
|
|
|
error: Test failed
|
|
|
|
",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
itest!(collect {
|
|
|
|
args: "test --ignore=test/collect/ignore test/collect",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/collect.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(test_with_config {
|
|
|
|
args: "test --config test/collect/deno.jsonc test/collect",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/collect.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(test_with_config2 {
|
|
|
|
args: "test --config test/collect/deno2.jsonc test/collect",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/collect2.out",
|
|
|
|
});
|
|
|
|
|
2023-04-26 23:02:36 -04:00
|
|
|
itest!(test_with_deprecated_config {
|
|
|
|
args: "test --config test/collect/deno.deprecated.jsonc test/collect",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/collect.deprecated.out",
|
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
itest!(test_with_malformed_config {
|
|
|
|
args: "test --config test/collect/deno.malformed.jsonc",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/collect_with_malformed_config.out",
|
|
|
|
});
|
|
|
|
|
2023-09-06 12:07:37 -04:00
|
|
|
itest!(test_filtered_out_only {
|
|
|
|
args: "test --quiet --filter foo test/filtered_out_only.ts",
|
|
|
|
output: "test/filtered_out_only.out",
|
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
itest!(parallel_flag {
|
|
|
|
args: "test test/short-pass.ts --parallel",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/short-pass.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(parallel_flag_with_env_variable {
|
|
|
|
args: "test test/short-pass.ts --parallel",
|
|
|
|
envs: vec![("DENO_JOBS".to_owned(), "2".to_owned())],
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/short-pass.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(load_unload {
|
|
|
|
args: "test test/load_unload.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/load_unload.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(interval {
|
|
|
|
args: "test test/interval.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/interval.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(doc {
|
|
|
|
args: "test --doc --allow-all test/doc.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/doc.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(doc_only {
|
|
|
|
args: "test --doc --allow-all test/doc_only",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/doc_only.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(markdown {
|
|
|
|
args: "test --doc --allow-all test/markdown.md",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/markdown.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(markdown_windows {
|
|
|
|
args: "test --doc --allow-all test/markdown_windows.md",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/markdown_windows.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
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",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(markdown_ignore_html_comment {
|
|
|
|
args: "test --doc --allow-all test/markdown_with_comment.md",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/markdown_with_comment.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(text {
|
|
|
|
args: "test --doc --allow-all test/text.md",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/text.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(quiet {
|
|
|
|
args: "test --quiet test/quiet.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/quiet.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(fail_fast {
|
2023-09-15 11:46:48 -04:00
|
|
|
args: "test --fail-fast test/fail_fast.ts test/fail_fast_other.ts",
|
2023-01-12 20:59:13 -05:00
|
|
|
exit_code: 1,
|
|
|
|
output: "test/fail_fast.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(only {
|
|
|
|
args: "test test/only.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/only.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(no_check {
|
|
|
|
args: "test --no-check test/no_check.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/no_check.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(no_run {
|
2024-01-23 09:33:07 -05:00
|
|
|
args: "test --no-run test/no_run.ts",
|
2023-01-12 20:59:13 -05:00
|
|
|
output: "test/no_run.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(allow_all {
|
2024-07-24 20:26:54 -04:00
|
|
|
args: "test --config ../config/deno.json --allow-all test/allow_all.ts",
|
2023-01-12 20:59:13 -05:00
|
|
|
exit_code: 0,
|
|
|
|
output: "test/allow_all.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(allow_none {
|
2024-07-24 20:26:54 -04:00
|
|
|
args: "test --config ../config/deno.json test/allow_none.ts",
|
2023-01-12 20:59:13 -05:00
|
|
|
exit_code: 1,
|
|
|
|
output: "test/allow_none.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(ops_sanitizer_unstable {
|
2024-02-16 12:49:42 -05:00
|
|
|
args: "test --trace-ops test/sanitizer/ops_sanitizer_unstable.ts",
|
2023-01-12 20:59:13 -05:00
|
|
|
exit_code: 1,
|
2024-02-16 12:49:42 -05:00
|
|
|
output: "test/sanitizer/ops_sanitizer_unstable.out",
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(ops_sanitizer_timeout_failure {
|
2024-02-16 12:49:42 -05:00
|
|
|
args: "test test/sanitizer/ops_sanitizer_timeout_failure.ts",
|
|
|
|
output: "test/sanitizer/ops_sanitizer_timeout_failure.out",
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(ops_sanitizer_multiple_timeout_tests {
|
2024-02-16 12:49:42 -05:00
|
|
|
args:
|
2024-02-28 11:12:43 -05:00
|
|
|
"test --trace-leaks test/sanitizer/ops_sanitizer_multiple_timeout_tests.ts",
|
2023-01-12 20:59:13 -05:00
|
|
|
exit_code: 1,
|
2024-02-16 12:49:42 -05:00
|
|
|
output: "test/sanitizer/ops_sanitizer_multiple_timeout_tests.out",
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(ops_sanitizer_multiple_timeout_tests_no_trace {
|
2024-02-16 12:49:42 -05:00
|
|
|
args: "test test/sanitizer/ops_sanitizer_multiple_timeout_tests.ts",
|
2023-01-12 20:59:13 -05:00
|
|
|
exit_code: 1,
|
2024-02-16 12:49:42 -05:00
|
|
|
output: "test/sanitizer/ops_sanitizer_multiple_timeout_tests_no_trace.out",
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
|
2024-02-16 12:49:42 -05:00
|
|
|
itest!(sanitizer_trace_ops_catch_error {
|
2024-02-28 11:12:43 -05:00
|
|
|
args: "test -A --trace-leaks test/sanitizer/trace_ops_caught_error/main.ts",
|
2023-01-12 20:59:13 -05:00
|
|
|
exit_code: 0,
|
2024-02-16 12:49:42 -05:00
|
|
|
output: "test/sanitizer/trace_ops_caught_error/main.out",
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
|
2023-09-14 10:38:15 -04:00
|
|
|
itest!(ops_sanitizer_closed_inside_started_before {
|
2024-02-28 11:12:43 -05:00
|
|
|
args: "test --trace-leaks test/sanitizer/ops_sanitizer_closed_inside_started_before.ts",
|
2023-09-14 10:38:15 -04:00
|
|
|
exit_code: 1,
|
2024-02-16 12:49:42 -05:00
|
|
|
output: "test/sanitizer/ops_sanitizer_closed_inside_started_before.out",
|
2023-09-14 10:38:15 -04:00
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
itest!(ops_sanitizer_nexttick {
|
2024-02-16 12:49:42 -05:00
|
|
|
args: "test --no-check test/sanitizer/ops_sanitizer_nexttick.ts",
|
|
|
|
output: "test/sanitizer/ops_sanitizer_nexttick.out",
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(resource_sanitizer {
|
2024-02-16 12:49:42 -05:00
|
|
|
args: "test --allow-read test/sanitizer/resource_sanitizer.ts",
|
2023-01-12 20:59:13 -05:00
|
|
|
exit_code: 1,
|
2024-02-16 12:49:42 -05:00
|
|
|
output: "test/sanitizer/resource_sanitizer.out",
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
|
2024-03-01 13:15:18 -05:00
|
|
|
itest!(ops_sanitizer_tcp {
|
|
|
|
args: "test --allow-net --trace-leaks test/sanitizer/ops_sanitizer_tcp.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/sanitizer/ops_sanitizer_tcp.out",
|
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
itest!(exit_sanitizer {
|
2024-02-16 12:49:42 -05:00
|
|
|
args: "test test/sanitizer/exit_sanitizer.ts",
|
|
|
|
output: "test/sanitizer/exit_sanitizer.out",
|
2023-01-12 20:59:13 -05:00
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
2023-08-17 17:41:29 -04:00
|
|
|
itest!(junit {
|
|
|
|
args: "test --reporter junit test/pass.ts",
|
|
|
|
output: "test/pass.junit.out",
|
|
|
|
});
|
|
|
|
|
fix(cli): output more detailed information for steps when using JUnit reporter (#22797)
This patch gets JUnit reporter to output more detailed information for
test steps (subtests).
## Issue with previous implementation
In the previous implementation, the test hierarchy was represented using
several XML tags like the following:
- `<testsuites>` corresponds to the entire test (one execution of `deno
test` has exactly one `<testsuites>` tag)
- `<testsuite>` corresponds to one file, such as `main_test.ts`
- `<testcase>` corresponds to one `Deno.test(...)`
- `<property>` corresponds to one `t.step(...)`
This structure describes the test layers but one problem is that
`<property>` tag is used for any use cases so some tools that can ingest
a JUnit XML file might not be able to interpret `<property>` as
subtests.
## How other tools address it
Some of the testing frameworks in the ecosystem address this issue by
fitting subtests into the `<testcase>` layer. For instance, take a look
at the following Go test file:
```go
package main_test
import "testing"
func TestMain(t *testing.T) {
t.Run("child 1", func(t *testing.T) {
// OK
})
t.Run("child 2", func(t *testing.T) {
// Error
t.Fatal("error")
})
}
```
Running [gotestsum], we can get the output like this:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="3" failures="2" errors="0" time="1.013694">
<testsuite tests="3" failures="2" time="0.510000" name="example/gosumtest" timestamp="2024-03-11T12:26:39+09:00">
<properties>
<property name="go.version" value="go1.22.1 darwin/arm64"></property>
</properties>
<testcase classname="example/gosumtest" name="TestMain/child_2" time="0.000000">
<failure message="Failed" type="">=== RUN TestMain/child_2
 main_test.go:12: error
--- FAIL: TestMain/child_2 (0.00s)
</failure>
</testcase>
<testcase classname="example/gosumtest" name="TestMain" time="0.000000">
<failure message="Failed" type="">=== RUN TestMain
--- FAIL: TestMain (0.00s)
</failure>
</testcase>
<testcase classname="example/gosumtest" name="TestMain/child_1" time="0.000000"></testcase>
</testsuite>
</testsuites>
```
This output shows that nested test cases are squashed into the
`<testcase>` layer by treating them as the same layer as their parent,
`TestMain`. We can still distinguish nested ones by their `name`
attributes that look like `TestMain/<subtest_name>`.
As described in #22795, [vitest] solves the issue in the same way as
[gotestsum].
One downside of this would be that one test failure that happens in a
nested test case will end up being counted multiple times, because not
only the subtest but also its wrapping container(s) are considered to be
failures. In fact, in the [gotestsum] output above, `TestMain/child_2`
failed (which is totally expected) while its parent, `TestMain`, was
also counted as failure. As
https://github.com/denoland/deno/pull/20273#discussion_r1307558757
pointed out, there is a test runner that offers flexibility to prevent
this, but I personally don't think the "duplicate failure count" issue
is a big deal.
## How to fix the issue in this patch
This patch fixes the issue with the same approach as [gotestsum] and
[vitest].
More specifically, nested test cases are put into the `<testcase>` level
and their names are now represented as squashed test names concatenated
by `>` (e.g. `parent 2 > child 1 > grandchild 1`). This change also
allows us to put a detailed error message as `<failure>` tag within the
`<testcase>` tag, which should be handled nicely by third-party tools
supporting JUnit XML.
## Extra fix
Also, file paths embedded into XML outputs are changed from absolute
path to relative path, which is helpful when running the test suites in
several different environments like CI.
Resolves #22795
[gotestsum]: https://github.com/gotestyourself/gotestsum
[vitest]: https://vitest.dev/
---------
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-03-25 11:08:46 -04:00
|
|
|
itest!(junit_nested {
|
|
|
|
args: "test --reporter junit test/nested_failures.ts",
|
|
|
|
output: "test/nested_failures.junit.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(junit_multiple_test_files {
|
|
|
|
args: "test --reporter junit test/pass.ts test/fail.ts",
|
|
|
|
output: "test/junit_multiple_test_files.junit.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
2023-11-01 15:59:51 -04:00
|
|
|
#[test]
|
|
|
|
fn junit_path() {
|
|
|
|
let context = TestContextBuilder::new().use_temp_cwd().build();
|
|
|
|
let temp_dir = context.temp_dir();
|
|
|
|
temp_dir.write("test.js", "Deno.test('does test', () => {});");
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args("test --junit-path=sub_dir/output.xml test.js")
|
|
|
|
.run();
|
|
|
|
output.skip_output_check();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
temp_dir
|
|
|
|
.path()
|
|
|
|
.join("sub_dir/output.xml")
|
|
|
|
.assert_matches_text("<?xml [WILDCARD]");
|
|
|
|
}
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
itest!(clear_timeout {
|
|
|
|
args: "test test/clear_timeout.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/clear_timeout.out",
|
|
|
|
});
|
|
|
|
|
2023-09-06 08:54:21 -04:00
|
|
|
itest!(hide_empty_suites {
|
|
|
|
args: "test --filter none test/pass.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/hide_empty_suites.out",
|
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
itest!(finally_timeout {
|
|
|
|
args: "test test/finally_timeout.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/finally_timeout.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(unresolved_promise {
|
|
|
|
args: "test test/unresolved_promise.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/unresolved_promise.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(unhandled_rejection {
|
|
|
|
args: "test test/unhandled_rejection.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/unhandled_rejection.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(filter {
|
|
|
|
args: "test --filter=foo test/filter",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/filter.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
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",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(aggregate_error {
|
|
|
|
args: "test --quiet test/aggregate_error.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/aggregate_error.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(steps_passing_steps {
|
|
|
|
args: "test test/steps/passing_steps.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/steps/passing_steps.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(steps_failing_steps {
|
|
|
|
args: "test test/steps/failing_steps.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/steps/failing_steps.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(steps_ignored_steps {
|
|
|
|
args: "test test/steps/ignored_steps.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/steps/ignored_steps.out",
|
|
|
|
});
|
|
|
|
|
2023-08-02 12:38:10 -04:00
|
|
|
itest!(steps_dot_passing_steps {
|
2023-08-02 22:05:34 -04:00
|
|
|
args: "test --reporter=dot test/steps/passing_steps.ts",
|
2023-08-02 12:38:10 -04:00
|
|
|
exit_code: 0,
|
|
|
|
output: "test/steps/passing_steps.dot.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(steps_dot_failing_steps {
|
2023-08-02 22:05:34 -04:00
|
|
|
args: "test --reporter=dot test/steps/failing_steps.ts",
|
2023-08-02 12:38:10 -04:00
|
|
|
exit_code: 1,
|
|
|
|
output: "test/steps/failing_steps.dot.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(steps_dot_ignored_steps {
|
2023-08-02 22:05:34 -04:00
|
|
|
args: "test --reporter=dot test/steps/ignored_steps.ts",
|
2023-08-02 12:38:10 -04:00
|
|
|
exit_code: 0,
|
|
|
|
output: "test/steps/ignored_steps.dot.out",
|
|
|
|
});
|
|
|
|
|
2023-08-25 19:19:23 -04:00
|
|
|
itest!(steps_tap_passing_steps {
|
|
|
|
args: "test --reporter=tap test/steps/passing_steps.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/steps/passing_steps.tap.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(steps_tap_failing_steps {
|
|
|
|
args: "test --reporter=tap test/steps/failing_steps.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
envs: vec![("NO_COLOR".to_owned(), "1".to_owned())],
|
|
|
|
output: "test/steps/failing_steps.tap.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(steps_tap_ignored_steps {
|
|
|
|
args: "test --reporter=tap test/steps/ignored_steps.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/steps/ignored_steps.tap.out",
|
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
itest!(steps_invalid_usage {
|
|
|
|
args: "test test/steps/invalid_usage.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/steps/invalid_usage.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(steps_output_within {
|
|
|
|
args: "test test/steps/output_within.ts",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/steps/output_within.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(no_prompt_by_default {
|
|
|
|
args: "test --quiet test/no_prompt_by_default.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/no_prompt_by_default.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(no_prompt_with_denied_perms {
|
|
|
|
args: "test --quiet --allow-read test/no_prompt_with_denied_perms.ts",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "test/no_prompt_with_denied_perms.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(test_with_custom_jsx {
|
|
|
|
args: "test --quiet --allow-read test/hello_world.ts --config=test/deno_custom_jsx.json",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "test/hello_world.out",
|
|
|
|
});
|
|
|
|
|
2023-05-03 17:10:51 -04:00
|
|
|
itest!(before_unload_prevent_default {
|
|
|
|
args: "test --quiet test/before_unload_prevent_default.ts",
|
|
|
|
output: "test/before_unload_prevent_default.out",
|
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
#[test]
|
|
|
|
fn captured_output() {
|
2023-03-13 09:40:46 -04:00
|
|
|
let context = TestContext::default();
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
2024-01-23 09:33:07 -05:00
|
|
|
.args("test --allow-run --allow-read test/captured_output.ts")
|
2023-01-12 20:59:13 -05:00
|
|
|
.env("NO_COLOR", "1")
|
2023-03-13 09:40:46 -04:00
|
|
|
.run();
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let output_start = "------- output -------";
|
|
|
|
let output_end = "----- output end -----";
|
2023-03-13 09:40:46 -04:00
|
|
|
output.assert_exit_code(0);
|
|
|
|
let output_text = output.combined_output();
|
2023-01-12 20:59:13 -05:00
|
|
|
let start = output_text.find(output_start).unwrap() + output_start.len();
|
|
|
|
let end = output_text.find(output_end).unwrap();
|
|
|
|
// replace zero width space that may appear in test output due
|
|
|
|
// to test runner output flusher
|
|
|
|
let output_text = output_text[start..end]
|
|
|
|
.replace('\u{200B}', "")
|
|
|
|
.trim()
|
|
|
|
.to_string();
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn recursive_permissions_pledge() {
|
2023-03-13 09:40:46 -04:00
|
|
|
let context = TestContext::default();
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
2023-04-27 18:37:03 -04:00
|
|
|
.args("test test/recursive_permissions_pledge.js")
|
2023-03-13 09:40:46 -04:00
|
|
|
.run();
|
|
|
|
output.assert_exit_code(1);
|
|
|
|
assert_contains!(
|
|
|
|
output.combined_output(),
|
2023-01-12 20:59:13 -05:00
|
|
|
"pledge test permissions called before restoring previous pledge"
|
2023-03-13 09:40:46 -04:00
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn file_protocol() {
|
|
|
|
let file_url =
|
|
|
|
Url::from_file_path(util::testdata_path().join("test/file_protocol.ts"))
|
|
|
|
.unwrap()
|
|
|
|
.to_string();
|
|
|
|
|
2023-03-30 17:47:53 -04:00
|
|
|
TestContext::default()
|
2023-02-28 14:10:12 -05:00
|
|
|
.new_command()
|
2023-03-30 17:47:53 -04:00
|
|
|
.args_vec(["test", file_url.as_str()])
|
2023-02-28 14:10:12 -05:00
|
|
|
.run()
|
|
|
|
.assert_matches_file("test/file_protocol.out");
|
2023-01-12 20:59:13 -05: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,
|
|
|
|
});
|
|
|
|
|
2023-04-27 08:40:03 -04:00
|
|
|
itest!(report_error {
|
|
|
|
args: "test --quiet test/report_error.ts",
|
|
|
|
output: "test/report_error.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
2023-01-12 20:59:13 -05: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,
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(non_error_thrown {
|
|
|
|
args: "test --quiet test/non_error_thrown.ts",
|
|
|
|
output: "test/non_error_thrown.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(parallel_output {
|
|
|
|
args: "test --parallel --reload test/parallel_output.ts",
|
|
|
|
output: "test/parallel_output.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
2023-02-23 10:58:10 -05:00
|
|
|
|
2023-03-25 15:32:11 -04:00
|
|
|
#[test]
|
2023-03-28 17:49:00 -04:00
|
|
|
// todo(#18480): re-enable
|
|
|
|
#[ignore]
|
2023-03-25 15:32:11 -04:00
|
|
|
fn sigint_with_hanging_test() {
|
|
|
|
util::with_pty(
|
|
|
|
&[
|
|
|
|
"test",
|
|
|
|
"--quiet",
|
|
|
|
"--no-check",
|
|
|
|
"test/sigint_with_hanging_test.ts",
|
|
|
|
],
|
|
|
|
|mut console| {
|
|
|
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
|
|
|
console.write_line("\x03");
|
2023-03-28 17:49:00 -04:00
|
|
|
let text = console.read_until("hanging_test.ts:10:15");
|
2023-03-25 15:32:11 -04:00
|
|
|
wildcard_match(
|
|
|
|
include_str!("../testdata/test/sigint_with_hanging_test.out"),
|
2023-03-28 17:49:00 -04:00
|
|
|
&text,
|
2023-03-25 15:32:11 -04:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-30 13:58:58 -04:00
|
|
|
// TODO(2.0): this should be rewritten to a spec test and first run `deno install`
|
|
|
|
// itest!(package_json_basic {
|
|
|
|
// args: "test",
|
|
|
|
// output: "package_json/basic/lib.test.out",
|
|
|
|
// envs: env_vars_for_npm_tests(),
|
|
|
|
// http_server: true,
|
|
|
|
// cwd: Some("package_json/basic"),
|
|
|
|
// copy_temp_dir: Some("package_json/basic"),
|
|
|
|
// exit_code: 0,
|
|
|
|
// });
|
2023-03-13 17:04:00 -04:00
|
|
|
|
2023-08-04 09:29:04 -04:00
|
|
|
itest!(test_replace_timers {
|
|
|
|
args: "test test/replace_timers.js",
|
|
|
|
output: "test/replace_timers.js.out",
|
|
|
|
});
|
|
|
|
|
2023-05-22 21:39:59 -04:00
|
|
|
#[test]
|
|
|
|
fn test_with_glob_config() {
|
|
|
|
let context = TestContextBuilder::new().cwd("test").build();
|
|
|
|
|
|
|
|
let cmd_output = context
|
|
|
|
.new_command()
|
|
|
|
.args("test --config deno.glob.json")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
cmd_output.assert_exit_code(0);
|
|
|
|
|
|
|
|
let output = cmd_output.combined_output();
|
|
|
|
assert_contains!(output, "glob/nested/fizz/fizz.ts");
|
|
|
|
assert_contains!(output, "glob/pages/[id].ts");
|
|
|
|
assert_contains!(output, "glob/nested/fizz/bar.ts");
|
|
|
|
assert_contains!(output, "glob/nested/foo/foo.ts");
|
|
|
|
assert_contains!(output, "glob/data/test1.js");
|
|
|
|
assert_contains!(output, "glob/nested/foo/bar.ts");
|
|
|
|
assert_contains!(output, "glob/nested/foo/fizz.ts");
|
|
|
|
assert_contains!(output, "glob/nested/fizz/foo.ts");
|
|
|
|
assert_contains!(output, "glob/data/test1.ts");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_with_glob_config_and_flags() {
|
|
|
|
let context = TestContextBuilder::new().cwd("test").build();
|
|
|
|
|
|
|
|
let cmd_output = context
|
|
|
|
.new_command()
|
|
|
|
.args("test --config deno.glob.json --ignore=glob/nested/**/bar.ts")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
cmd_output.assert_exit_code(0);
|
|
|
|
|
|
|
|
let output = cmd_output.combined_output();
|
|
|
|
assert_contains!(output, "glob/nested/fizz/fizz.ts");
|
|
|
|
assert_contains!(output, "glob/pages/[id].ts");
|
|
|
|
assert_contains!(output, "glob/nested/fizz/bazz.ts");
|
|
|
|
assert_contains!(output, "glob/nested/foo/foo.ts");
|
|
|
|
assert_contains!(output, "glob/data/test1.js");
|
|
|
|
assert_contains!(output, "glob/nested/foo/bazz.ts");
|
|
|
|
assert_contains!(output, "glob/nested/foo/fizz.ts");
|
|
|
|
assert_contains!(output, "glob/nested/fizz/foo.ts");
|
|
|
|
assert_contains!(output, "glob/data/test1.ts");
|
|
|
|
|
|
|
|
let cmd_output = context
|
|
|
|
.new_command()
|
|
|
|
.args("test --config deno.glob.json glob/data/test1.?s")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
cmd_output.assert_exit_code(0);
|
|
|
|
|
|
|
|
let output = cmd_output.combined_output();
|
|
|
|
assert_contains!(output, "glob/data/test1.js");
|
|
|
|
assert_contains!(output, "glob/data/test1.ts");
|
|
|
|
}
|
2023-06-06 17:07:46 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn conditionally_loads_type_graph() {
|
|
|
|
let context = TestContext::default();
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args("test --reload -L debug run/type_directives_js_main.js")
|
|
|
|
.run();
|
2024-04-18 21:43:28 -04:00
|
|
|
output.assert_matches_text("[WILDCARD] - FileFetcher::fetch_no_follow_with_options - specifier: file:///[WILDCARD]/subdir/type_reference.d.ts[WILDCARD]");
|
2023-06-06 17:07:46 -04:00
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args("test --reload -L debug --no-check run/type_directives_js_main.js")
|
|
|
|
.run();
|
|
|
|
assert_not_contains!(output.combined_output(), "type_reference.d.ts");
|
|
|
|
}
|
2024-01-13 10:39:22 -05:00
|
|
|
|
2024-03-07 20:16:32 -05:00
|
|
|
#[test]
|
|
|
|
fn opt_out_top_level_exclude_via_test_unexclude() {
|
|
|
|
let context = TestContextBuilder::new().use_temp_cwd().build();
|
|
|
|
let temp_dir = context.temp_dir().path();
|
|
|
|
temp_dir.join("deno.json").write_json(&json!({
|
|
|
|
"test": {
|
|
|
|
"exclude": [ "!excluded.test.ts" ]
|
|
|
|
},
|
|
|
|
"exclude": [ "excluded.test.ts", "actually_excluded.test.ts" ]
|
|
|
|
}));
|
|
|
|
|
|
|
|
temp_dir
|
|
|
|
.join("main.test.ts")
|
|
|
|
.write("Deno.test('test1', () => {});");
|
|
|
|
temp_dir
|
|
|
|
.join("excluded.test.ts")
|
|
|
|
.write("Deno.test('test2', () => {});");
|
|
|
|
temp_dir
|
|
|
|
.join("actually_excluded.test.ts")
|
|
|
|
.write("Deno.test('test3', () => {});");
|
|
|
|
|
|
|
|
let output = context.new_command().arg("test").run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
let output = output.combined_output();
|
|
|
|
assert_contains!(output, "main.test.ts");
|
|
|
|
assert_contains!(output, "excluded.test.ts");
|
|
|
|
assert_not_contains!(output, "actually_excluded.test.ts");
|
|
|
|
}
|