Skip to content

Commit

Permalink
trying out approaches for test skipping support in cucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Apr 19, 2024
1 parent 5aed886 commit 39ff720
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/datadog/ci/contrib/cucumber/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative "../../ext/test"
require_relative "../../git/local_repository"
require_relative "../../utils/test_run"
require_relative "ext"

module Datadog
Expand Down Expand Up @@ -55,13 +56,18 @@ def on_test_run_finished(event)
def on_test_case_started(event)
test_suite_name = test_suite_name(event.test_case)

# @type var tags: Hash[String, String]
tags = {
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::Cucumber::Integration.version.to_s,
CI::Ext::Test::TAG_SOURCE_FILE => Git::LocalRepository.relative_to_root(event.test_case.location.file),
CI::Ext::Test::TAG_SOURCE_START => event.test_case.location.line.to_s
}

if (parameters = extract_parameters_hash(event.test_case))
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)

test_span = CI.start_test(
Expand All @@ -70,16 +76,21 @@ def on_test_case_started(event)
tags: tags,
service: configuration[:service_name]
)

if (parameters = extract_parameters_hash(event.test_case))
test_span&.set_parameters(parameters)
if test_span&.skipped_by_itr?
p "WANT TO SKIP TEST #{test_span}"
p ::Cucumber::Core::Ast::Tag.new("", "_dd_itr_skip")
event.test_case.tags << ::Cucumber::Core::Ast::Tag.new("", "@_dd_itr_skip")
end
end

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

if test_span.skipped_by_itr?
p "DID WE SKIP TEST? answer: #{event.result}"
end

finish_span(test_span, event.result)
@failed_tests_count += 1 if test_span.failed?
end
Expand Down
15 changes: 15 additions & 0 deletions spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

let(:itr_enabled) { true }
let(:code_coverage_enabled) { true }
let(:tests_skipping_enabled) { true }
end

let(:cucumber_8_or_above) { Gem::Version.new("8.0.0") <= Datadog::CI::Contrib::Cucumber::Integration.version }
Expand Down Expand Up @@ -206,6 +207,20 @@
)
end
end

context "skipping a test" do
let(:itr_skippable_tests) do
Set.new([
"Datadog integration at spec/datadog/ci/contrib/cucumber/features/passing.feature.cucumber scenario."
])
end

it "skips the test" do
expect(test_spans).to have(4).items
p test_spans.map { |span| span.get_tag("test.status") }
# expect(test_spans).to all have_skip_status
end
end
end

context "executing a failing test suite" do
Expand Down

0 comments on commit 39ff720

Please sign in to comment.