1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00
denoland-deno/tests/testdata/test
Yusuke Tanaka 64e8c36805
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&#xA;    main_test.go:12: error&#xA;--- FAIL: TestMain/child_2 (0.00s)&#xA;</failure>
		</testcase>
		<testcase classname="example/gosumtest" name="TestMain" time="0.000000">
			<failure message="Failed" type="">=== RUN   TestMain&#xA;--- FAIL: TestMain (0.00s)&#xA;</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-26 00:08:46 +09:00
..
collect chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
doc_only chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
filter chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
glob chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
relative_pattern_dot_slash chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
sanitizer perf(cli): use new deno_core timers (#22569) 2024-03-01 11:15:18 -07:00
shuffle chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
steps chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
aggregate_error.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
aggregate_error.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
allow_all.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
allow_all.ts chore: move test_util/std to tests/util/std (#22402) 2024-02-13 09:22:49 -07:00
allow_none.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
allow_none.ts chore: move test_util/std to tests/util/std (#22402) 2024-02-13 09:22:49 -07:00
before_unload_prevent_default.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
before_unload_prevent_default.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
captured_output.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
captured_output.worker.js chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
check_local_by_default.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
check_local_by_default.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
check_local_by_default2.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
check_local_by_default2.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
clear_timeout.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
clear_timeout.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
collect.deprecated.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
collect.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
collect2.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
collect_with_malformed_config.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
deno.glob.json chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
deno_custom_jsx.json chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
doc.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
doc.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
doc_only.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
fail.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
fail.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
fail_fast.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
fail_fast.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
fail_fast_other.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
fail_fast_with_val.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
fail_fast_with_val.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
file_protocol.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
file_protocol.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
filter.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
filtered_out_only.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
filtered_out_only.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
finally_timeout.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
finally_timeout.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
hello_world.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
hello_world.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
hide_empty_suites.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
ignore.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
ignore.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
ignore_permissions.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
ignore_permissions.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
interval.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
interval.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
junit_multiple_test_files.junit.out fix(cli): output more detailed information for steps when using JUnit reporter (#22797) 2024-03-26 00:08:46 +09:00
load_unload.out fix(cli): ensure that pre- and post-test output is flushed at the appropriate times (#22611) 2024-02-28 22:12:21 +00:00
load_unload.ts fix(cli): ensure that pre- and post-test output is flushed at the appropriate times (#22611) 2024-02-28 22:12:21 +00:00
markdown.md chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
markdown.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
markdown_full_block_names.md chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
markdown_full_block_names.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
markdown_windows.md chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
markdown_windows.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
markdown_with_comment.md chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
markdown_with_comment.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
meta.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
meta.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
nested_failures.junit.out fix(cli): output more detailed information for steps when using JUnit reporter (#22797) 2024-03-26 00:08:46 +09:00
nested_failures.ts fix(cli): output more detailed information for steps when using JUnit reporter (#22797) 2024-03-26 00:08:46 +09:00
no_check.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
no_check.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
no_color.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
no_prompt_by_default.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
no_prompt_by_default.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
no_prompt_with_denied_perms.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
no_prompt_with_denied_perms.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
no_run.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
no_run.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
non_error_thrown.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
non_error_thrown.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
only.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
only.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
overloads.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
overloads.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
parallel_output.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
parallel_output.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
pass.junit.out fix(cli): output more detailed information for steps when using JUnit reporter (#22797) 2024-03-26 00:08:46 +09:00
pass.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
pass.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
quiet.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
quiet.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
recursive_permissions_pledge.js chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
replace_timers.js chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
replace_timers.js.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
report_error.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
report_error.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
short-pass-jobs-flag-warning.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
short-pass.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
short-pass.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
shuffle.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
sigint_with_hanging_test.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
sigint_with_hanging_test.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
text.md chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
text.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
uncaught_errors.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
uncaught_errors_1.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
uncaught_errors_2.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
uncaught_errors_3.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
unhandled_rejection.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
unhandled_rejection.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
unresolved_promise.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
unresolved_promise.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00