Skip to content

Commit

Permalink
set source location for RSpec test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Sep 23, 2024
1 parent f3d84e6 commit f692387
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/datadog/ci/contrib/rspec/example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ def run(reporter = ::RSpec::Core::NullReporter)
return super unless top_level?

suite_name = "#{description} at #{file_path}"
test_suite = test_visibility_component.start_test_suite(suite_name)
test_suite = test_visibility_component.start_test_suite(
suite_name,
tags: {
CI::Ext::Test::TAG_SOURCE_FILE => Git::LocalRepository.relative_to_root(metadata[:file_path]),
CI::Ext::Test::TAG_SOURCE_START => metadata[:line_number].to_s
}
)

success = super
return success unless test_suite
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/test_visibility/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def on_test_module_started(test_module)
end

def on_test_suite_started(test_suite)
# set_codeowners(test_suite)

Telemetry.event_created(test_suite)
end

Expand Down
9 changes: 8 additions & 1 deletion spec/datadog/ci/contrib/rspec/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def expect_failure

context "with git root changed" do
before do
expect(Datadog::CI::Git::LocalRepository).to receive(:root).and_return("#{Dir.pwd}/spec")
allow(Datadog::CI::Git::LocalRepository).to receive(:root).and_return("#{Dir.pwd}/spec")
end

it "provides source file path relative to git root" do
Expand Down Expand Up @@ -588,6 +588,13 @@ def expect_failure
:framework_version,
Datadog::CI::Contrib::RSpec::Integration.version.to_s
)

expect(first_test_suite_span).to have_test_tag(
:source_file,
"spec/datadog/ci/contrib/rspec/instrumentation_spec.rb"
)
expect(first_test_suite_span).to have_test_tag(:source_start, "57")

expect(first_test_suite_span).to have_pass_status
end

Expand Down
1 change: 1 addition & 0 deletions vendor/rbs/rspec/0/rspec.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module RSpec::Core::ExampleGroup
def top_level?: () -> bool
def file_path: () -> String
def description: () -> String
def metadata: () -> untyped
end
end

Expand Down

0 comments on commit f692387

Please sign in to comment.