2021-11-08 10:13:35 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
return unless ENV['CI']
|
2022-01-05 19:15:57 -05:00
|
|
|
return if ENV['SKIP_FLAKY_TESTS_AUTOMATICALLY'] == "false"
|
2021-11-08 13:09:52 -05:00
|
|
|
return if ENV['CI_MERGE_REQUEST_LABELS'].to_s.include?('pipeline:run-flaky-tests')
|
2021-11-08 10:13:35 -05:00
|
|
|
|
2022-01-25 13:11:55 -05:00
|
|
|
require_relative '../../tooling/rspec_flaky/config'
|
2021-11-17 07:11:55 -05:00
|
|
|
require_relative '../../tooling/rspec_flaky/report'
|
2021-11-08 10:13:35 -05:00
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
$flaky_test_example_ids = begin # rubocop:disable Style/GlobalVars
|
2022-01-25 13:11:55 -05:00
|
|
|
raise "#{RspecFlaky::Config.suite_flaky_examples_report_path} doesn't exist" unless File.exist?(RspecFlaky::Config.suite_flaky_examples_report_path)
|
2021-11-08 10:13:35 -05:00
|
|
|
|
2022-01-25 13:11:55 -05:00
|
|
|
RspecFlaky::Report.load(RspecFlaky::Config.suite_flaky_examples_report_path).map { |_, flaky_test_data| flaky_test_data.to_h[:example_id] }
|
2021-11-08 10:13:35 -05:00
|
|
|
rescue => e # rubocop:disable Style/RescueStandardError
|
|
|
|
puts e
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
$skipped_flaky_tests_report = [] # rubocop:disable Style/GlobalVars
|
|
|
|
|
|
|
|
config.around do |example|
|
|
|
|
# Skip flaky tests automatically
|
|
|
|
if $flaky_test_example_ids.include?(example.id) # rubocop:disable Style/GlobalVars
|
|
|
|
puts "Skipping #{example.id} '#{example.full_description}' because it's flaky."
|
|
|
|
$skipped_flaky_tests_report << example.id # rubocop:disable Style/GlobalVars
|
|
|
|
else
|
|
|
|
example.run
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
config.after(:suite) do
|
2022-01-25 13:11:55 -05:00
|
|
|
next unless RspecFlaky::Config.skipped_flaky_tests_report_path
|
|
|
|
next if $skipped_flaky_tests_report.empty? # rubocop:disable Style/GlobalVars
|
2021-11-08 10:13:35 -05:00
|
|
|
|
2022-01-25 13:11:55 -05:00
|
|
|
File.write(RspecFlaky::Config.skipped_flaky_tests_report_path, "#{ENV['CI_JOB_URL']}\n#{$skipped_flaky_tests_report.join("\n")}\n\n") # rubocop:disable Style/GlobalVars
|
2021-11-08 10:13:35 -05:00
|
|
|
end
|
|
|
|
end
|