diff options
author | Alexander Michaud <131308558+armichaud@users.noreply.github.com> | 2023-08-17 17:41:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-17 23:41:29 +0200 |
commit | b5839eefcf02e62e9e77e8095f372ac06a523cba (patch) | |
tree | 1e1c1bf0f992936ce52bcfc6d568e5e787f7916b | |
parent | f343391a9f97d29ad287f247c06aa370eb7cab50 (diff) |
fix(test): JUnit reporter includes file, line and column attributes (#20174)
Closes #20156
-rw-r--r-- | cli/tests/integration/test_tests.rs | 5 | ||||
-rw-r--r-- | cli/tests/testdata/test/pass.junit.out | 38 | ||||
-rw-r--r-- | cli/tools/test/reporters/junit.rs | 23 |
3 files changed, 60 insertions, 6 deletions
diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs index bcf050adf..04465dd53 100644 --- a/cli/tests/integration/test_tests.rs +++ b/cli/tests/integration/test_tests.rs @@ -267,6 +267,11 @@ itest!(exit_sanitizer { exit_code: 1, }); +itest!(junit { + args: "test --reporter junit test/pass.ts", + output: "test/pass.junit.out", +}); + itest!(clear_timeout { args: "test test/clear_timeout.ts", exit_code: 0, diff --git a/cli/tests/testdata/test/pass.junit.out b/cli/tests/testdata/test/pass.junit.out new file mode 100644 index 000000000..b652dbf85 --- /dev/null +++ b/cli/tests/testdata/test/pass.junit.out @@ -0,0 +1,38 @@ +Check [WILDCARD]/testdata/test/pass.ts +<?xml version="1.0" encoding="UTF-8"?> +<testsuites name="deno test" tests="16" failures="0" errors="0" time="[WILDCARD]"> + <testsuite name="[WILDCARD]/testdata/test/pass.ts" tests="16" disabled="0" errors="0" failures="0"> + <testcase name="test 0" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="1" col="6"> + </testcase> + <testcase name="test 1" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="2" col="6"> + </testcase> + <testcase name="test 2" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="3" col="6"> + </testcase> + <testcase name="test 3" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="4" col="6"> + </testcase> + <testcase name="test 4" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="5" col="6"> + </testcase> + <testcase name="test 5" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="6" col="6"> + </testcase> + <testcase name="test 6" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="7" col="6"> + </testcase> + <testcase name="test 7" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="8" col="6"> + </testcase> + <testcase name="test 8" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="9" col="6"> + </testcase> + <testcase name="test 9" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="12" col="6"> + </testcase> + <testcase name="test\b" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="16" col="6"> + </testcase> + <testcase name="test\f" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="19" col="6"> + </testcase> + <testcase name="test\t" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="23" col="6"> + </testcase> + <testcase name="test\n" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="27" col="6"> + </testcase> + <testcase name="test\r" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="31" col="6"> + </testcase> + <testcase name="test\v" time="[WILDCARD]" filename="[WILDCARD]/testdata/test/pass.ts" line="35" col="6"> + </testcase> + </testsuite> +</testsuites> diff --git a/cli/tools/test/reporters/junit.rs b/cli/tools/test/reporters/junit.rs index eb6479a59..a62c32dab 100644 --- a/cli/tools/test/reporters/junit.rs +++ b/cli/tools/test/reporters/junit.rs @@ -40,13 +40,24 @@ impl JunitTestReporter { impl TestReporter for JunitTestReporter { fn report_register(&mut self, description: &TestDescription) { - self.cases.insert( - description.id, - quick_junit::TestCase::new( - description.name.clone(), - quick_junit::TestCaseStatus::skipped(), - ), + let mut case = quick_junit::TestCase::new( + description.name.clone(), + quick_junit::TestCaseStatus::skipped(), ); + let file_name = description.location.file_name.clone(); + let file_name = file_name.strip_prefix("file://").unwrap_or(&file_name); + case + .extra + .insert(String::from("filename"), String::from(file_name)); + case.extra.insert( + String::from("line"), + description.location.line_number.to_string(), + ); + case.extra.insert( + String::from("col"), + description.location.column_number.to_string(), + ); + self.cases.insert(description.id, case); } fn report_plan(&mut self, _plan: &TestPlan) {} |