coverband 4.2.0.rc1 → 4.2.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -1
  3. data/.travis.yml +4 -2
  4. data/README.md +48 -43
  5. data/Rakefile +1 -1
  6. data/changes.md +40 -24
  7. data/coverband.gemspec +2 -0
  8. data/lib/coverband.rb +23 -3
  9. data/lib/coverband/adapters/base.rb +24 -1
  10. data/lib/coverband/adapters/redis_store.rb +28 -7
  11. data/lib/coverband/at_exit.rb +19 -2
  12. data/lib/coverband/collectors/coverage.rb +36 -82
  13. data/lib/coverband/collectors/delta.rb +63 -0
  14. data/lib/coverband/integrations/background.rb +4 -3
  15. data/lib/coverband/integrations/rack_server_check.rb +4 -1
  16. data/lib/coverband/reporters/base.rb +21 -14
  17. data/lib/coverband/reporters/html_report.rb +40 -15
  18. data/lib/coverband/reporters/web.rb +29 -6
  19. data/lib/coverband/utils/html_formatter.rb +20 -4
  20. data/lib/coverband/utils/railtie.rb +8 -0
  21. data/lib/coverband/utils/result.rb +3 -2
  22. data/lib/coverband/utils/results.rb +63 -0
  23. data/lib/coverband/utils/source_file.rb +5 -0
  24. data/lib/coverband/version.rb +1 -1
  25. data/public/application.css +5 -0
  26. data/public/application.js +108 -1644
  27. data/public/dependencies.js +1581 -0
  28. data/public/favicon.png +0 -0
  29. data/test/coverband/adapters/redis_store_test.rb +26 -9
  30. data/test/coverband/collectors/coverage_test.rb +56 -45
  31. data/test/coverband/collectors/delta_test.rb +52 -0
  32. data/test/coverband/coverband_test.rb +7 -0
  33. data/test/coverband/integrations/background_test.rb +14 -11
  34. data/test/coverband/integrations/middleware_test.rb +1 -0
  35. data/test/coverband/reporters/base_test.rb +4 -4
  36. data/test/coverband/reporters/console_test.rb +1 -1
  37. data/test/coverband/reporters/html_test.rb +6 -7
  38. data/test/integration/full_stack_test.rb +10 -8
  39. data/test/integration/rails_full_stack_test.rb +23 -4
  40. data/test/rails4_dummy/config/application.rb +1 -1
  41. data/test/rails4_dummy/config/coverband.rb +4 -1
  42. data/test/rails4_dummy/tmp/.keep +0 -0
  43. data/test/rails5_dummy/config/application.rb +1 -1
  44. data/test/rails5_dummy/config/coverband.rb +3 -1
  45. data/test/rails_test_helper.rb +13 -8
  46. data/test/test_helper.rb +9 -13
  47. data/test/unique_files.rb +23 -0
  48. data/views/file_list.erb +9 -0
  49. data/views/gem_list.erb +1 -1
  50. data/views/layout.erb +4 -3
  51. data/views/source_file.erb +16 -4
  52. data/views/source_file_loader.erb +7 -0
  53. metadata +29 -4
  54. data/test/integration/rails_gems_full_stack_test.rb +0 -36
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6f8d36b44cdc8402a49224920afd6c7a896a88a06ca81d7237566dc3784283a
4
- data.tar.gz: 5968d46ebf2badb624044a0af99ac13b3d1cf4f9aa390786da7cc52debc4fe57
3
+ metadata.gz: 48eecf1954fc57c470fec896c9196df70d44f5ed1fba84b57aa1fff41e97eb16
4
+ data.tar.gz: 1c4800d304c3c6746a6950d9a5ec7fedbf30540a657e0e645c22278804b38f8d
5
5
  SHA512:
