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 9995b7b4..5a557c1e 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,10 +53,58 @@ 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], + timestamp: Time.now.iso8601, + hostname: Socket.gethostname + } + 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) - ) + Minitest::Reporters.use! [ + Minitest::Reporters::SpecReporter.new(color: true), + Minitest::Reporters::JUnitReporter.new('build/reports/', true, 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 49ea3d1b..1c7e9d4b 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,10 +52,59 @@ 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], + timestamp: suite_result[:timestamp] || Time.now.iso8601, + hostname: Socket.gethostname + } + 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) - ) + Minitest::Reporters.use! [ + Minitest::Reporters::SpecReporter.new(color: true), + Minitest::Reporters::JUnitReporter.new('build/reports/', true, single_file: true) + ] end rescue LoadError warn 'minitest-reporters not available — install with `bundle add minitest-reporters`'