mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 23:34:47 -05:00
64e8c36805
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> |
||
---|---|---|
.. | ||
collect | ||
doc_only | ||
filter | ||
glob | ||
relative_pattern_dot_slash | ||
sanitizer | ||
shuffle | ||
steps | ||
aggregate_error.out | ||
aggregate_error.ts | ||
allow_all.out | ||
allow_all.ts | ||
allow_none.out | ||
allow_none.ts | ||
before_unload_prevent_default.out | ||
before_unload_prevent_default.ts | ||
captured_output.ts | ||
captured_output.worker.js | ||
check_local_by_default.out | ||
check_local_by_default.ts | ||
check_local_by_default2.out | ||
check_local_by_default2.ts | ||
clear_timeout.out | ||
clear_timeout.ts | ||
collect.deprecated.out | ||
collect.out | ||
collect2.out | ||
collect_with_malformed_config.out | ||
deno.glob.json | ||
deno_custom_jsx.json | ||
doc.out | ||
doc.ts | ||
doc_only.out | ||
fail.out | ||
fail.ts | ||
fail_fast.out | ||
fail_fast.ts | ||
fail_fast_other.ts | ||
fail_fast_with_val.out | ||
fail_fast_with_val.ts | ||
file_protocol.out | ||
file_protocol.ts | ||
filter.out | ||
filtered_out_only.out | ||
filtered_out_only.ts | ||
finally_timeout.out | ||
finally_timeout.ts | ||
hello_world.out | ||
hello_world.ts | ||
hide_empty_suites.out | ||
ignore.out | ||
ignore.ts | ||
ignore_permissions.out | ||
ignore_permissions.ts | ||
interval.out | ||
interval.ts | ||
junit_multiple_test_files.junit.out | ||
load_unload.out | ||
load_unload.ts | ||
markdown.md | ||
markdown.out | ||
markdown_full_block_names.md | ||
markdown_full_block_names.out | ||
markdown_windows.md | ||
markdown_windows.out | ||
markdown_with_comment.md | ||
markdown_with_comment.out | ||
meta.out | ||
meta.ts | ||
nested_failures.junit.out | ||
nested_failures.ts | ||
no_check.out | ||
no_check.ts | ||
no_color.ts | ||
no_prompt_by_default.out | ||
no_prompt_by_default.ts | ||
no_prompt_with_denied_perms.out | ||
no_prompt_with_denied_perms.ts | ||
no_run.out | ||
no_run.ts | ||
non_error_thrown.out | ||
non_error_thrown.ts | ||
only.out | ||
only.ts | ||
overloads.out | ||
overloads.ts | ||
parallel_output.out | ||
parallel_output.ts | ||
pass.junit.out | ||
pass.out | ||
pass.ts | ||
quiet.out | ||
quiet.ts | ||
recursive_permissions_pledge.js | ||
replace_timers.js | ||
replace_timers.js.out | ||
report_error.out | ||
report_error.ts | ||
short-pass-jobs-flag-warning.out | ||
short-pass.out | ||
short-pass.ts | ||
shuffle.out | ||
sigint_with_hanging_test.out | ||
sigint_with_hanging_test.ts | ||
text.md | ||
text.out | ||
uncaught_errors.out | ||
uncaught_errors_1.ts | ||
uncaught_errors_2.ts | ||
uncaught_errors_3.ts | ||
unhandled_rejection.out | ||
unhandled_rejection.ts | ||
unresolved_promise.out | ||
unresolved_promise.ts |