1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00
denoland-deno/tests/testdata
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
..
assets chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
bench chore: move test_util/std to tests/util/std (#22402) 2024-02-13 09:22:49 -07:00
benches chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
bundle chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
cache chore: rough first pass on spec tests (#22877) 2024-03-13 16:21:13 +00:00
cert chore: move test_util/std to tests/util/std (#22402) 2024-02-13 09:22:49 -07:00
check chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
commonjs chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
compile fix: respect unstable "temporal" configuration in config file (#22134) 2024-03-08 01:32:11 +01:00
coverage chore: move more tests away from itest (#22909) 2024-03-15 15:46:51 -04:00
doc chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
dynamic_import chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
encoding chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
eval chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
file_extensions chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
fmt chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
import_attributes chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
import_maps chore: rough first pass on spec tests (#22877) 2024-03-13 16:21:13 +00:00
info chore: rough first pass on spec tests (#22877) 2024-03-13 16:21:13 +00:00
inspector chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
install chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
jsr/registry/@denotest chore: move more tests away from itest (#22909) 2024-03-15 15:46:51 -04:00
jsx chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
jupyter chore: move more tests away from itest (#22909) 2024-03-15 15:46:51 -04:00
lint feat(lint): deno lint --fix and lsp quick fixes (#22615) 2024-03-21 14:18:59 -07:00
lockfile chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
lsp chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
malformed_config chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
module_graph chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
node chore(cli): fix part of flaky test (#22515) 2024-02-21 19:10:51 +00:00
npm fix(node): resolve types via package.json for directory import (#22878) 2024-03-13 22:37:56 -04:00
package_json chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
publish fix(ext/node): Implement isBuiltin in node:module (#22817) 2024-03-08 18:06:04 -08:00
repl chore: bump deno_core (#22596) 2024-02-27 08:05:57 -07:00
run chore: rough first pass on spec tests (#22877) 2024-03-13 16:21:13 +00:00
runtime chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
subdir fix(lsp): don't apply renames to remote modules (#22765) 2024-03-07 17:27:24 +00:00
task chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
test fix(cli): output more detailed information for steps when using JUnit reporter (#22797) 2024-03-26 00:08:46 +09:00
tls chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
tsc chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
tsc2 chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
type_definitions chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
unfurl feat(publish): support sloppy imports and bare node built-ins (#22588) 2024-02-27 15:13:16 +00:00
vendor chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
webcrypto chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
webgpu chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
workers fix(ext/node): worker_threads doesn't exit if there are message listeners (#22944) 2024-03-15 21:38:16 +01:00
allow_run_allowlist_resolution.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
allow_run_allowlist_resolution.ts.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
cat.ts feat(lint): deno lint --fix and lsp quick fixes (#22615) 2024-03-21 14:18:59 -07:00
echo.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
echo_server.ts chore: move test_util/std to tests/util/std (#22402) 2024-02-13 09:22:49 -07:00
env chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
error_cause_recursive_aggregate.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
error_cause_recursive_aggregate.ts.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
error_cause_recursive_tail.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
error_cause_recursive_tail.ts.out chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
navigator_language.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
navigator_languages.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
spawn_kill_permissions.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
symlink_to_subdir chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00
welcome.ts chore: move cli/tests/ -> tests/ (#22369) 2024-02-10 20:22:13 +00:00