Skip to content

Commit

Permalink
cucumber test skipping implementation done
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Apr 22, 2024
1 parent 5a889cf commit 685c205
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 10 deletions.
10 changes: 0 additions & 10 deletions lib/datadog/ci/contrib/cucumber/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@ def on_test_run_finished(event)
end

def on_test_case_started(event)
::Cucumber::Core::Test::Step.class_eval do
def execute(*args)
test_span = CI.active_test
if test_span&.skipped_by_itr?
@action.skip(*args)
else
@action.execute(*args)
end
end
end
test_suite_name = test_suite_name(event.test_case)

# @type var tags: Hash[String, String]
Expand Down
3 changes: 3 additions & 0 deletions lib/datadog/ci/contrib/cucumber/patcher.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

require "datadog/tracing/contrib/patcher"

require_relative "instrumentation"
require_relative "step"

module Datadog
module CI
Expand All @@ -19,6 +21,7 @@ def target_version

def patch
::Cucumber::Runtime.include(Instrumentation)
::Cucumber::Core::Test::Step.include(Datadog::CI::Contrib::Cucumber::Step)
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions lib/datadog/ci/contrib/cucumber/step.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Datadog
module CI
module Contrib
module Cucumber
# instruments Cucumber::Core::Test::Step from cucumber-ruby-core to change
module Step
def self.included(base)
base.prepend(InstanceMethods)
end

module InstanceMethods
def execute(*args)
test_span = CI.active_test
if test_span&.skipped_by_itr?
@action.skip(*args)
else
super
end
end
end
end
end
end
end
end
16 changes: 16 additions & 0 deletions sig/datadog/ci/contrib/cucumber/step.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Datadog
module CI
module Contrib
module Cucumber
module Step
def self.included: (untyped base) -> untyped

module InstanceMethods
prepend ::Cucumber::Core::Test::Step
def execute: (*untyped args) -> untyped
end
end
end
end
end
end
41 changes: 41 additions & 0 deletions spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@
Datadog::CI::Contrib::Cucumber::Integration.version.to_s
)
expect(test_session_span).to have_pass_status

# ITR
expect(test_session_span).to have_test_tag(:itr_test_skipping_enabled, "true")
expect(test_session_span).to have_test_tag(:itr_test_skipping_type, "test")
expect(test_session_span).to have_test_tag(:itr_tests_skipped, "false")
expect(test_session_span).to have_test_tag(:itr_test_skipping_count, 0)
end

it "creates test module span" do
Expand Down Expand Up @@ -218,6 +224,16 @@
it "skips the test" do
expect(test_spans).to have(4).items
expect(test_spans).to all have_skip_status

itr_skipped_test = test_spans.find { |span| span.name == "cucumber scenario" }
expect(itr_skipped_test).to have_test_tag(:itr_skipped_by_itr, "true")
end

it "sets session level tags" do
expect(test_session_span).to have_test_tag(:itr_test_skipping_enabled, "true")
expect(test_session_span).to have_test_tag(:itr_test_skipping_type, "test")
expect(test_session_span).to have_test_tag(:itr_tests_skipped, "true")
expect(test_session_span).to have_test_tag(:itr_test_skipping_count, 1)
end
end
end
Expand Down Expand Up @@ -272,6 +288,31 @@
expect(span).to have_pass_status
end
end

context "skipping some tests" do
before do
skip("test parameters are not supported in cucumber 3") unless cucumber_4_or_above
end

let(:itr_skippable_tests) do
Set.new([
'Datadog integration for parametrized tests at spec/datadog/ci/contrib/cucumber/features/with_parameters.feature.scenario with examples.{"arguments":{"num1":"0","num2":"1","total":"1"},"metadata":{}}',
'Datadog integration for parametrized tests at spec/datadog/ci/contrib/cucumber/features/with_parameters.feature.scenario with examples.{"arguments":{"num1":"2","num2":"3","total":"5"},"metadata":{}}'
])
end

it "skips the test" do
expect(test_spans).to have(3).items
expect(test_spans).to have_tag_values_no_order(:status, ["skip", "skip", "pass"])
end

it "sets session level tags" do
expect(test_session_span).to have_test_tag(:itr_test_skipping_enabled, "true")
expect(test_session_span).to have_test_tag(:itr_test_skipping_type, "test")
expect(test_session_span).to have_test_tag(:itr_tests_skipped, "true")
expect(test_session_span).to have_test_tag(:itr_test_skipping_count, 2)
end
end
end

context "executing several features at once" do
Expand Down
5 changes: 5 additions & 0 deletions vendor/rbs/cucumber/0/cucumber.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Cucumber::Core::Test::Result
def exception: () -> untyped
end

module Cucumber::Core::Test::Step
@action: untyped
def execute: (untyped args) -> untyped
end

class Cucumber::Formatter::AstLookup
def initialize: (untyped config) -> void

Expand Down

0 comments on commit 685c205

Please sign in to comment.