Skip to content

Commit

Permalink
Merge pull request #211 from DataDog/anmarchenko/cucumber_better_test…
Browse files Browse the repository at this point in the history
…_skipping

[SDTEST-481] Skip Before/After hooks in cucumber when scenario is skipped by intelligent test runner
  • Loading branch information
anmarchenko authored Jul 31, 2024
2 parents 0e24d28 + 507b4e8 commit f00caf6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 46 deletions.
8 changes: 8 additions & 0 deletions lib/datadog/ci/contrib/cucumber/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def formatters
@datadog_formatter ||= CI::Contrib::Cucumber::Formatter.new(@configuration)
[@datadog_formatter] + existing_formatters
end

def begin_scenario(test_case)
if Datadog::CI.active_test&.skipped_by_itr?
raise ::Cucumber::Core::Test::Result::Skipped, CI::Ext::Test::ITR_TEST_SKIP_REASON
end

super
end
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/datadog/ci/contrib/cucumber/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
require "datadog/tracing/contrib/patcher"

require_relative "instrumentation"
require_relative "step"

module Datadog
module CI
module Contrib
module Cucumber
# Patcher enables patching of 'cucumber' module.
# Patches 'cucumber' gem.
module Patcher
include Datadog::Tracing::Contrib::Patcher

Expand All @@ -21,7 +20,6 @@ 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: 0 additions & 27 deletions lib/datadog/ci/contrib/cucumber/step.rb

This file was deleted.

16 changes: 0 additions & 16 deletions sig/datadog/ci/contrib/cucumber/step.rbs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
require_relative "helpers/helper"

Before do
Datadog::CI.active_test.set_tag("cucumber_before_hook_executed", "true")
end

After do
Datadog::CI.active_test.set_tag("cucumber_after_hook_executed", "true")
end

AfterStep do
Datadog::CI.active_test.set_tag("cucumber_after_step_hook_executed", "true")
end

Then "datadog" do
Helper.help?
end
Expand Down
5 changes: 5 additions & 0 deletions spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@

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

# check that hooks are not executed for skipped tests
expect(itr_skipped_test.get_tag("cucumber_before_hook_executed")).to be_nil
expect(itr_skipped_test.get_tag("cucumber_after_hook_executed")).to be_nil
expect(itr_skipped_test.get_tag("cucumber_after_step_hook_executed")).to be_nil
end

it "sets session level tags" do
Expand Down
4 changes: 4 additions & 0 deletions vendor/rbs/cucumber/0/cucumber.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ end

class Cucumber::Runtime
def formatters: () -> untyped
def begin_scenario: (untyped test_case) -> void
end

module Cucumber::Formatter
Expand All @@ -23,6 +24,9 @@ class Cucumber::Core::Test::Result
def undefined?: () -> bool
def message: () -> String
def exception: () -> untyped

class Skipped < StandardError
end
end

module Cucumber::Core::Test::Step
Expand Down

0 comments on commit f00caf6

Please sign in to comment.