From 79676e72a3972b77238d99965d1fcddfedf0d410 Mon Sep 17 00:00:00 2001 From: Mridang Agarwalla Date: Sun, 20 Apr 2025 11:52:54 +0300 Subject: [PATCH 1/5] Configured the test engine to generate Junits-style XML reports --- spec/spec_helper.rb | 10 +++++++--- test/test_helper.rb | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6f1d2d9b..4ddc5342 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -45,9 +45,13 @@ def output_path begin require 'minitest/reporters' unless ENV['RM_INFO'] - Minitest::Reporters.use!( - Minitest::Reporters::SpecReporter.new(color: true) - ) + Minitest::Reporters.use! [ + Minitest::Reporters::SpecReporter.new(color: true), + Minitest::Reporters::JUnitReporter.new( + 'build/reports/', + single_file: true + ) + ] end rescue LoadError warn 'minitest-reporters not available — install with `bundle add minitest-reporters`' diff --git a/test/test_helper.rb b/test/test_helper.rb index 6f1d2d9b..6c7ca9c0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -45,9 +45,13 @@ def output_path begin require 'minitest/reporters' unless ENV['RM_INFO'] - Minitest::Reporters.use!( - Minitest::Reporters::SpecReporter.new(color: true) - ) + Minitest::Reporters.use! [ + Minitest::Reporters::SpecReporter.new(color: true), + Minitest::Reporters::JUnitReporter.new( + 'build/reports', + single_file: true + ) + ] end rescue LoadError warn 'minitest-reporters not available — install with `bundle add minitest-reporters`' From 66e62fe616c0b16886805d24ef7d84377c3b9999 Mon Sep 17 00:00:00 2001 From: Mridang Agarwalla Date: Sun, 20 Apr 2025 15:39:32 +0300 Subject: [PATCH 2/5] Updated the workflow to archive and publish reports --- .github/workflows/test.yml | 16 ++++++++++++++++ spec/spec_helper.rb | 12 ++++++------ test/test_helper.rb | 12 ++++++------ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 654aeeeb..549474a5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,3 +39,19 @@ jobs: JWT_KEY: ${{ secrets.JWT_KEY }} CLIENT_ID: ${{ secrets.CLIENT_ID }} CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} + + - name: Upload Results + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-results + path: build/reports/**/*.xml + + - name: Generate Report + if: ${{ always() && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false) }} + uses: dorny/test-reporter@v2.0.0 + with: + name: Tests + reporter: java-junit + path: build/reports/**/*.xml + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4ddc5342..0961db0a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -46,12 +46,12 @@ def output_path require 'minitest/reporters' unless ENV['RM_INFO'] Minitest::Reporters.use! [ - Minitest::Reporters::SpecReporter.new(color: true), - Minitest::Reporters::JUnitReporter.new( - 'build/reports/', - single_file: true - ) - ] + Minitest::Reporters::SpecReporter.new(color: true), + Minitest::Reporters::JUnitReporter.new( + 'build/reports/', + single_file: true + ) + ] end rescue LoadError warn 'minitest-reporters not available — install with `bundle add minitest-reporters`' diff --git a/test/test_helper.rb b/test/test_helper.rb index 6c7ca9c0..d1e2054a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -46,12 +46,12 @@ def output_path require 'minitest/reporters' unless ENV['RM_INFO'] Minitest::Reporters.use! [ - Minitest::Reporters::SpecReporter.new(color: true), - Minitest::Reporters::JUnitReporter.new( - 'build/reports', - single_file: true - ) - ] + Minitest::Reporters::SpecReporter.new(color: true), + Minitest::Reporters::JUnitReporter.new( + 'build/reports', + single_file: true + ) + ] end rescue LoadError warn 'minitest-reporters not available — install with `bundle add minitest-reporters`' From d5b141c2c3a41ca3be20414a8f792734504a5a6e Mon Sep 17 00:00:00 2001 From: Mridang Agarwalla Date: Wed, 23 Apr 2025 08:43:49 +0300 Subject: [PATCH 3/5] Tweaked the minitest reporters to not use fileno and lineno in the testsuite attributes --- spec/spec_helper.rb | 48 +++++++++++++++++++++++++++++++++++++++++++++ test/test_helper.rb | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 998b8332..22baba88 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,8 +3,11 @@ require 'dotenv' require 'simplecov' require 'simplecov-lcov' +require 'warning' + require_relative '../lib/zitadel_client' +Warning.ignore(:method_redefined, __dir__) Dotenv.load('.env') # Configure the LCOV formatter @@ -50,6 +53,51 @@ class HTMLFormatter begin require 'minitest/reporters' + + module Minitest + module Reporters + # rubocop:disable Metrics/AbcSize,Style/Documentation,Metrics/MethodLength + class JUnitReporter + private + + def parse_xml_for(xml, suite, tests) + suite_result = analyze_suite(tests) + file_path = get_relative_path(tests.first) + + testsuite_attributes = { + name: suite, + file: file_path, + skipped: suite_result[:skip_count], + failures: suite_result[:fail_count], + errors: suite_result[:error_count], + tests: suite_result[:test_count], + assertions: suite_result[:assertion_count], + time: suite_result[:time] + } + testsuite_attributes[:timestamp] = suite_result[:timestamp] if @timestamp_report + + xml.testsuite(testsuite_attributes) do + tests.each do |test| + line = get_source_location(test).last + xml.testcase( + name: test.name, + line: line, + classname: suite, + assertions: test.assertions, + time: test.time, + file: file_path + ) do + xml << xml_message_for(test) unless test.passed? + xml << xml_attachment_for(test) if test.respond_to?('metadata') && test.metadata[:failure_screenshot_path] + end + end + end + end + end + # rubocop:enable Metrics/AbcSize,Style/Documentation,Metrics/MethodLength + end + end + unless ENV['RM_INFO'] Minitest::Reporters.use! [ Minitest::Reporters::SpecReporter.new(color: true), diff --git a/test/test_helper.rb b/test/test_helper.rb index fdba6b70..b8500cb1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -6,6 +6,7 @@ require 'simplecov-lcov' require_relative '../lib/zitadel_client' +Warning.ignore(:method_redefined, __dir__) Dotenv.load('.env') # Configure the LCOV formatter @@ -51,6 +52,52 @@ class HTMLFormatter begin require 'minitest/reporters' + + # 🔧 Monkeypatch to override :lineno with :line + module Minitest + module Reporters + # rubocop:disable Metrics/AbcSize,Style/Documentation,Metrics/MethodLength + class JUnitReporter + private + + def parse_xml_for(xml, suite, tests) + suite_result = analyze_suite(tests) + file_path = get_relative_path(tests.first) + + testsuite_attributes = { + name: suite, + filepath: file_path, + skipped: suite_result[:skip_count], + failures: suite_result[:fail_count], + errors: suite_result[:error_count], + tests: suite_result[:test_count], + assertions: suite_result[:assertion_count], + time: suite_result[:time] + } + testsuite_attributes[:timestamp] = suite_result[:timestamp] if @timestamp_report + + xml.testsuite(testsuite_attributes) do + tests.each do |test| + line = get_source_location(test).last + xml.testcase( + name: test.name, + line: line, + classname: suite, + assertions: test.assertions, + time: test.time, + file: file_path + ) do + xml << xml_message_for(test) unless test.passed? + xml << xml_attachment_for(test) if test.respond_to?('metadata') && test.metadata[:failure_screenshot_path] + end + end + end + end + end + # rubocop:enable Metrics/AbcSize,Style/Documentation,Metrics/MethodLength + end + end + unless ENV['RM_INFO'] Minitest::Reporters.use! [ Minitest::Reporters::SpecReporter.new(color: true), From 967d00c88595f5c8721b0af9eff97f06e096990c Mon Sep 17 00:00:00 2001 From: Mridang Agarwalla Date: Wed, 23 Apr 2025 08:56:05 +0300 Subject: [PATCH 4/5] Fixed a bug in Minitest that prevented a single-file XML report from being generated --- spec/spec_helper.rb | 5 +---- test/test_helper.rb | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 22baba88..c8185b94 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -101,10 +101,7 @@ def parse_xml_for(xml, suite, tests) unless ENV['RM_INFO'] Minitest::Reporters.use! [ Minitest::Reporters::SpecReporter.new(color: true), - Minitest::Reporters::JUnitReporter.new( - 'build/reports/', - single_file: true - ) + Minitest::Reporters::JUnitReporter.new('build/reports/', true, single_file: true) ] end rescue LoadError diff --git a/test/test_helper.rb b/test/test_helper.rb index b8500cb1..67e8a6e2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -101,10 +101,7 @@ def parse_xml_for(xml, suite, tests) unless ENV['RM_INFO'] Minitest::Reporters.use! [ Minitest::Reporters::SpecReporter.new(color: true), - Minitest::Reporters::JUnitReporter.new( - 'build/reports', - single_file: true - ) + Minitest::Reporters::JUnitReporter.new('build/reports/', true, single_file: true) ] end rescue LoadError From 9408022bf2512660d27816ff2bea5e2a175a0ce3 Mon Sep 17 00:00:00 2001 From: Mridang Agarwalla Date: Wed, 23 Apr 2025 09:16:34 +0300 Subject: [PATCH 5/5] Added the hostname and timestamp attributes --- spec/spec_helper.rb | 4 +++- test/test_helper.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c8185b94..5a557c1e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -72,7 +72,9 @@ def parse_xml_for(xml, suite, tests) errors: suite_result[:error_count], tests: suite_result[:test_count], assertions: suite_result[:assertion_count], - time: suite_result[:time] + time: suite_result[:time], + timestamp: Time.now.iso8601, + hostname: Socket.gethostname } testsuite_attributes[:timestamp] = suite_result[:timestamp] if @timestamp_report diff --git a/test/test_helper.rb b/test/test_helper.rb index 67e8a6e2..1c7e9d4b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -72,7 +72,9 @@ def parse_xml_for(xml, suite, tests) errors: suite_result[:error_count], tests: suite_result[:test_count], assertions: suite_result[:assertion_count], - time: suite_result[:time] + time: suite_result[:time], + timestamp: suite_result[:timestamp] || Time.now.iso8601, + hostname: Socket.gethostname } testsuite_attributes[:timestamp] = suite_result[:timestamp] if @timestamp_report