forking_test_runner 1.6.0 → 1.11.0

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: 15dc01600948f014f33866de176d8d3991f5af044b7dc669a727a064522c8a99
4
- data.tar.gz: 037b27bd86eab3c5a8a9095a5fb9a5a18b48fda7db9f5e2c505452ac6a931a70
3
+ metadata.gz: 310cb4e18cc6ae7699b73ed2ff52b7ace99f4c85ad6d96c57a2e3b26251a9be2
4
+ data.tar.gz: fc42925b1e5c1bc1039b2ef2900e29de0c9dea7494eb69517d13d1b3c3ee0f91
5
5
  SHA512:
6
- metadata.gz: 53176ec4ca09268b4790bfbf438fbd40e1dd85344534cdb3655165114b20a82f355c4863b2e1fc4e18ac8eae5e6ee8aded5353af28d021176b1ba72829b47f0d
7
- data.tar.gz: 5123b3023462d28fe1296b7b902d232f30ef9298104f957b316669c6ecce289f48f0ce1539b5fce3fb42f9c6001ccc2f8b08d01a5c1d278d35da31542597bc5c
6
+ metadata.gz: a37d5ec4d8cde469b487c7bffa9153c030aca524e8a9e91bd1ada13c8cdec6f2be5042588472620d9f39b2234d44470ea26d9b2beb4a3c3f7070d01439c6918a
7
+ data.tar.gz: 15d354d5a8047be55e86df400a6ebed70594e68b25afec6e2fd14cc9b163fd07dbe09a7b1eccd407d06822a13f70e81b1e061601e93eefb0d5af0647cfd34216
@@ -8,6 +8,7 @@ require 'tempfile'
8
8
 
9
9
  module ForkingTestRunner
10
10
  CLEAR = "------"
11
+ CONVERAGE_REPORT_PREFIX = "coverage/fork-"
11
12
 
12
13
  class << self
13
14
  def cli(argv)
@@ -79,6 +80,8 @@ module ForkingTestRunner
79
80
  record_test_runtime(mode, results, log)
80
81
  end
81
82
 
83
+ summarize_partial_reports if partial_reports_for_single_cov?
84
+
82
85
  # exit with success or failure
83
86
  success ? 0 : 1
84
87
  end
@@ -279,7 +282,10 @@ module ForkingTestRunner
279
282
  def run_test(file)
280
283
  stdout = change_program_name_to file do
281
284
  fork_with_captured_stdout do
282
- SimpleCov.pid = Process.pid if defined?(SimpleCov) && SimpleCov.respond_to?(:pid=) # trick simplecov into reporting in this fork
285
+ SimpleCov.pid = Process.pid if defined?(SimpleCov) && SimpleCov.respond_to?(:pid=) # make simplecov report in this fork
286
+ if partial_reports_for_single_cov?
287
+ SingleCov.coverage_report = "#{CONVERAGE_REPORT_PREFIX}#{Process.pid}.json"
288
+ end
283
289
  if active_record?
284
290
  key = (ActiveRecord::VERSION::STRING >= "4.1.0" ? :test : "test")
285
291
  ActiveRecord::Base.establish_connection key
@@ -291,6 +297,10 @@ module ForkingTestRunner
291
297
  [$?.success?, stdout]
292
298
  end
293
299
 
300
+ def partial_reports_for_single_cov?
301
+ @options.fetch(:merge_coverage) && defined?(SingleCov) && SingleCov.respond_to?(:coverage_report=) && SingleCov.coverage_report
302
+ end
303
+
294
304
  def change_program_name_to(name)
295
305
  return yield if @options.fetch(:parallel)
296
306
  begin
@@ -347,9 +357,32 @@ module ForkingTestRunner
347
357
 
348
358
  if value
349
359
  minitest_class.autorun
350
- require(file.start_with?('/') ? file : "./#{file}")
360
+ load file
351
361
  end
352
362
  end
353
363
  end
364
+
365
+ def summarize_partial_reports
366
+ reports = Dir.glob("#{CONVERAGE_REPORT_PREFIX}*")
367
+ return if reports.empty?
368
+ key = nil
369
+
370
+ require "json" # not a global dependency
371
+ coverage = reports.each_with_object({}) do |report, all|
372
+ data = JSON.parse(File.read(report), symbolize_names: true)
373
+ key ||= data.keys.first
374
+ suites = data.values
375
+ raise "Unsupported number of suites #{suites.size}" if suites.size != 1
376
+ all.replace CoverageCapture.merge_coverage(all, suites.first.fetch(:coverage))
377
+ ensure
378
+ File.unlink(report) # do not leave junk behind
379
+ end
380
+
381
+ data = JSON.pretty_generate(key => {"coverage" => coverage, "timestamp" => Time.now.to_i })
382
+ File.write(SingleCov.coverage_report, data)
383
+
384
+ # make it not override our report when it finishes for main process
385
+ SingleCov.coverage_report = nil
386
+ end
354
387
  end
355
388
  end
@@ -7,7 +7,7 @@ module ForkingTestRunner
7
7
  [:quiet, "--quiet", "Quiet"],
8
8
  [:no_fixtures, "--no-fixtures", "Do not load fixtures"],
9
9
  [:no_ar, "--no-ar", "Disable ActiveRecord logic"],
10
- [:merge_coverage, "--merge-coverage", "Merge base code coverage into indvidual files coverage, great for SingleCov"],
10
+ [:merge_coverage, "--merge-coverage", "Merge base code coverage into individual files coverage and summarize coverage report"],
11
11
  [
12
12
  :record_runtime,
13
13
  "--record-runtime=MODE",
@@ -1,3 +1,3 @@
1
1
  module ForkingTestRunner
2
- VERSION = "1.6.0"
2
+ VERSION = "1.11.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forking_test_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-29 00:00:00.000000000 Z
11
+ date: 2020-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel_tests
@@ -133,14 +133,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - ">="
135
135
  - !ruby/object:Gem::Version
136
- version: 2.3.0
136
+ version: 2.5.0
137
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  requirements:
139
139
  - - ">="
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubygems_version: 3.0.3
143
+ rubygems_version: 3.1.3
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: Run every test in a fork to avoid pollution and get clean output per test