Skip to content

Commit

Permalink
Merge pull request #209 from buildkite/pie-2103-add-signifier-to-link…
Browse files Browse the repository at this point in the history
…-outputs

Add signifier to link outputs
  • Loading branch information
meghan-kradolfer authored Nov 7, 2023
2 parents ed97b1f + 18ce880 commit b160a8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/buildkite/test_collector/library_hooks/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

require_relative "../rspec_plugin/reporter"
require_relative "../rspec_plugin/trace"
require_relative "../test_links_plugin/reporter"
require_relative "../test_links_plugin/formatter"

Buildkite::TestCollector.uploader = Buildkite::TestCollector::Uploader

RSpec.configure do |config|
config.before(:suite) do
config.add_formatter Buildkite::TestCollector::RSpecPlugin::Reporter
config.add_formatter Buildkite::TestCollector::TestLinksPlugin::Reporter
config.add_formatter Buildkite::TestCollector::TestLinksPlugin::Formatter
end

config.around(:each) do |example|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Buildkite::TestCollector::TestLinksPlugin
class Reporter
class Formatter
RSpec::Core::Formatters.register self, :dump_failures

def initialize(output)
Expand All @@ -23,7 +23,9 @@ def dump_failures(notification)
# return if suite url is nil
return if metadata['suite_url'].nil?

@output << "\n\nTest Analytics failures:\n\n"
@output << "\n\n🔥 \x1b[31mTest Analytics failures 🔥\n"
@output << '_____________________________'
@output << "\n\n"

@output << notification.failed_examples.map do |example|
failed_example_output(example, metadata['suite_url'])
Expand All @@ -43,7 +45,7 @@ def failed_example_output(example, url)
name = example.description
scope_name_digest = generate_scope_name_digest(scope, name)
test_url = "#{url}/tests/#{scope_name_digest}"
"\x1b[31m#{%(\x1b]1339;url=#{test_url};content="#{scope} #{name}"\x07)}\x1b[0m"
"🔗 \x1b[4m\x1b[37m#{%(\x1b]1339;url=#{test_url};content="#{scope} #{name}"\x07)}\x1b[m"
end

def fetch_metadata
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# frozen_string_literal: true

require 'buildkite/test_collector/test_links_plugin/reporter'
require 'buildkite/test_collector/test_links_plugin/formatter'

RSpec.describe Buildkite::TestCollector::TestLinksPlugin::Reporter do
RSpec.describe Buildkite::TestCollector::TestLinksPlugin::Formatter do
let(:passed_example) { fake_example(status: :passed) }
let(:http_client) { double('Buildkite::TestCollector::HTTPClient') }
let(:suite_url) { 'https://example.com/suite/12345' }
let(:response) { { suite_url: suite_url }.to_json }
let(:io) { StringIO.new }
let(:reporter) { Buildkite::TestCollector::TestLinksPlugin::Reporter.new(io) }
let(:formatter) { Buildkite::TestCollector::TestLinksPlugin::Formatter.new(io) }

before do
allow(Buildkite::TestCollector::HTTPClient).to receive(:new).and_return(http_client)
Expand Down Expand Up @@ -36,12 +36,12 @@
end

it 'does not render summary' do
reporter.dump_failures(notification)
formatter.dump_failures(notification)
expect(io.string.strip).to be_empty
end

it 'does not request metadata' do
reporter.dump_failures(notification)
formatter.dump_failures(notification)
expect(Buildkite::TestCollector::HTTPClient).not_to receive(:new)
end
end
Expand All @@ -50,7 +50,7 @@
it 'does not render summary' do
allow(http_client).to receive(:metadata)
.and_return(OpenStruct.new(code: '200', body: { suite_url: nil }.to_json))
reporter.dump_failures(notification)
formatter.dump_failures(notification)

expect(io.string.strip).to be_empty
end
Expand All @@ -59,7 +59,7 @@
context 'fetch_metadata throws an error' do
it 'does not render summary' do
allow(http_client).to receive(:metadata).and_return(StandardError)
reporter.dump_failures(notification)
formatter.dump_failures(notification)

expect(io.string.strip).to be_empty
end
Expand All @@ -68,7 +68,7 @@
context 'fetch_metadata has a non 200 response' do
it 'does not render summary' do
allow(http_client).to receive(:metadata).and_return(OpenStruct.new(code: '500', body: response))
reporter.dump_failures(notification)
formatter.dump_failures(notification)

# dump_failures should not out put anything
expect(io.string.strip).to be_empty
Expand All @@ -82,9 +82,9 @@
scope_name_digest = Digest::SHA256.hexdigest(scope + name)

allow(http_client).to receive(:metadata).and_return(OpenStruct.new(code: '200', body: response))
reporter.dump_failures(notification)
formatter.dump_failures(notification)

expect(io.string.strip).to include('Test Analytics failures:')
expect(io.string.strip).to include('Test Analytics failures')
expect(io.string.strip).to include("#{suite_url}/tests/#{scope_name_digest}")
expect(io.string.strip).to include("#{scope} #{name}")
end
Expand All @@ -97,7 +97,7 @@
end

before do
reporter.dump_failures(notification)
formatter.dump_failures(notification)
end

it 'does not render summary' do
Expand Down

0 comments on commit b160a8b

Please sign in to comment.