Skip to content

Commit

Permalink
test suite source location support for Cucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Sep 24, 2024
1 parent 415c5b1 commit ff0f32a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
28 changes: 25 additions & 3 deletions lib/datadog/ci/contrib/cucumber/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ def on_test_case_started(event)
tags[CI::Ext::Test::TAG_PARAMETERS] = Utils::TestRun.test_parameters(arguments: parameters)
end

start_test_suite(test_suite_name) unless same_test_suite_as_current?(test_suite_name)
unless same_test_suite_as_current?(test_suite_name)
start_test_suite(
test_suite_name,
tags: test_suite_source_file_tags(event.test_case)
)
end

test_span = test_visibility_component.trace_test(
event.test_case.name,
Expand Down Expand Up @@ -146,10 +151,10 @@ def finish_session(result)
test_session.finish
end

def start_test_suite(test_suite_name)
def start_test_suite(test_suite_name, tags: {})
finish_current_test_suite

@current_test_suite = test_visibility_component.start_test_suite(test_suite_name)
@current_test_suite = test_visibility_component.start_test_suite(test_suite_name, tags: tags)
end

def finish_current_test_suite
Expand Down Expand Up @@ -201,6 +206,23 @@ def configuration
def test_visibility_component
Datadog.send(:components).test_visibility
end

def test_suite_source_file_tags(test_case)
if test_case.respond_to?(:parent_locations)
# supported in cucumber >= 9.0
source_file = test_case.parent_locations.file
line_number = test_case.parent_locations.line.to_s
else
# fallback for cucumber < 9.0
source_file = test_case.location.file
line_number = "1"
end

{
CI::Ext::Test::TAG_SOURCE_FILE => Git::LocalRepository.relative_to_root(source_file),
CI::Ext::Test::TAG_SOURCE_START => line_number.to_s
}
end
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion sig/datadog/ci/contrib/cucumber/formatter.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module Datadog

def test_suite_name: (untyped test_case) -> String

def start_test_suite: (String test_suite_name) -> void
def start_test_suite: (String test_suite_name, ?tags: Hash[String, String]) -> void

def finish_current_test_suite: () -> void

Expand All @@ -52,6 +52,8 @@ module Datadog
def configuration: () -> untyped

def test_visibility_component: () -> Datadog::CI::TestVisibility::Component

def test_suite_source_file_tags: (untyped test_case) -> Hash[String, String]
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@
:framework_version,
Datadog::CI::Contrib::Cucumber::Integration.version.to_s
)

expect(first_test_suite_span).to have_test_tag(
:source_file,
"passing.feature"
)
expect(first_test_suite_span).to have_test_tag(:source_start, "1")

expect(first_test_suite_span).to have_test_tag(
:codeowners,
"[\"@test-owner\"]"
)

expect(first_test_suite_span).to have_pass_status
end

Expand Down

0 comments on commit ff0f32a

Please sign in to comment.