6
- metadata.gz: 8b16934f2a74fb43a2868648cc2008100a8abb7c099f087b6b3eb28fd5e9acc2aa697b8c38189e1a510efbcbc363eefb72582d70ad095c451399735299ebbf31
7
- data.tar.gz: c8bdb22ed7aab4f36e3daee17ee4f070e3e529c3ce47689e9c14ef4b7499e8d3cad53140dee308b235deb5666ab13f9cc1a493fca0f93dd612374831c19ab308
6
+ metadata.gz: 5e71b1ebf042e029813e720a81d99ffe436fb9bc96fe1c11c650871e5ae110bb38e35aba37a430d356cec5c16dbd28cd9c73ef212b0cddc7d175f4211d067d6d
7
+ data.tar.gz: 32af9fc06b8c73d3900b0d12d19a0d4fac99875cc08fd65e73c395df6e0529d1d34dc5db2486d507b9f2db847a7e395d406ade4fa61347518b4e4f6e27b539e6
data/.gitignore CHANGED
@@ -16,7 +16,10 @@ rdoc
16
16
  spec/reports
17
17
  test/tmp
18
18
  test/version_tmp
19
- tmp
19
+ /tmp/
20
+ temp_results
20
21
  .byebug_history
21
22
  .env
22
23
  log/
24
+ test/unique_files
25
+ test/rails5_dummy/tmp
data/.travis.yml CHANGED
@@ -3,7 +3,7 @@ rvm:
3
3
  - "2.3"
4
4
  - "2.4"
5
5
  - "2.5"
6
- - "2.6"
6
+ - "2.6.1"
7
7
  gemfile:
8
8
  - Gemfile
9
9
  - Gemfile.rails4
@@ -11,7 +11,9 @@ services:
11
11
  - redis-server
12
12
  before_install:
13
13
  - echo 'this is a hack to clear default bundler and force bundler 1.17.3'
14
+ - ls /home/travis/.rvm/gems/
14
15
  - rm /home/travis/.rvm/gems/ruby-2.3.7@global/specifications/bundler-2.0.1.gemspec || true
16
+ - rm /home/travis/.rvm/gems/ruby-2.5.4@global/specifications/bundler-2.0.1.gemspec || true
15
17
  - gem uninstall bundler || true
16
18
  - gem install bundler -v '1.17.3'
17
- - bundler --version
19
+ - bundler --version
data/README.md CHANGED
@@ -15,24 +15,24 @@
15
15
 
16
16
  A gem to measure production code usage, showing a counter for the number of times each line of code that is executed. Coverband allows easy configuration to collect and report on production code usage. It reports in the background via a thread or can be used as Rack middleware, or manually configured to meet any need.
17
17
 
