knapsack_pro 3.2.0 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5baae9cb1ea264d73e085e9f475b4f775e06801992ffd715f33a90fc93fd974f
4
- data.tar.gz: e74b748147d57817546675c86ea534274f65cf287e52884d3960f09aa44efbb7
3
+ metadata.gz: 11036d33c04d07966ab4acadc55b1fb20a885b0e9b0d78fc8cf03fe798b7c3bf
4
+ data.tar.gz: 8ddfce179b4f7fce9bd28ae965bf15bec132b26b217326d5ce156e94e21cb145
5
5
  SHA512:
6
- metadata.gz: 8f6102eef985cb8cb6c810053be5afecefcf309eb6a8367e3bcacdde09fb6bd10aa8d6ea10f68cdcdaf9b02a83117f2720ba6613562183c1ec9d52751ca87d56
7
- data.tar.gz: b8c3d75e4267141135723fd29de4d5b97dffc1485dc762d7a9df0ba449c0827fa184261ffc101435b94678a7fc89bc8ed75876937a96d90ee6fd6103d7e38362
6
+ metadata.gz: 4c27910d9850ad2d229864dac8b07cb17d9d23a9bd2d14aa05052b6e95a3e218667b32fb40f711324651d2bcd6ee8d180fc7d743ba5cd3b990908ab05d5c57de
7
+ data.tar.gz: a868ac3c2ef9c1fdefc655b2dbb59c8034cc21101717be46400fdeec087bd99c62c43c5357fbba1eccfe8a8cc23b032ee1e9e8eb14e75304357ccbe6a179a32b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Change Log
2
2
 
3
+ ### 3.3.1
4
+
5
+ * Skip loading a test file path for Minitest in Queue Mode when it does not exist on the disk
6
+
7
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/174
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v3.3.0...v3.3.1
10
+
11
+ ### 3.3.0
12
+
13
+ * Show a JSON report file content when RSpec fails during a dry run
14
+
15
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/172
16
+
17
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v3.2.1...v3.3.0
18
+
19
+ ### 3.2.1
20
+
21
+ * Raise exception when using `:focus` tag to avoid skipping RSpec tests
22
+
23
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/167
24
+
25
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v3.2.0...v3.2.1
26
+
3
27
  ### 3.2.0
4
28
 
5
29
  * Add an error message to `KnapsackPro::Adapters::RspecAdapter#bind`
@@ -62,6 +62,10 @@ module KnapsackPro
62
62
  current_test_path
63
63
  end
64
64
 
65
+ if example.metadata[:focus] && KnapsackPro::Adapters::RSpecAdapter.rspec_configuration.filter.rules[:focus]
66
+ raise "We detected a test file path #{current_test_path} with a test using the metadata `:focus` tag. RSpec might not run some tests in the Queue Mode (causing random tests skipping problem). Please remove the `:focus` tag from your codebase. See more: https://knapsackpro.com/faq/question/rspec-is-not-running-some-tests"
67
+ end
68
+
65
69
  example.run
66
70
  end
67
71
 
@@ -95,6 +99,14 @@ module KnapsackPro
95
99
  end
96
100
  end
97
101
  end
102
+
103
+ private
104
+
105
+ # Hide RSpec configuration so that we could mock it in the spec.
106
+ # Mocking existing RSpec configuration could impact test's runtime.
107
+ def self.rspec_configuration
108
+ ::RSpec.configuration
109
+ end
98
110
  end
99
111
 
100
112
  # This is added to provide backwards compatibility
@@ -91,7 +91,13 @@ module KnapsackPro
91
91
 
92
92
  def self.minitest_run(runner, test_file_paths, args)
93
93
  test_file_paths.each do |test_file_path|
