diff --git a/lib/datadog/ci/contrib/minitest/patcher.rb b/lib/datadog/ci/contrib/minitest/patcher.rb index db914cd6..01521675 100644 --- a/lib/datadog/ci/contrib/minitest/patcher.rb +++ b/lib/datadog/ci/contrib/minitest/patcher.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require_relative "runner" require_relative "reporter" require_relative "hooks" require_relative "runnable" @@ -19,9 +20,14 @@ def target_version end def patch - ::Minitest::CompositeReporter.include(Reporter) - ::Minitest::Test.include(Hooks) + # test session start + ::Minitest.include(Runner) + # test suites (when not executed concurrently) ::Minitest::Runnable.include(Runnable) + # tests; test suites (when executed concurrently) + ::Minitest::Test.include(Hooks) + # test session finish + ::Minitest::CompositeReporter.include(Reporter) end end end diff --git a/lib/datadog/ci/contrib/minitest/reporter.rb b/lib/datadog/ci/contrib/minitest/reporter.rb index bc0e1096..596b6622 100644 --- a/lib/datadog/ci/contrib/minitest/reporter.rb +++ b/lib/datadog/ci/contrib/minitest/reporter.rb @@ -37,21 +37,6 @@ def report(*) res end - def start(*) - return super unless datadog_configuration[:enabled] - - test_session = CI.start_test_session( - tags: { - CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK, - CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::Minitest::Integration.version.to_s - }, - service: datadog_configuration[:service_name] - ) - CI.start_test_module(test_session.name) if test_session - - super - end - private def datadog_configuration diff --git a/lib/datadog/ci/contrib/minitest/runner.rb b/lib/datadog/ci/contrib/minitest/runner.rb new file mode 100644 index 00000000..f4ebbcad --- /dev/null +++ b/lib/datadog/ci/contrib/minitest/runner.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require_relative "../../ext/test" +require_relative "ext" + +module Datadog + module CI + module Contrib + module Minitest + module Runner + def self.included(base) + base.singleton_class.prepend(ClassMethods) + end + + module ClassMethods + def init_plugins(*) + super + + return unless datadog_configuration[:enabled] + + test_session = CI.start_test_session( + tags: { + CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK, + CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::Minitest::Integration.version.to_s + }, + service: datadog_configuration[:service_name] + ) + CI.start_test_module(test_session.name) if test_session + end + + private + + def datadog_configuration + Datadog.configuration.ci[:minitest] + end + end + end + end + end + end +end diff --git a/sig/datadog/ci/contrib/minitest/reporter.rbs b/sig/datadog/ci/contrib/minitest/reporter.rbs index c2bd30cb..78aff5f2 100644 --- a/sig/datadog/ci/contrib/minitest/reporter.rbs +++ b/sig/datadog/ci/contrib/minitest/reporter.rbs @@ -8,8 +8,6 @@ module Datadog class InstanceMethods < ::Minitest::AbstractReporter def report: (*untyped) -> untyped - def start: (*untyped) -> untyped - private def datadog_configuration: () -> untyped diff --git a/sig/datadog/ci/contrib/minitest/runner.rbs b/sig/datadog/ci/contrib/minitest/runner.rbs new file mode 100644 index 00000000..852c50c6 --- /dev/null +++ b/sig/datadog/ci/contrib/minitest/runner.rbs @@ -0,0 +1,21 @@ +module Datadog + module CI + module Contrib + module Minitest + module Runner + def self.included: (untyped base) -> untyped + + class ClassMethods + extend ::Minitest + + def init_plugins: (*untyped) -> (nil | untyped) + + private + + def datadog_configuration: () -> untyped + end + end + end + end + end +end