Skip to content

Commit

Permalink
Cucumber contrib doesn't use public API anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jul 26, 2024
1 parent 8034e41 commit 7a41b72
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/datadog/ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

require_relative "ci/version"
require_relative "ci/utils/configuration"
require_relative "ci/utils/telemetry"
require_relative "ci/ext/app_types"
require_relative "ci/ext/telemetry"

require "datadog/core"

Expand Down
22 changes: 13 additions & 9 deletions lib/datadog/ci/contrib/cucumber/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def bind_events(config)
end

def on_test_run_started(event)
CI.start_test_session(
test_visibility_component.start_test_session(
tags: {
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::Cucumber::Integration.version.to_s
},
service: configuration[:service_name]
)
CI.start_test_module(Ext::FRAMEWORK)
test_visibility_component.start_test_module(Ext::FRAMEWORK)
end

def on_test_run_finished(event)
Expand Down Expand Up @@ -70,7 +70,7 @@ def on_test_case_started(event)

start_test_suite(test_suite_name) unless same_test_suite_as_current?(test_suite_name)

test_span = CI.start_test(
test_span = test_visibility_component.trace_test(
event.test_case.name,
test_suite_name,
tags: tags,
Expand All @@ -82,19 +82,19 @@ def on_test_case_started(event)
end

def on_test_case_finished(event)
test_span = CI.active_test
test_span = test_visibility_component.active_test
return if test_span.nil?

finish_span(test_span, event.result)
@failed_tests_count += 1 if test_span.failed?
end

def on_test_step_started(event)
CI.trace(event.test_step.to_s, type: Ext::STEP_SPAN_TYPE)
test_visibility_component.trace(event.test_step.to_s, type: Ext::STEP_SPAN_TYPE)
end

def on_test_step_finished(event)
current_step_span = CI.active_span
current_step_span = test_visibility_component.active_span
return if current_step_span.nil?

finish_span(current_step_span, event.result)
Expand Down Expand Up @@ -130,8 +130,8 @@ def finish_span(span, result)
def finish_session(result)
finish_current_test_suite

test_session = CI.active_test_session
test_module = CI.active_test_module
test_session = test_visibility_component.active_test_session
test_module = test_visibility_component.active_test_module

return unless test_session && test_module

Expand All @@ -150,7 +150,7 @@ def finish_session(result)
def start_test_suite(test_suite_name)
finish_current_test_suite

@current_test_suite = CI.start_test_suite(test_suite_name)
@current_test_suite = test_visibility_component.start_test_suite(test_suite_name)
end

def finish_current_test_suite
Expand Down Expand Up @@ -197,6 +197,10 @@ def ok?(result, strict)
def configuration
Datadog.configuration.ci[:cucumber]
end

def test_visibility_component
Datadog.send(:components).test_visibility
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/contrib/cucumber/formatter.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ module Datadog
def ok?: (Cucumber::Core::Test::Result result, untyped strict) -> bool

def configuration: () -> untyped

def test_visibility_component: () -> Datadog::CI::TestVisibility::Component
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
expect(Datadog::CI::Ext::Environment).to receive(:tags).never
expect(kernel).to receive(:exit).with(expected_test_run_code)

# do not use manual API
expect(Datadog::CI).to receive(:start_test_session).never
expect(Datadog::CI).to receive(:start_test_module).never
expect(Datadog::CI).to receive(:start_test_suite).never
expect(Datadog::CI).to receive(:start_test).never

cli.execute!(existing_runtime)
end

Expand Down

0 comments on commit 7a41b72

Please sign in to comment.