94
- require "./#{test_file_path}"
94
+ relative_test_file_path = "./#{test_file_path}"
95
+
96
+ if File.exist?(relative_test_file_path)
97
+ require relative_test_file_path
98
+ else
99
+ KnapsackPro.logger.warn("Skip loading the #{relative_test_file_path} test file path because it does not exist on the disk. Most likely, the test file path should not be loaded. The test file path could have been recorded during the previous CI build when the knapsack_pro gem could not attribute the execution time of a test to a correct test file path. For instance, you have shared examples in your test suite, and the knapsack_pro gem could not correctly determine for which test file path they were executed. In such a case, the test file path should not be loaded because the actual test cases will be executed by loading a correct test file path. You can ignore this warning.")
100
+ end
95
101
  end
96
102
 
97
103
  # duplicate args because Minitest modifies args
@@ -36,11 +36,19 @@ module KnapsackPro
36
36
  ] + cli_args).join(' ')
37
37
 
38
38
  KnapsackPro.logger.error('-'*10 + ' START of actionable error message ' + '-'*50)
39
- KnapsackPro.logger.error('There was a problem while generating test examples for the slow test files using the RSpec dry-run flag. To reproduce the error triggered by the RSpec, please try to run below command (this way, you can find out what is causing the error):')
39
+ KnapsackPro.logger.error('RSpec (with a dry-run option) had a problem generating the report with test examples for the slow test files. Here is what you can do:')
40
+
41
+ KnapsackPro.logger.error("a) Please look for an error message from RSpec in the output above or below. If you don't see anything, that is fine. Sometimes RSpec does not produce any errors in the output.")
42
+
43
+ KnapsackPro.logger.error("b) Check if RSpec generated the report file #{report_path}. If the report exists, it may contain an error message. Here is a preview of the report file:")
44
+ KnapsackPro.logger.error(report_content || 'N/A')
45
+
46
+ KnapsackPro.logger.error('c) To reproduce the error manually, please run the following RSpec command. This way, you can find out what is causing the error. Please ensure you run the command in the same environment where the error occurred. For instance, if the error happens on the CI server, you should run the command in the CI environment:')
40
47
  KnapsackPro.logger.error(debug_cmd)
48
+
41
49
  KnapsackPro.logger.error('-'*10 + ' END of actionable error message ' + '-'*50)
42
50
 
43
- raise 'There was a problem while generating test examples for the slow test files. Please read actionable error message above.'
51
+ raise 'There was a problem while generating test examples for the slow test files. Please read the actionable error message above.'
44
52
  end
45
53
  end
46
54
 
@@ -75,6 +83,10 @@ module KnapsackPro
75
83
  "#{report_dir}/rspec_dry_run_json_report_node_#{KnapsackPro::Config::Env.ci_node_index}.json"
76
84
  end
77
85
 
86
+ def report_content
87
+ File.read(report_path) if File.exist?(report_path)
88
+ end
89
+
78
90
  def adapter_class
79
91
  KnapsackPro::Adapters::RSpecAdapter
80
92
  end
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '3.2.0'
2
+ VERSION = '3.3.1'
3
3
  end
@@ -175,7 +175,35 @@ describe KnapsackPro::Adapters::RSpecAdapter do
175
175
  let(:logger) { instance_double(Logger) }
176
176
  let(:global_time) { 'Global time: 01m 05s' }
177
177
  let(:test_path) { 'spec/a_spec.rb' }
178
- let(:current_example) { double }
178
+ let(:current_example) { double(metadata: {}) }
179
+
180
+ context "when the example's metadata has :focus tag AND RSpec inclusion rule includes :focus" do
181
+ let(:current_example) { double(metadata: { focus: true }) }
182
+
183
+ it do
184
+ expect(KnapsackPro::Config::Env).to receive(:rspec_split_by_test_examples?).and_return(false)
185
+
186
+ expect(config).to receive(:prepend_before).with(:context).and_yield
187
+
188
+ allow(KnapsackPro).to receive(:tracker).and_return(tracker)
189
+ expect(tracker).to receive(:start_timer).ordered
190
+
191
+ expect(config).to receive(:around).with(:each).and_yield(current_example)
192
+ expect(::RSpec).to receive(:configure).and_yield(config)
193
+
194
+ expect(tracker).to receive(:stop_timer).ordered
195
+
196
+ expect(described_class).to receive(:test_path).with(current_example).and_return(test_path)
197
+
198
+ expect(tracker).to receive(:current_test_path=).with(test_path).ordered
199
+
200
+ expect(described_class).to receive_message_chain(:rspec_configuration, :filter, :rules, :[]).with(:focus).and_return(true)
201
+
202
+ expect {
203
+ subject.bind_time_tracker
204
+ }.to raise_error /We detected a test file path spec\/a_spec\.rb with a test using the metadata `:focus` tag/
205
+ end
206
+ end
179
207
 
