buildkite-test_collector 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 497ced90aac96227b8e4d2fc9ad1685eb4f554742b597568efa7e0f8bb1a0879
4
- data.tar.gz: 709f96eaa2af7732b73c2838862bb98f350e9f8cda5aa7e209b00e96e00ab127
3
+ metadata.gz: 423b9692a49e1cea2d180d684f9f54c82a6fd84289087efe256cf4a2d1dd5f4b
4
+ data.tar.gz: 7ec78a72fb4506ee301b44f2830adfc22c83eb0508cab3ef7d455ec4a1f3049a
5
5
  SHA512:
6
- metadata.gz: d559f0b297b7402a3f57203ea6226ee861b81b72682896c8a49d13ecaa036ca6ba6b3cf6b22e5693d0de8133500b4dd0b84a10db171d17c93237a0d2873e2704
7
- data.tar.gz: e6d23fe2be97f26f4c1f753585340220d46ea926ed490878a4b02627b3488da57a859a1e3948796e84055dce99d01380e60ca77e96c33970c03ba38683259b7c
6
+ metadata.gz: dcf9a81dd2c1b74f8241c22ea94aff3dc75a9c1190afda0b12d4c2ac06bd79b89694fcee5d43a07a051864d404e140cf665064778dbb5d73b389abbba28af1ec
7
+ data.tar.gz: eb43eb66820451723296546c70b3b2fc7b63572aa393ae4ea2380bb8e195e7faa0c6e8b7eff56c04a70223585c55162872a82d647a7a4d74e8cfe7ffa7cad3c6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v2.11.0
4
+
5
+ * Add `location_prefix` option. Allows a file name prefix to be set which will be prepended to `file_name` and `location` in the test results.
6
+
7
+ **Full Changelog**: https://github.com/buildkite/test-collector-ruby/compare/v2.10.0...v2.11.0
8
+
3
9
  ## v2.10.0
4
10
 
