diff --git a/Dockerfile b/Dockerfile index 1a3c847..f6e21a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:2.5.1 +FROM ruby:2.5.1-alpine # Fetch/install gems RUN mkdir -p /opt/gems diff --git a/Gemfile b/Gemfile index d104bc9..957e1fb 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,6 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } gem 'bundler', '~> 1.16' gem 'haml' -gem 'nokogiri' group :development, :test do gem 'rake', '~> 10.0' diff --git a/Gemfile.lock b/Gemfile.lock index 604844e..703c39c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,9 +8,6 @@ GEM temple (>= 0.8.0) tilt json (2.1.0) - mini_portile2 (2.3.0) - nokogiri (1.8.2) - mini_portile2 (~> 2.3.0) parallel (1.12.1) parser (2.5.1.0) ast (~> 2.4.0) @@ -53,7 +50,6 @@ PLATFORMS DEPENDENCIES bundler (~> 1.16) haml - nokogiri rake (~> 10.0) rspec (~> 3.0) rubocop diff --git a/lib/test_summary_buildkite_plugin/input.rb b/lib/test_summary_buildkite_plugin/input.rb index 6c567a1..dc722fa 100644 --- a/lib/test_summary_buildkite_plugin/input.rb +++ b/lib/test_summary_buildkite_plugin/input.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true -require 'nokogiri' +# We don't use nokogiri because we use an alpine-based docker image +# And adding the required dependencies triples the size of the image +require 'rexml/document' module TestSummaryBuildkitePlugin module Input @@ -72,7 +74,7 @@ def crop class JUnit < Base def failures_raw - files.map { |file| File.open(file) { |f| Nokogiri::XML(f, nil, encoding) } } + files.map { |file| REXML::Document.new(read(file)) } .map { |xml| xml_to_failures(xml) } .flatten end @@ -80,12 +82,12 @@ def failures_raw private def xml_to_failures(xml) - xml.css('testcase').each_with_object([]) do |testcase, failures| - testcase.css('failure').each do |failure| + xml.elements.enum_for(:each, '*/testcase').each_with_object([]) do |testcase, failures| + testcase.elements.each('failure') do |failure| failures << Failure::Structured.new( - file: testcase['file'], - name: testcase['name'], - details: failure.inner_html + file: testcase.attributes['file'].to_s, + name: testcase.attributes['name'].to_s, + details: failure.text ) end end diff --git a/spec/test_summary_buildkite_plugin/input_spec.rb b/spec/test_summary_buildkite_plugin/input_spec.rb index 3572afb..b1edfca 100644 --- a/spec/test_summary_buildkite_plugin/input_spec.rb +++ b/spec/test_summary_buildkite_plugin/input_spec.rb @@ -66,10 +66,6 @@ expect(input.failures.first.details).to start_with('Failure/Error: ') end - it 'details escape html' do - expect(input.failures.first.details).to include('<') - end - it 'failures have file' do expect(input.failures.first.file).to eq('./spec/lib/url_whitelist_spec.rb') end