180
208
  context 'when rspec split by test examples is disabled' do
181
209
  before do
@@ -100,7 +100,7 @@ describe KnapsackPro::Runners::Queue::MinitestRunner do
100
100
  end
101
101
 
102
102
  context 'when test files exist' do
103
- let(:test_file_paths) { ['a_test.rb', 'b_test.rb'] }
103
+ let(:test_file_paths) { ['a_test.rb', 'b_test.rb', 'fake_path_test.rb'] }
104
104
 
105
105
  before do
106
106
  subset_queue_id = 'fake-subset-queue-id'
@@ -114,8 +114,12 @@ describe KnapsackPro::Runners::Queue::MinitestRunner do
114
114
  expect(tracker).to receive(:set_prerun_tests).with(test_file_paths)
115
115
 
116
116
  # .minitest_run
117
+ expect(File).to receive(:exist?).with('./a_test.rb').and_return(true)
118
+ expect(File).to receive(:exist?).with('./b_test.rb').and_return(true)
119
+ expect(File).to receive(:exist?).with('./fake_path_test.rb').and_return(false)
117
120
  expect(described_class).to receive(:require).with('./a_test.rb')
118
121
  expect(described_class).to receive(:require).with('./b_test.rb')
122
+ expect(described_class).to_not receive(:require).with('./fake_path_test.rb')
119
123
 
120
124
  expect(Minitest).to receive(:run).with(args).and_return(is_tests_green)
121
125
 
@@ -11,7 +11,7 @@ describe KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector do
11
11
 
12
12
  expect(FileUtils).to receive(:mkdir_p).with(report_dir)
13
13
 
14
- expect(File).to receive(:exist?).with(report_path).and_return(true)
14
+ expect(File).to receive(:exist?).at_least(:once).with(report_path).and_return(true)
15
15
  expect(File).to receive(:delete).with(report_path)
16
16
 
17
17
  expect(rspec_test_example_detector).to receive(:slow_test_files).and_return(test_file_entities)
@@ -68,8 +68,15 @@ describe KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector do
68
68
  context 'when exit code from RSpec::Core::Runner is 1' do
69
69
  let(:exit_code) { 1 }
70
70
 
71
+ before do
72
+ json_file = %{
73
+ {"version":"3.11.0","messages":["An error occurred while loading ./spec/a_spec.rb"],"examples":[],"summary":{"duration":3.6e-05,"example_count":0,"failure_count":0,"pending_count":0,"errors_outside_of_examples_count":1},"summary_line":"0 examples, 0 failures, 1 error occurred outside of examples"}
74
+ }.strip
75
+ expect(File).to receive(:read).with(report_path).and_return(json_file)
76
+ end
77
+
71
78
  it do
72
- expect { subject }.to raise_error(RuntimeError, 'There was a problem while generating test examples for the slow test files. Please read actionable error message above.')
79
+ expect { subject }.to raise_error(RuntimeError, 'There was a problem while generating test examples for the slow test files. Please read the actionable error message above.')
73
80
  end
74
81
  end
75
82
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-03 00:00:00.000000000 Z
11
+ date: 2022-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -405,7 +405,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
405
405
  - !ruby/object:Gem::Version
406
406
  version: '0'
407
407
  requirements: []
408
- rubygems_version: 3.2.32
408
+ rubygems_version: 3.3.7
409
409
  signing_key:
410
410
  specification_version: 4
411
411
  summary: Knapsack Pro splits tests across parallel CI nodes and ensures each parallel