5
11
  * Add support for Cucumber
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- buildkite-test_collector (2.10.0)
4
+ buildkite-test_collector (2.11.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -113,17 +113,15 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/buildk
113
113
  ## 🚀 Releasing
114
114
 
115
115
  1. Bump the version in `version.rb` and run `bundle` to update the `Gemfile.lock`.
116
- 1. Update the CHANGELOG.md with your new version and a description of your changes.
116
+ 2. Update the CHANGELOG.md with your new version and a description of your changes.
117
+ 3. Once your PR is merged to `main` git tag the merge commit and push:
117
118
 
118
- Once your PR is merged to `main`:
119
-
120
- 1. Git tag the merge commit and push
121
119
  ```
122
120
  git tag vX.X.X
123
121
  git push origin vX.X.X
124
122
  ```
125
- 1. Visit the [release pipeline](https://buildkite.com/buildkite/test-collector-ruby-release) to unblock it and confirm the new version is pushed to rubygems.org
126
- 1. Create a [new release in github](https://github.com/buildkite/test-collector-ruby/releases).
123
+ 4. Visit the [release pipeline](https://buildkite.com/buildkite/test-collector-ruby-release) to unblock it and confirm the new version is pushed to rubygems.org
124
+ 5. Create a [new release in github](https://github.com/buildkite/test-collector-ruby/releases).
127
125
 
128
126
  ## 📜 MIT License
129
127
 
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Buildkite::TestCollector::CucumberPlugin
4
- class Trace
4
+ class Trace < Buildkite::TestCollector::Trace
5
5
  attr_accessor :scenario, :failure_reason, :failure_expanded
6
- attr_reader :history, :tags
6
+ attr_reader :history, :tags, :location_prefix
7
7
 
8
8
  FILE_PATH_REGEX = /^(.*?\.(rb|feature))/
9
9
 
10
- def initialize(scenario, history:, failure_reason: nil, failure_expanded: [], tags: nil)
10
+ def initialize(scenario, history:, failure_reason: nil, failure_expanded: [], tags: nil, location_prefix: nil)
11
11
  @scenario = scenario
12
12
  @history = history
13
13
  @failure_reason = failure_reason
14
14
  @failure_expanded = failure_expanded
15
15
  @tags = tags
16
+ @location_prefix = location_prefix
16
17
  end
17
18
 
18
19
  def result
@@ -25,41 +26,30 @@ module Buildkite::TestCollector::CucumberPlugin
25
26
  end
26
27
  end
27
28
 
28
- def as_hash
29
- parser = Gherkin::Parser.new
30
- document = parser.parse(File.read(file_name))
31
- feature_name = document.feature.name
29
+ private
32
30
 
33
- strip_invalid_utf8_chars(
34
- scope: feature_name,
35
- name: scenario.name,
36
- location: scenario.location&.to_s,
37
- file_name: file_name,
38
- result: result,
39
- failure_reason: failure_reason,
40
- failure_expanded: failure_expanded,
41
- history: history,
42
- tags: tags,
43
- ).select { |_, v| !v.nil? }
31
+ def gherkin_parser
32
+ @gherkin_parser ||= Gherkin::Parser.new
44
33
  end
45
34
 
46
- private
35
+ def document
36
+ @document ||= gherkin_parser.parse(File.read(file_name))
37
+ end
47
38
 
48
- def file_name
49
- @file_name ||= scenario.location&.to_s[FILE_PATH_REGEX]
39
+ def scope
40
+ document.feature.name
50
41
  end
51
42
 
52
- def strip_invalid_utf8_chars(object)
53
- case object
54
- when Hash
55
- object.transform_values { |v| strip_invalid_utf8_chars(v) }
56
- when Array
57
- object.map { |v| strip_invalid_utf8_chars(v) }
58
- when String
59
- object.encode('UTF-8', invalid: :replace, undef: :replace)
60
- else
61
- object
62
- end
43
+ def name
44
+ scenario.name
45
+ end
46
+
47
+ def location
48
+ scenario.location&.to_s
49
+ end
50
+
51
+ def file_name
52
+ @file_name ||= location&.to_s[FILE_PATH_REGEX]
63
53
  end
64
54
  end
65
55
  end
@@ -52,6 +52,7 @@ After do |scenario|
52
52
  failure_reason: failure_reason,
53
53
  failure_expanded: failure_expanded,
54
54
  tags: tags,
55
+ location_prefix: Buildkite::TestCollector.location_prefix,
55
56
  )
56
57
 
57
58
  Buildkite::TestCollector.uploader.traces[scenario.location.to_s] = trace
@@ -37,6 +37,7 @@ RSpec.configure do |config|
37
37
  example,
38
38
  history: tracer.history,
39
39
  tags: tags,
40
+ location_prefix: Buildkite::TestCollector.location_prefix
40
41
  )
41
42
 
42
43
  Buildkite::TestCollector.uploader.traces[example.id] = trace
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Buildkite::TestCollector::MinitestPlugin
4
- class Trace
4
+ class Trace < Buildkite::TestCollector::Trace
5
5
  attr_accessor :example
6
6
  attr_writer :failure_reason, :failure_expanded
7
7
  attr_reader :history
8
+ attr_reader :location_prefix
8
9
  attr_reader :tags
9
10
 
10
11
  RESULT_CODES = {
@@ -16,10 +17,11 @@ module Buildkite::TestCollector::MinitestPlugin
16
17
 
17
18
  FILE_PATH_REGEX = /^(.*?\.(rb|feature))/
18
19
 
19
- def initialize(example, history:, tags: nil)
20
+ def initialize(example, history:, tags: nil, trace: nil, location_prefix: nil)
20
21
  @example = example
21
22
  @history = history
22
23
  @tags = tags
24
+ @location_prefix = location_prefix
23
25
  end
24
26
 
25
27
  def result
@@ -30,21 +32,15 @@ module Buildkite::TestCollector::MinitestPlugin
30
32
  @source_location ||= example.method(example.name).source_location
31
33
  end
32
34
 
33
- def as_hash
34
- strip_invalid_utf8_chars(
35
- scope: example.class.name,
36
- name: example.name,
37
- location: location,
38
- file_name: file_name,
39
- result: result,
40
- failure_reason: failure_reason,
41
- failure_expanded: failure_expanded,
42
- history: history,
43
- tags: tags,
44
- ).select { |_, value| !value.nil? }
35
+ private
36
+
37
+ def scope
38
+ example.class.name
45
39
  end
46
40
 
47
- private
41
+ def name
42
+ example.name
43
+ end
48
44
 
49
45
  def location
50
46
  if file_name
@@ -85,17 +81,5 @@ module Buildkite::TestCollector::MinitestPlugin
85
81
  }
86
82
  end
87
83
  end
88
-
89
- def strip_invalid_utf8_chars(object)
90
- if object.is_a?(Hash)
91
- Hash[object.map { |key, value| [key, strip_invalid_utf8_chars(value)] }]
92
- elsif object.is_a?(Array)
93
- object.map { |value| strip_invalid_utf8_chars(value) }
94
- elsif object.is_a?(String)
95
- object.encode('UTF-8', :invalid => :replace, :undef => :replace)
96
- else
97
- object
98
- end
99
- end
100
84
  end
101
85
  end
@@ -35,6 +35,7 @@ module Buildkite::TestCollector::MinitestPlugin
35
35
  self,
36
36
  history: tracer.history,
37
37
  tags: tags,
38
+ location_prefix: Buildkite::TestCollector.location_prefix
38
39
  )
39
40
 
40
41
  Buildkite::TestCollector.uploader.traces[trace.source_location] = trace
@@ -1,19 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Buildkite::TestCollector::RSpecPlugin
4
- class Trace
4
+ class Trace < Buildkite::TestCollector::Trace
5
5
  attr_accessor :example, :failure_reason, :failure_expanded
6
6
  attr_reader :history
7
7
  attr_reader :tags
8
+ attr_reader :location_prefix
8
9
 
9
10
  FILE_PATH_REGEX = /^(.*?\.(rb|feature))/
10
11
 
11
- def initialize(example, history:, failure_reason: nil, failure_expanded: [], tags: nil)
12
+ def initialize(example, history:, failure_reason: nil, failure_expanded: [], tags: nil, location_prefix: nil)
12
13
  @example = example
13
14
  @history = history
14
15
  @failure_reason = failure_reason
15
16
  @failure_expanded = failure_expanded
16
17
  @tags = tags
18
+ @location_prefix = location_prefix
17
19
  end
18
20
 
19
21
  def result
@@ -24,21 +26,19 @@ module Buildkite::TestCollector::RSpecPlugin
24
26
  end
25
27
  end
26
28
 
27
- def as_hash
28
- strip_invalid_utf8_chars(
29
- scope: example.example_group.metadata[:full_description],
30
- name: example.description,
31
- location: example.location,
32
- file_name: file_name,
33
- result: result,
34
- failure_reason: failure_reason,
35
- failure_expanded: failure_expanded,
36
- history: history,
37
- tags: tags,
38
- ).select { |_, value| !value.nil? }
29
+ private
30
+
31
+ def scope
32
+ example.example_group.metadata[:full_description]
39
33
  end
40
34
 
41
- private
35
+ def name
36
+ example.description
37
+ end
38
+
39
+ def location
40
+ example.location
41
+ end
42
42
 
43
43
  def file_name
44
44
  @file_name ||= begin
@@ -69,17 +69,5 @@ module Buildkite::TestCollector::RSpecPlugin
69
69
  def shared_example_call_location
70
70
  example.metadata[:shared_group_inclusion_backtrace].last.inclusion_location
71
71
  end
72
-
73
- def strip_invalid_utf8_chars(object)
74
- if object.is_a?(Hash)
75
- Hash[object.map { |key, value| [key, strip_invalid_utf8_chars(value)] }]
76
- elsif object.is_a?(Array)
77
- object.map { |value| strip_invalid_utf8_chars(value) }
78
- elsif object.is_a?(String)
79
- object.encode('UTF-8', :invalid => :replace, :undef => :replace)
80
- else
81
- object
82
- end
83
- end
84
72
  end
85
73
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Buildkite
4
+ module TestCollector
5
+ class Trace
6
+ def as_hash
7
+ strip_invalid_utf8_chars(
8
+ scope: scope,
9
+ name: name,
10
+ location: prepend_location_prefix(location),
11
+ file_name: prepend_location_prefix(file_name),
12
+ result: result,
13
+ failure_reason: failure_reason,
14
+ failure_expanded: failure_expanded,
15
+ history: history,
16
+ tags: tags,
17
+ ).select { |_, value| !value.nil? }
18
+ end
19
+
20
+ private
21
+
22
+ def strip_invalid_utf8_chars(object)
23
+ if object.is_a?(Hash)
24
+ Hash[object.map { |key, value| [key, strip_invalid_utf8_chars(value)] }]
25
+ elsif object.is_a?(Array)
26
+ object.map { |value| strip_invalid_utf8_chars(value) }
27
+ elsif object.is_a?(String)
28
+ object.encode('UTF-8', :invalid => :replace, :undef => :replace)
29
+ else
30
+ object
31
+ end
32
+ end
33
+
34
+ def prepend_location_prefix(file_name)
35
+ return file_name unless file_name && location_prefix
36
+
37
+ Pathname.new(location_prefix).join(
38
+ Pathname.new(file_name)
39
+ ).to_s
40
+ end
41
+ end
42
+ end
43
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Buildkite
4
4
  module TestCollector
5
- VERSION = "2.10.0"
5
+ VERSION = "2.11.0"
6
6
  NAME = "buildkite-test_collector"
7
7
  end
8
8
  end
@@ -20,6 +20,7 @@ require_relative "test_collector/http_client"
20
20
  require_relative "test_collector/uploader"
21
21
  require_relative "test_collector/network"
22
22
  require_relative "test_collector/object"
23
+ require_relative "test_collector/trace"
23
24
  require_relative "test_collector/tracer"
24
25
  require_relative "test_collector/session"
25
26
  require_relative "test_collector/uuid"
@@ -35,6 +36,7 @@ module Buildkite
35
36
  attr_accessor :session
36
37
  attr_accessor :tracing_enabled
37
38
  attr_accessor :artifact_path
39
+ attr_accessor :location_prefix
38
40
  attr_accessor :env
39
41
  attr_accessor :tags
40
42
  attr_accessor :batch_size
@@ -42,15 +44,16 @@ module Buildkite
42
44
  attr_accessor :span_filters
43
45
  end
44
46
 
45
- def self.configure(hook:, token: nil, url: nil, tracing_enabled: true, artifact_path: nil, env: {}, tags: {})
47
+ def self.configure(hook:, token: nil, url: nil, tracing_enabled: true, artifact_path: nil, location_prefix: nil, env: {}, tags: {})
46
48
  if hook.to_sym == :cucumber && Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
47
49
  raise UnsupportedFrameworkError.new("Cucumber is only supported in versions of Ruby >= 2.7")
48
50
  end
49
51
 
50
52
  self.api_token = (token || ENV["BUILDKITE_ANALYTICS_TOKEN"])&.strip
51
- self.url = url || DEFAULT_URL
53
+ self.url = url || ENV["BUILDKITE_ANALYTICS_ENDPOINT"] || DEFAULT_URL
52
54
  self.tracing_enabled = tracing_enabled
53
55
  self.artifact_path = artifact_path
56
+ self.location_prefix = location_prefix || ENV["BUILDKITE_ANALYTICS_LOCATION_PREFIX"]
54
57
  self.env = env
55
58
  self.tags = tags
56
59
  self.batch_size = ENV.fetch("BUILDKITE_ANALYTICS_UPLOAD_BATCH_SIZE") { DEFAULT_UPLOAD_BATCH_SIZE }.to_i
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildkite-test_collector
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Buildkite
@@ -105,6 +105,7 @@ files:
105
105
  - lib/buildkite/test_collector/rspec_plugin/reporter.rb
106
106
  - lib/buildkite/test_collector/rspec_plugin/trace.rb
107
107
  - lib/buildkite/test_collector/session.rb
108
+ - lib/buildkite/test_collector/trace.rb
108
109
  - lib/buildkite/test_collector/tracer.rb
109
110
  - lib/buildkite/test_collector/uploader.rb
110
111
  - lib/buildkite/test_collector/uuid.rb
@@ -130,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  - !ruby/object:Gem::Version
131
132
  version: '0'
132
133
  requirements: []
133
- rubygems_version: 3.6.7
134
+ rubygems_version: 3.6.9
134
135
  specification_version: 4
135
136
  summary: Track test executions and report to Buildkite Test Engine
136
137
  test_files: []