18
- __Note:__ Coverband is not intended for test code coverage, for that we recommended using [SimpleCov](https://github.com/colszowka/simplecov).
18
+ **Note:** Coverband is not intended for test code coverage, for that we recommended using [SimpleCov](https://github.com/colszowka/simplecov).
19
19
 
20
20
  ## Key Features
21
21
 
22
22
  The primary goal of Coverband is giving deep insight into your production runtime usage of your application code, while having the least impact on performance possible.
23
23
 
24
- * Low performance overhead
25
- * Very simple setup and configuration
26
- * Out of the box support for all standard code execution paths (web, cron, background jobs, rake tasks, etc)
27
- * Easy to understand actionable insights from the report
28
- * Development mode, offers deep insight of code usage details (number of LOC execution during single request, etc) during development.
29
- * Mountable web interface to easily share reports
24
+ - Low performance overhead
25
+ - Very simple setup and configuration
26
+ - Out of the box support for all standard code execution paths (web, cron, background jobs, rake tasks, etc)
27
+ - Easy to understand actionable insights from the report
28
+ - Development mode, offers deep insight of code usage details (number of LOC execution during single request, etc) during development.
29
+ - Mountable web interface to easily share reports
30
30
 
31
31
  # Installation
32
32
 
33
33
  ## Redis
34
34
 
35
- Coverband stores coverage data in Redis. The Redis endpoint is looked for in this order:
35
+ Coverband stores coverage data in Redis. The Redis endpoint is looked for in this order:
36
36
 
37
37
  1. `ENV['COVERBAND_REDIS_URL']`
38
38
  2. `ENV['REDIS_URL']`
@@ -54,7 +54,6 @@ If [tracking gem usage](#collecting-gem--library-usage), be sure to include cove
54
54
 
55
55
  The Railtie integration means you shouldn't need to do anything anything else other than ensure coverband is required after rails within your Gemfile.
56
56
 
57
-
58
57
  ## Sinatra
59
58
 
60
59
  For the best coverage you want this loaded as early as possible. I have been putting it directly in my `config.ru` but you could use an initializer, though you may end up missing some boot up coverage. To start collection require Coverband as early as possible.
@@ -77,7 +76,7 @@ Rails.application.routes.draw do
77
76
  end
78
77
  ```
79
78
 
80
- But don't forget to *protect your source code with proper authentication*. Something like this when using devise:
79
+ But don't forget to _protect your source code with proper authentication_. Something like this when using devise:
81
80
 
82
81
  ```ruby
83
82
  Rails.application.routes.draw do
@@ -92,11 +91,12 @@ end
92
91
  The web endpoint is a barebones endpoint that you can either expose direct (after authentication) or you can just link to the actions you wish to expose. The index is intended as a example to showcase all the features.
93
92
 
94
93
  ![image](https://raw.github.com/danmayer/coverband/master/docs/coverband_web_update.png)
94
+
95
95
  > The web index as available on the Coverband Demo site
96
96
 
97
- * __force coverage collection:__ This triggers coverage collection on the current webserver process
98
- * __reload Coverband files:__ This has Coverband reload files as configured (force reload of some files that might not capture Coverage on boot). This can be used to reload files on demand.
99
- * __clear coverage report:__ This will clear the coverage data. This wipes out all collected data (__dangerous__)
97
+ - **force coverage collection:** This triggers coverage collection on the current webserver process
98
+ - **reload Coverband files:** This has Coverband reload files as configured (force reload of some files that might not capture Coverage on boot). This can be used to reload files on demand.
99
+ - **clear coverage report:** This will clear the coverage data. This wipes out all collected data (**dangerous**)
100
100
 
101
101
  ### Rake Tasks
102
102
 
@@ -118,17 +118,16 @@ Details on an example Sinatra app
118
118
 
119
119
  # Verify Correct Installation
120
120
 
121
- * boot up your application
122
- * run app and hit a controller (via a web request, at least one request must complete)
123
- * run `rake coverband:coverage` this will show app initialization coverage
124
- * make another request, or enough that your reporting frequency will trigger
125
- * run `rake coverband:coverage` and you should see coverage increasing for the endpoints you hit.
121
+ - boot up your application
122
+ - run app and hit a controller (via a web request, at least one request must complete)
123
+ - run `rake coverband:coverage` this will show app initialization coverage
124
+ - make another request, or enough that your reporting frequency will trigger
125
+ - run `rake coverband:coverage` and you should see coverage increasing for the endpoints you hit.
126
126
 
127
127
  # Coverband Demo
128
128
 
129
129
  Take Coverband for a spin on the live Heroku deployed [Coverband Demo](https://coverband-demo.herokuapp.com/). The [full source code for the demo](https://github.com/danmayer/coverband_demo) is available to help with installation, configuration, and understanding of basic usage.
130
130
 
131
-
132
131
  ### Example apps
133
132
 
134
133
  - [Rails 5.2.x App](https://github.com/danmayer/coverband_demo)
@@ -137,14 +136,12 @@ Take Coverband for a spin on the live Heroku deployed [Coverband Demo](https://c
137
136
 
138
137
  # Advanced Config
139
138
 
140
-
141
139
  If you need to configure coverband, this can be done by creating a `config/coverband.rb` file relative to your project root.
142
140
 
143
- * See [lib/coverband/configuration.rb](https://github.com/danmayer/coverband/blob/master/lib/coverband/configuration.rb) for all options
144
- * By default Coverband will try to stored data to Redis
145
- * Redis endpoint is looked for in this order: `ENV['COVERBAND_REDIS_URL']`, `ENV['REDIS_URL']`, or `localhost`
141
+ - See [lib/coverband/configuration.rb](https://github.com/danmayer/coverband/blob/master/lib/coverband/configuration.rb) for all options
142
+ - By default Coverband will try to stored data to Redis \* Redis endpoint is looked for in this order: `ENV['COVERBAND_REDIS_URL']`, `ENV['REDIS_URL']`, or `localhost`
146
143
 
147
- Below is an example config file for a Rails 5 app:
144
+ Below is an example config file for a Rails 5 app:
148
145
 
149
146
  ```ruby
150
147
  #config/coverband.rb
@@ -170,14 +167,12 @@ end
170
167
  Sometimes you have files that are known to be valuable perhaps in other environments or something that is just run very infrequently. Opposed to having to mentally filter them out of the report, you can just have them ignored in the Coverband reporting by using `config.ignore` as shown below. Ignore takes a string but can also match with regex rules see how below ignores all rake tasks as an example.
171
168
 
172
169
  ```
173
- config.ignore = ['config/application.rb',
170
+ config.ignore += ['config/application.rb',
174
171
  'config/boot.rb',
175
172
  'config/puma.rb',
176
173
  'config/schedule.rb',
177
- 'config/environments/test.rb',
178
- 'config/environments/development.rb',
179
- 'config/environments/staging.rb',
180
- 'config/environments/production.rb',
174
+ 'bin/*'
175
+ 'config/environments/*',
181
176
  'lib/tasks/*']
182
177
  ```
183
178
 
@@ -208,8 +203,7 @@ Between the release of 4.0 and 4.1 our data format changed. This resets all your
208
203
 
209
204
  `rake coverband:migrate`
210
205
 
211
- * We will be working to support migrations going forward, when possible
212
-
206
+ - We will be working to support migrations going forward, when possible
213
207
 
214
208
  ### Clear Coverage
215
209
 
@@ -250,8 +244,8 @@ Coverband.configure do |config|
250
244
  config.safe_reload_files = ['config/coverband.rb']
251
245
  end
252
246
  ```
253
- By adding any files above you will get reporting on those files as part of your coverage runtime report. The files are reloaded when Coverband first starts, you can also trigger a reload via the web interface.
254
247
 
248
+ By adding any files above you will get reporting on those files as part of your coverage runtime report. The files are reloaded when Coverband first starts, you can also trigger a reload via the web interface.
255
249
 
256
250
  ### Collecting Gem / Library Usage
257
251
 
@@ -278,6 +272,17 @@ end
278
272
 
279
273
  This flag exposes line by line usage of gem files. Unfortunately due to the way the coverband report is currently rendered, enabling `gem_details` slows down viewing of the coverage report in the browser and is not yet recommended.
280
274
 
275
+ ### Manually Starting Coverband
276
+
277
+ Coverband starts on require of the the library which is usually done within the Gemfile. This can be disabled by setting the `COVERBAND_DISABLE_AUTO_START` environment variable. This environment variable can be useful to toggle coverband on and off in certain environments.
278
+
279
+ In order to start coverband manually yourself when this flag is enabled, call `Coverband.configure` followed by `Coverband.start`.
280
+
281
+ ```ruby
282
+ Coverband.configure
283
+ Coverband.start
284
+ ```
285
+
281
286
  ### Verbose Debug / Development Mode
282
287
 
283
288
  Note: To debug issues getting Coverband working. I recommend running in development mode, by turning verbose logging on `config.verbose = true` and passing in the Rails.logger `config.logger = Rails.logger` to the Coverband config. This makes it easy to follow in development mode. Be careful to not leave these on in production as they will affect performance.
@@ -304,8 +309,8 @@ If you are trying to debug locally wondering what code is being run during a req
304
309
 
305
310
  # Prerequisites
306
311
 
307
- * Coverband 3.0.X+ requires Ruby 2.3+
308
- * Coverband currently requires Redis for production usage
312
+ - Coverband 3.0.X+ requires Ruby 2.3+
313
+ - Coverband currently requires Redis for production usage
309
314
 
310
315
  # Contributing To Coverband
311
316
 
@@ -322,18 +327,18 @@ If you are working on adding features, PRs, or bugfixes to Coverband this sectio
322
327
 
323
328
  If you submit a change please make sure the tests and benchmarks are passing.
324
329
 
325
- * run tests:
326
- * `bundle exec rake`
327
- * `BUNDLE_GEMFILE=Gemfile.rails4 bundle exec rake` (Same tests using rails 4 instead of 5)
328
- * view test coverage: `open coverage/index.html`
329
- * run the benchmarks before and after your change to see impact
330
- * `rake benchmarks`
330
+ - run tests:
331
+ - `bundle exec rake`
332
+ - `BUNDLE_GEMFILE=Gemfile.rails4 bundle exec rake` (Same tests using rails 4 instead of 5)
333
+ - view test coverage: `open coverage/index.html`
334
+ - run the benchmarks before and after your change to see impact
335
+ - `rake benchmarks`
331
336
 
332
337
  ### Known Issues
333
338
 
334
- * __total fail__ on front end code, because of the precompiled template step basically coverage doesn't work well for `erb`, `slim`, and the like.
335
- * related it will try to report something, but the line numbers reported for `ERB` files are often off and aren't considered useful. I recommend filtering out .erb using the `config.ignore` option. The default configuration excludes these files
336
- * coverage doesn't show for Rails `config/application.rb` or `config/boot.rb` as they get loaded when loading the Rake environment prior to starting the `Coverage` library. See [reload files section](#forcing-coverband-to-track-coverage-on-files-loaded-during-boot-safe_reload_files).
339
+ - **total fail** on front end code, because of the precompiled template step basically coverage doesn't work well for `erb`, `slim`, and the like.
340
+ - related it will try to report something, but the line numbers reported for `ERB` files are often off and aren't considered useful. I recommend filtering out .erb using the `config.ignore` option. The default configuration excludes these files
341
+ - coverage doesn't show for Rails `config/application.rb` or `config/boot.rb` as they get loaded when loading the Rake environment prior to starting the `Coverage` library. See [reload files section](#forcing-coverband-to-track-coverage-on-files-loaded-during-boot-safe_reload_files).
337
342
 
338
343
  ### Debugging Redis Store
339
344
 
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ Rake::TestTask.new(:test) do |test|
13
13
  # exclude benchmark from the tests as the way it functions resets code coverage during executions
14
14
  # test.pattern = 'test/unit/*_test.rb'
15
15
  # using test files opposed to pattern as it outputs which files are run
16
- test.test_files = FileList['test/**/*_test.rb']
16
+ test.test_files = FileList['test/integration/**/*_test.rb', 'test/coverband/**/*_test.rb']
17
17
  test.verbose = true
18
18
  end
19
19
 
data/changes.md CHANGED
@@ -36,7 +36,17 @@ Will be the fully modern release that drops maintenance legacy support in favor
36
36
  - Make good video on setup, install, usage
37
37
  - See if we can add support for views / templates
38
38
  - using this technique https://github.com/ioquatix/covered
39
- - Better default grouping (could use groups features for gems for rails controllers, models, lib, etc)
39
+ - Better default grouping (could use groups features for gems for rails controllers, models, lib, etc)
40
+ - Improved logging for easier debugging and development
41
+ - drop the verbose mode and better support standard logger levels
42
+ - Possibly setup a build assets system
43
+ - my JS rules expanded the compressed JS at the top of application.js, basically we want to stitch together JS
44
+ - I guess we could also load multiple JS files as most of the JS is just default compressed JS and a tiny amount of actual app JS.
45
+ - lazy load for Coverband results
46
+ - view layer file coverage
47
+ - move all code to work with relative paths leaving only stdlib Coverage working on full paths
48
+ - add gem_safe_lists to track only some gems
49
+ - add gem_details_safe list to report on details on some gems
40
50
 
41
51
  ### Coverband_jam_session
42
52
 
@@ -63,41 +73,47 @@ Feature Ideas:
63
73
 
64
74
  # Alpha
65
75
 
66
- ### Coverband 4.2.0.alpha
76
+ ### Coverband 4.2.0.rc
67
77
 
68
- ???
78
+ For this release your combined coverage is OK, but your runtime coverage will be incorrect until you reset your coverage. This is due to an additive change in how we store coverage. We didn't reset by default as the coverage history for some folks may be more important than runtime breakdown.
69
79
 
70
- ### Coverband 4.1.0.beta
71
-
72
- - default disabled web clear, add config option to allow it
73
- - out of the box support for resque
74
- - readme improvements
75
- - fix on regression of merging directory changing deployments
76
- - fixes for duplicate root paths
77
- - pilot release of Gems tracking (disabled by default)
78
- - todos
79
- - support multiple gem paths (various version managers setup multiple gem paths)
80
- - speed up page load by allowing multiple pages
81
- - added web settings and debug views
82
- - added support for seeing coverage data size consumed in redis
83
- - support coverage data migrations from 4.0.x to 4.1.0
84
- - fixes for heroku /tmp asset building
80
+ - loadtime vs runtime coverage
81
+ - This fixes the coverage last seen date to exclude just load time data
82
+ - now you can see boot time coverage vs code hit during production execution
83
+ - list view shows runtime percentage and runtime hits
84
+ - file view shows line hits load, runtime, and combined
85
+ - perf speedup on gem details views
86
+ - ajax load code views for more responsive pages on large projects
87
+ - fix for issues with COVERBAND_DISABLE_AUTO_START
88
+ - silence warnings
89
+ - move from thread based reporter instance to process based instance
90
+ - thanks Karl Baum for much of the above mentioned work
91
+ - clear coverage on individual files
85
92
 
86
93
  # Released
87
94
 
95
+ ### Coverband 4.2.0
96
+
97
+ ### Coverband 4.1.1
98
+
99
+ - fix bug on info page when using namespaces
100
+ - fix bug related to forking Ruby processes (Resque for example)
101
+ - bug caused negative line hits
102
+ - bug seemed to cause memory leaks (not entirely sure how)
103
+ - various test improvements
104
+ - fix bad requests on coverband web admin to `/coverage/favicon.png`
105
+ - improved documentation
106
+
88
107
  ### Coverband 4.1.0
89
108
 
90
109
  - default disabled web clear, add config option to allow it
91
110
  - out of the box support for resque
92
111
  - readme improvements
93
112
  - fix on regression of merging directory changing deployments
94
- - fixes for duplicate root paths
95
- - pilot release of Gems tracking (disabled by default)
96
- - todos
97
- - support multiple gem paths (various version managers setup multiple gem paths)
98
- - speed up page load by allowing multiple pages
113
+ - fixes for duplicate root paths
114
+ - pilot release of Gems tracking (disabled by default) - todos - support multiple gem paths (various version managers setup multiple gem paths) - speed up page load by allowing multiple pages
99
115
  - added web settings and debug views
100
- - added support for seeing coverage data size consumed in redis
116
+ - added support for seeing coverage data size consumed in redis
101
117
  - support coverage data migrations from 4.0.x to 4.1.0
102
118
  - fixes for heroku /tmp asset building
103
119
 
data/coverband.gemspec CHANGED
@@ -33,6 +33,8 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'rack-test'
34
34
  spec.add_development_dependency 'rake'
35
35
  spec.add_development_dependency 'resque'
36
+ # temporarily needed to fun tests for classifier-reborn as part of benchmarks
37
+ spec.add_development_dependency 'minitest-reporters'
36
38
 
37
39
  # TODO: used for benchmarking and tests I think we have other better benchmarking
38
40
  # perhaps time to drop this and refactor.
data/lib/coverband.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  require 'logger'
4
4
  require 'json'
5
5
  require 'redis'
6
-
7
6
  require 'coverband/version'
8
7
  require 'coverband/at_exit'
9
8
  require 'coverband/configuration'
@@ -19,7 +18,7 @@ require 'coverband/utils/gem_list'
19
18
  require 'coverband/utils/source_file'
20
19
  require 'coverband/utils/file_groups'
21
20
  require 'coverband/utils/lines_classifier'
22
- require 'coverband/utils/railtie' if defined? ::Rails::Railtie
21
+ require 'coverband/utils/results'
23
22
  require 'coverband/collectors/coverage'
24
23
  require 'coverband/reporters/base'
25
24
  require 'coverband/reporters/html_report'
@@ -29,10 +28,14 @@ require 'coverband/integrations/rack_server_check'
29
28
  require 'coverband/reporters/web'
30
29
  require 'coverband/integrations/middleware'
31
30
  require 'coverband/integrations/background'
32
- require 'coverband/integrations/resque' if defined? Resque
33
31
 
34
32
  module Coverband
35
33
  CONFIG_FILE = './config/coverband.rb'
34
+ RUNTIME_TYPE = nil
35
+ EAGER_TYPE = :eager_loading
36
+ MERGED_TYPE = :merged
37
+ TYPES = [RUNTIME_TYPE, EAGER_TYPE]
38
+ ALL_TYPES = TYPES + [:merged]
36
39
 
37
40
  class << self
38
41
  attr_accessor :configuration_data
@@ -48,6 +51,7 @@ module Coverband
48
51
  else
49
52
  configuration.logger&.debug('using default configuration')
50
53
  end
54
+ coverage.reset_instance
51
55
  end
52
56
 
53
57
  def self.report_coverage(force_report = false)
@@ -60,14 +64,30 @@ module Coverband
60
64
 
61
65
  def self.start
62
66
  Coverband::Collectors::Coverage.instance
67
+ # TODO Railtie sets up at_exit after forks, via middleware, perhaps this hsould be
68
+ # added if not rails or if rails but not rackserverrunning
63
69
  AtExit.register
64
70
  Background.start if configuration.background_reporting_enabled && !RackServerCheck.running?
65
71
  end
66
72
 
73
+ def self.eager_loading_coverage!
74
+ coverage.eager_loading!
75
+ end
76
+
77
+ def self.runtime_coverage!
78
+ coverage.runtime!
79
+ end
80
+
81
+ def self.coverage
82
+ Coverband::Collectors::Coverage.instance
83
+ end
84
+
67
85
  unless ENV['COVERBAND_DISABLE_AUTO_START']
68
86
  # Coverband should be setup as early as possible
69
87
  # to capture usage of things loaded by initializers or other Rails engines
70
88
  configure
71
89
  start
90
+ require 'coverband/utils/railtie' if defined? ::Rails::Railtie
91
+ require 'coverband/integrations/resque' if defined? Resque
72
92
  end
73
93
  end
@@ -4,6 +4,7 @@ module Coverband
4
4
  module Adapters
5
5
  class Base
6
6
  include Coverband::Utils::FilePathHelper
7
+ attr_accessor :type
7
8
 
8
9
  def initialize
9
10
  @file_hash_cache = {}
@@ -13,6 +14,10 @@ module Coverband
13
14
  raise 'abstract'
14
15
  end
15
16
 
17
+ def clear_file!(_file)
18
+ raise 'abstract'
19
+ end
20
+
16
21
  def migrate!
17
22
  raise 'abstract'
18
23
  end
@@ -39,6 +44,11 @@ module Coverband
39
44
  get_report
40
45
  end
41
46
 
47
+ def get_coverage_report
48
+ data = Coverband.configuration.store.split_coverage(Coverband::TYPES)
49
+ data.merge(Coverband::MERGED_TYPE => Coverband.configuration.store.merged_coverage(Coverband::TYPES))
50
+ end
51
+
42
52
  def covered_files
43
53
  coverage.keys || []
44
54
  end
@@ -50,6 +60,18 @@ module Coverband
50
60
 
51
61
  protected
52
62
 
63
+ def split_coverage(types)
64
+ types.reduce({}) do |data, type|
65
+ data.update(type => get_report(type))
66
+ end
67
+ end
68
+
69
+ def merged_coverage(types)
70
+ types.reduce({}) do |data, type|
71
+ merge_reports(data, get_report(type), skip_expansion: true)
72
+ end
73
+ end
74
+
53
75
  def save_coverage
54
76
  raise 'abstract'
55
77
  end
@@ -65,10 +87,11 @@ module Coverband
65
87
  def expand_report(report)
66
88
  expanded = {}
67
89
  report_time = Time.now.to_i
90
+ updated_time = self.type == Coverband::EAGER_TYPE ? nil : report_time
68
91
  report.each_pair do |key, line_data|
69
92
  extended_data = {
70
93
  'first_updated_at' => report_time,
71
- 'last_updated_at' => report_time,
94
+ 'last_updated_at' => updated_time,
72
95
  'file_hash' => file_hash(key),
73
96
  'data' => line_data
74
97
  }