Skip to content

Commit

Permalink
use feature name as a prefix for cucumber test suite name
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jan 16, 2024
1 parent cff4f36 commit 6cff8bc
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
17 changes: 16 additions & 1 deletion lib/datadog/ci/contrib/cucumber/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def on_test_run_finished(event)
end

def on_test_case_started(event)
test_suite_name = event.test_case.location.file
test_suite_name = test_suite_name(event.test_case)

tags = {
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
Expand Down Expand Up @@ -108,6 +108,21 @@ def on_test_step_finished(event)

private

def test_suite_name(test_case)
feature = if test_case.respond_to?(:feature)
test_case.feature
elsif @ast_lookup
gherkin_doc = @ast_lookup.gherkin_document(test_case.location.file)
gherkin_doc.feature if gherkin_doc
end

if feature
"#{feature.name} at #{test_case.location.file}"
else
test_case.location.file
end
end

def finish_test(span, result)
if result.skipped?
span.skipped!
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 @@ -30,6 +30,8 @@ module Datadog

private

def test_suite_name: (untyped test_case) -> String

def start_test_suite: (String test_suite_name) -> void

def finish_current_test_suite: () -> void
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/ci/contrib/cucumber/features/failing.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: Datadog integration
Feature: Datadog integration - test failing features
Scenario: cucumber failing scenario
Given datadog
And datadog
Expand Down
10 changes: 6 additions & 4 deletions spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
expect(scenario_span.get_tag(Datadog::CI::Ext::Test::TAG_SPAN_KIND)).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST)
expect(scenario_span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("cucumber scenario")
expect(scenario_span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE)).to eq(
"spec/datadog/ci/contrib/cucumber/features/passing.feature"
"Datadog integration at spec/datadog/ci/contrib/cucumber/features/passing.feature"
)
expect(scenario_span.get_tag(Datadog::CI::Ext::Test::TAG_TYPE)).to eq(Datadog::CI::Ext::Test::TEST_TYPE)
expect(scenario_span.get_tag(Datadog::CI::Ext::Test::TAG_FRAMEWORK)).to eq(
Expand Down Expand Up @@ -147,7 +147,7 @@

it "creates test suite span" do
expect(test_suite_span).not_to be_nil
expect(test_suite_span.name).to eq(features_path)
expect(test_suite_span.name).to eq("Datadog integration at spec/datadog/ci/contrib/cucumber/features/passing.feature")
expect(test_suite_span.service).to eq("jalapenos")
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_SPAN_KIND)).to eq(
Datadog::CI::Ext::AppTypes::TYPE_TEST
Expand Down Expand Up @@ -189,7 +189,9 @@
Datadog::CI::Ext::Test::Status::FAIL
)

expect(test_suite_span.name).to eq(features_path)
expect(test_suite_span.name).to eq(
"Datadog integration - test failing features at spec/datadog/ci/contrib/cucumber/features/failing.feature"
)
expect(test_suite_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
Expand Down Expand Up @@ -224,7 +226,7 @@
)
end
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE)).to eq(
"spec/datadog/ci/contrib/cucumber/features/with_parameters.feature"
"Datadog integration for parametrized tests at spec/datadog/ci/contrib/cucumber/features/with_parameters.feature"
)
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID)).to eq(test_suite_span.id.to_s)
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Expand Down
13 changes: 12 additions & 1 deletion vendor/rbs/cucumber/0/cucumber.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ end
module Cucumber::Formatter
end


class Cucumber::Core::Test::Result
def failed?: () -> bool
def ok?: () -> bool
Expand All @@ -26,4 +25,16 @@ class Cucumber::Formatter::AstLookup
def initialize: (untyped config) -> void

def scenario_source: (untyped test_case) -> untyped
def gherkin_document: (String uri) -> Cucumber::Messages::GherkinDocument?
end

module Cucumber::Messages
end

class Cucumber::Messages::GherkinDocument
def feature: () -> Cucumber::Messages::Feature
end

class Cucumber::Messages::Feature
def name: () -> String
end

0 comments on commit 6cff8bc

Please sign in to comment.