Skip to content

Commit cb787db

Browse files
committed
test: ✅ add new step to assert array attribute values without knowing the order of the span
1 parent ba7a47e commit cb787db

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Diff for: test/browser/features/component-lifecycle-spans.feature

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ Feature: Component lifecycle spans
55
When I wait to receive 1 trace
66
Then a span name equals "[ViewLoad/Component]Component"
77
And a span name equals "[ViewLoadPhase/Mount]Component"
8-
And a span name equals "[ViewLoadPhase/Update]Component"
98
And a span name equals "[ViewLoadPhase/Unmount]Component"
10-
# [ViewLoadPhase/Update]Component attributes
11-
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.2" string array attribute "bugsnag.component.update.props" equals the array:
9+
And a span named "[ViewLoadPhase/Update]Component" contains the string array attribute "bugsnag.component.update.props":
1210
| count |
1311

1412
@skip

Diff for: test/browser/features/steps/browser-steps.rb

+20
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,26 @@
195195
end
196196
end
197197

198+
Then('a span named {string} contains the string array attribute {string}:') do |span_name, attribute, table|
199+
spans = spans_from_request_list(Maze::Server.list_for('traces'))
200+
named_spans = spans.find_all { |span| span['name'].eql?(span_name) }
201+
raise Test::Unit::AssertionFailedError.new "No spans were found with the name #{span_name}" if named_spans.empty?
202+
203+
expected_values = table.raw.flatten
204+
205+
named_spans.each do |span|
206+
attribute_values = span['attributes'].find { |attr| attr['key'].eql?(attribute) }&.dig('value', 'arrayValue', 'values')&.map { |v| v['stringValue'] }
207+
if attribute_values.nil?
208+
raise Test::Unit::AssertionFailedError.new "Attribute #{attribute} was not found on span #{span_name}"
209+
end
210+
211+
missing_values = expected_values - attribute_values
212+
unless missing_values.empty?
213+
raise Test::Unit::AssertionFailedError.new "Attribute #{attribute} on span #{span_name} is missing values: #{missing_values.join(', ')}"
214+
end
215+
end
216+
end
217+
198218
Then('a span named {string} does not contain the attribute {string}') do |span_name, expected_attribute|
199219
spans = spans_from_request_list(Maze::Server.list_for('traces'))
200220
named_spans = spans.find_all { |span| span['name'].eql?(span_name) }

0 commit comments

Comments
 (0)