6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/knapsack_pro/test_case_detectors/rspec_test_example_detector.rb', line 6
def generate_json_report(rspec_args)
raise "The internal KNAPSACK_PRO_RSPEC_OPTIONS environment variable is unset. Ensure it is not overridden accidentally. Otherwise, please report this as a bug: #{KnapsackPro::Urls::SUPPORT}" if rspec_args.nil?
require 'rspec/core'
cli_format =
if Gem::Version.new(::RSpec::Core::Version::STRING) < Gem::Version.new('3.6.0')
require_relative '../formatters/rspec_json_formatter'
['--format', KnapsackPro::Formatters::RSpecJsonFormatter.to_s]
else
['--format', 'json']
end
ensure_report_dir_exists
remove_old_json_report
test_file_entities = slow_test_files
if test_file_entities.empty?
no_examples_json = { examples: [] }.to_json
File.write(report_path, no_examples_json)
return
end
args = (rspec_args || '').split
cli_args_without_formatters = KnapsackPro::Adapters::RSpecAdapter.remove_formatters(args)
cli_args = cli_args_without_formatters + cli_format + [
'--dry-run',
'--out', report_path,
'--default-path', test_dir
] + KnapsackPro::TestFilePresenter.paths(test_file_entities)
exit_code = begin
options = ::RSpec::Core::ConfigurationOptions.new(cli_args)
::RSpec::Core::Runner.new(options).run($stderr, $stdout)
rescue SystemExit => e
e.status
end
return if exit_code.zero?
report.fetch('messages', []).each { |message| puts message }
command = (['bundle exec rspec'] + cli_args).join(' ')
KnapsackPro.logger.error("Failed to generate the slow test files report: #{command}")
exit exit_code
end
|