Add ability to define formatter file name and path.
This commit is contained in:
parent
412ed0d1c1
commit
acae702c45
|
@ -25,7 +25,7 @@ else
|
|||
worker.max_requeues = config.max_requeues
|
||||
worker.queue_wait_timeout = config.queue_wait_timeout
|
||||
worker.fail_fast = config.fail_fast
|
||||
worker.output_junit = config.output_junit
|
||||
worker.junit_formatter = config.junit_formatter
|
||||
worker.seed = config.seed if config.seed
|
||||
worker.reproduction = config.reproduction
|
||||
worker.work
|
||||
|
|
|
@ -3,14 +3,15 @@ require "rspec_junit_formatter"
|
|||
module RSpecQ
|
||||
module Formatters
|
||||
# Junit output formatter that handles outputting of requeued examples,
|
||||
# the multiple suites per rspecq run.
|
||||
# parallel gem, and multiple suites per rspecq run.
|
||||
class JUnitFormatter < RSpecJUnitFormatter
|
||||
def initialize(queue, job, max_requeues, job_index)
|
||||
def initialize(queue, job, max_requeues, job_index, path)
|
||||
@queue = queue
|
||||
@job = job
|
||||
@max_requeues = max_requeues
|
||||
@requeued_examples = []
|
||||
path = "test_results/results-#{ENV['TEST_ENV_NUMBER']}-#{job_index}.xml"
|
||||
path = path.gsub(/{{TEST_ENV_NUMBER}}/,ENV["TEST_ENV_NUMBER"].to_s)
|
||||
path = path.gsub(/{{JOB_INDEX}}/, job_index.to_s)
|
||||
RSpec::Support::DirectoryMaker.mkdir_p(File.dirname(path))
|
||||
output_file = File.new(path, "w")
|
||||
super(output_file)
|
||||
|
@ -35,7 +36,7 @@ module RSpecQ
|
|||
|
||||
def examples
|
||||
@examples_notification.notifications.reject do |example_notification|
|
||||
@requeued_examples.include?(example_notification.example)
|
||||
@requeued_examples.map(&:id).include?(example_notification.example.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -131,9 +131,9 @@ module RSpecQ
|
|||
opts[:reproduction] = v
|
||||
end
|
||||
|
||||
o.on("--output-junit", "Output junit formatted xml " \
|
||||
"for CI suites.") do |v|
|
||||
opts[:output_junit] = v
|
||||
o.on("--junit-formatter filepath", String, "Output junit formatted xml " \
|
||||
"for CI suites to the defined file path.") do |v|
|
||||
opts[:junit_formatter] = v
|
||||
end
|
||||
|
||||
o.on_tail("-h", "--help", "Show this message.") do
|
||||
|
@ -162,7 +162,7 @@ module RSpecQ
|
|||
opts[:redis_url] ||= ENV["RSPECQ_REDIS_URL"]
|
||||
opts[:fail_fast] ||= Integer(ENV["RSPECQ_FAIL_FAST"] || DEFAULT_FAIL_FAST)
|
||||
opts[:reproduction] ||= env_set?("RSPECQ_REPRODUCTION")
|
||||
opts[:output_junit] ||= env_set?("RSPECQ_OUTPUT_JUNIT")
|
||||
opts[:junit_formatter] ||= ENV["RSPECQ_JUNIT_FORMATTER"]
|
||||
end
|
||||
|
||||
def env_set?(var)
|
||||
|
|
|
@ -60,9 +60,13 @@ module RSpecQ
|
|||
|
||||
# Include a suite counter in any output filenames so that each suite run
|
||||
# Output Junit formatted XML
|
||||
# Output Junit formatted XML to a specifiedd file
|
||||
#
|
||||
# Defaults to false
|
||||
attr_accessor :output_junit
|
||||
# Example: test_results/results-{{TEST_ENV_NUMBER}}-{{JOB_INDEX}}.xml
|
||||
# where TEST_ENV_NUMBER is substituted with the environment variable
|
||||
# from the gem parallel test, and JOB_INDEX is incremented based
|
||||
# on the number of test suites run in the current process.
|
||||
attr_accessor :junit_formatter
|
||||
|
||||
# Optional arguments to pass along to rspec.
|
||||
#
|
||||
|
@ -84,7 +88,7 @@ module RSpecQ
|
|||
@queue_wait_timeout = 30
|
||||
@seed = srand && srand % 0xFFFF
|
||||
@reproduction = false
|
||||
@output_junit = false
|
||||
@junit_formatter = nil
|
||||
|
||||
RSpec::Core::Formatters.register(Formatters::JobTimingRecorder, :dump_summary)
|
||||
RSpec::Core::Formatters.register(Formatters::ExampleCountRecorder, :dump_summary)
|
||||
|
@ -130,8 +134,9 @@ module RSpecQ
|
|||
RSpec.configuration.backtrace_formatter.filter_gem("rspecq")
|
||||
RSpec.configuration.add_formatter(Formatters::FailureRecorder.new(queue, job, max_requeues, @worker_id))
|
||||
|
||||
if output_junit
|
||||
RSpec.configuration.add_formatter(Formatters::JUnitFormatter.new(queue, job, max_requeues, idx))
|
||||
if junit_formatter
|
||||
RSpec.configuration.add_formatter(Formatters::JUnitFormatter.new(queue, job, max_requeues,
|
||||
idx, junit_formatter))
|
||||
end
|
||||
|
||||
RSpec.configuration.add_formatter(Formatters::ExampleCountRecorder.new(queue))
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
require "test_helpers"
|
||||
|
||||
class TestEndToEnd < RSpecQTest
|
||||
def after_teardown
|
||||
Dir["./test/sample_suites/flakey_suite/test/test_results/**/*"].each do |file|
|
||||
File.delete(file)
|
||||
end
|
||||
end
|
||||
|
||||
def test_suite_with_legit_failures
|
||||
queue = exec_build("failing_suite")
|
||||
|
||||
|
@ -129,4 +135,29 @@ class TestEndToEnd < RSpecQTest
|
|||
|
||||
assert_includes [2, 3], queue.processed_jobs.length
|
||||
end
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
def test_suite_with_rspec_arguments
|
||||
queue = exec_build("tagged_suite", "-- --tag foo")
|
||||
|
||||
assert_equal 1, queue.example_count
|
||||
end
|
||||
|
||||
def test_suite_with_junit_formatter
|
||||
queue = exec_build("flakey_suite",
|
||||
"--junit-formatter test/test_results/test.{{JOB_INDEX}}.xml")
|
||||
|
||||
assert queue.build_successful?
|
||||
assert_processed_jobs [
|
||||
"./spec/foo_spec.rb",
|
||||
"./spec/foo_spec.rb[1:1]",
|
||||
], queue
|
||||
|
||||
assert_equal({ "./spec/foo_spec.rb[1:1]" => "2" }, queue.requeued_jobs)
|
||||
assert File.exist?("test/sample_suites/flakey_suite/test/test_results/test.0.xml")
|
||||
assert File.exist?("test/sample_suites/flakey_suite/test/test_results/test.1.xml")
|
||||
assert File.exist?("test/sample_suites/flakey_suite/test/test_results/test.2.xml")
|
||||
end
|
||||
>>>>>>> 74202f3... Add ability to define formatter file name and path.
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue