Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ Unreleased
* JSON formatter: group stats changed from `{ "covered_percent": 80.0 }` to full stats shape `{ "covered": 8, "missed": 2, "total": 10, "percent": 80.0, "strength": 0.0 }`. The key `covered_percent` is renamed to `percent`.
* JSON formatter: `simplecov_json_formatter` gem is now built in. `require "simplecov_json_formatter"` continues to work via a shim.
* `StringFilter` now matches at path-segment boundaries. `"lib"` matches `/lib/` but no longer matches `/library/`. Use a `Regexp` filter for substring matching.
* `SourceFile#project_filename` now returns a truly relative path with no leading separator (e.g. `lib/foo.rb` instead of `/lib/foo.rb`). This also removes the leading `/` from file path keys in `coverage.json` and from the filename in `minimum_coverage_by_file` error messages. Anchored `RegexFilter`s that relied on a leading `/` (e.g. `%r{^/lib/}`) should be rewritten (e.g. `%r{\Alib/}`).
* Removed `docile` gem dependency. The `SimpleCov.configure` DSL block is now evaluated via `instance_exec` with instance variable proxying.
* Removed automatic activation of `JSONFormatter` when the `CC_TEST_REPORTER_ID` environment variable is set. The default `HTMLFormatter` now emits `coverage.json` alongside the HTML report (using `JSONFormatter.build_hash` to serialize the same payload `JSONFormatter` writes), so the env-var special case is no longer needed.

## Enhancements
* JSON formatter: `meta.timestamp` is now emitted with millisecond precision (`iso8601(3)`) so the concurrent-overwrite warning can distinguish writes within the same wall-clock second
* JSON formatter: added `total` section with aggregate coverage statistics (covered, missed, total, percent, strength) for line, branch, and method coverage. Line stats additionally include `omitted` (count of blank/comment lines, i.e. lines that cannot be covered)
* JSON formatter: per-file output now includes `lines_covered_percent`, and when enabled: `branches_covered_percent`, `methods` array, and `methods_covered_percent`
* JSON formatter: per-file output now includes `total_lines`, `lines_covered_percent`, and when enabled: `branches_covered_percent`, `methods` array, and `methods_covered_percent`
* JSON formatter: group stats now include full statistics for all enabled coverage types, not just line coverage percent
* JSON formatter: added `silent:` keyword to `JSONFormatter.new` to suppress console output
* Merged `simplecov-html` formatter into the main gem. A backward-compatibility shim ensures `require "simplecov-html"` still works.
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,6 @@ SimpleCov includes a `SimpleCov::Formatter::JSONFormatter` that provides you wit
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
```

> _Note:_ In case you plan to report your coverage results to CodeClimate services, know that SimpleCov will automatically use the
> JSON formatter along with the HTML formatter when the `CC_TEST_REPORTER_ID` variable is present in the environment.

> The JSON formatter was originally a separate gem called [simplecov_json_formatter](https://github.com/codeclimate-community/simplecov_json_formatter). It is now built in and loaded by default. Existing code that does `require "simplecov_json_formatter"` will continue to work.

## Available formatters, editor integrations and hosted services
Expand Down
5 changes: 4 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ task test: %i[spec cucumber test_html]
task default: %i[rubocop spec cucumber test_html]

namespace :assets do
desc "Compile frontend assets (JS + CSS) using esbuild"
desc "Compile frontend assets (HTML, JS, CSS) using esbuild"
task :compile do
frontend = File.expand_path("html_frontend", __dir__)
outdir = File.expand_path("lib/simplecov/formatter/html_formatter/public", __dir__)
Expand All @@ -62,5 +62,8 @@ namespace :assets do
io.close_write
File.write("#{outdir}/application.css", io.read)
end

# HTML: copy static index.html
FileUtils.cp(File.join(frontend, "src/index.html"), File.join(outdir, "index.html"))
end
end
3 changes: 1 addition & 2 deletions features/branch_coverage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ Feature:
end
"""
When I open the coverage report generated with `bundle exec rspec spec`
Then the output should contain "Line coverage: 56 / 61 (91.80%)"
And the output should contain "Branch coverage: 2 / 4 (50.00%)"
Then the output should contain "56 / 61 LOC (91.8%) covered"
And I should see the groups:
| name | coverage | files |
| All Files | 91.80% | 7 |
Expand Down
20 changes: 0 additions & 20 deletions features/config_json_formatter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,3 @@ Feature:
When I successfully run `bundle exec rake test`
Then a JSON coverage report should have been generated in "coverage"
And the output should contain "JSON Coverage report generated"

Scenario: When CC_TEST_REPORTER_ID is set in the environment
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.at_exit do
puts SimpleCov.result.format!
end
SimpleCov.start do
add_group 'Libs', 'lib/faked_project/'
end
"""
And I set the environment variables to:
| variable | value |
| CC_TEST_REPORTER_ID | some-id |

When I successfully run `bundle exec rake test`

Then a JSON coverage report should have been generated in "coverage"
And the output should contain "JSON Coverage report generated"
8 changes: 4 additions & 4 deletions features/minimum_coverage_by_file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Feature:

When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Line coverage by file (75.00%) is below the expected minimum coverage (75.01%) in /lib/faked_project/framework_specific.rb."
And the output should contain "Line coverage by file (75.00%) is below the expected minimum coverage (75.01%) in lib/faked_project/framework_specific.rb."
And the output should contain "SimpleCov failed with exit 2"

Scenario: Just passing it
Expand Down Expand Up @@ -48,8 +48,8 @@ Feature:

When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Line coverage by file (80.00%) is below the expected minimum coverage (90.00%) in /lib/faked_project/some_class.rb."
And the output should contain "Branch coverage by file (50.00%) is below the expected minimum coverage (70.00%) in /lib/faked_project/some_class.rb."
And the output should contain "Line coverage by file (80.00%) is below the expected minimum coverage (90.00%) in lib/faked_project/some_class.rb."
And the output should contain "Branch coverage by file (50.00%) is below the expected minimum coverage (70.00%) in lib/faked_project/some_class.rb."
And the output should contain "SimpleCov failed with exit 2"

@branch_coverage
Expand All @@ -67,6 +67,6 @@ Feature:

When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Branch coverage by file (50.00%) is below the expected minimum coverage (70.00%) in /lib/faked_project/some_class.rb."
And the output should contain "Branch coverage by file (50.00%) is below the expected minimum coverage (70.00%) in lib/faked_project/some_class.rb."
And the output should not contain "Line coverage ("
And the output should contain "SimpleCov failed with exit 2"
24 changes: 23 additions & 1 deletion features/step_definitions/html_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,29 @@
end

Then /^there should be (\d+) skipped lines in the source files$/ do |expected_count|
count = page.evaluate_script("document.querySelectorAll('.source_files template').length > 0 ? Array.from(document.querySelectorAll('.source_files template')).reduce(function(sum, t) { return sum + t.content.querySelectorAll('ol li.skipped').length; }, 0) : document.querySelectorAll('.source_table ol li.skipped').length")
# Materialize all source files (renders them from coverage data), then count skipped lines
count = page.evaluate_script(<<~JS)
(function() {
// Check for pre-rendered templates (old simplecov-html)
var templates = document.querySelectorAll('.source_files template');
if (templates.length > 0) {
return Array.from(templates).reduce(function(sum, t) {
return sum + t.content.querySelectorAll('ol li.skipped').length;
}, 0);
}
// New architecture: count skipped lines directly from coverage data
if (window.SIMPLECOV_DATA) {
var count = 0;
var coverage = window.SIMPLECOV_DATA.coverage;
Object.keys(coverage).forEach(function(fn) {
var lines = coverage[fn].lines;
lines.forEach(function(l) { if (l === 'ignored') count++; });
});
return count;
}
return document.querySelectorAll('.source_table ol li.skipped').length;
})()
JS
expect(count).to eq(expected_count.to_i)
end

Expand Down
17 changes: 0 additions & 17 deletions features/step_definitions/json_steps.rb

This file was deleted.

17 changes: 16 additions & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,23 @@ def extended(base)

# Rack app for Capybara which returns the latest coverage report from Aruba temp project dir
coverage_dir = File.expand_path("../../tmp/aruba/project/coverage/", __dir__)

# Prevent the browser from caching coverage_data.js between scenario visits
Comment thread
sferik marked this conversation as resolved.
class NoCacheMiddleware
def initialize(app)
@app = app
end

def call(env)
status, headers, body = @app.call(env)
headers["cache-control"] = "no-store"
[status, headers, body]
end
end

Capybara.app = Rack::Builder.new do
use Rack::Static, urls: {"/" => "index.html"}, root: coverage_dir, header_rules: [[:all, {"cache-control" => "no-store"}]]
use NoCacheMiddleware
use Rack::Static, urls: {"/" => "index.html"}, root: coverage_dir
run Rack::Directory.new(coverage_dir)
end.to_app

Expand Down
33 changes: 0 additions & 33 deletions features/test_unit_basic.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,3 @@ Feature:

And the report should be based upon:
| Unit Tests |

Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
ENV['CC_TEST_REPORTER_ID'] = "9719ac886877886b7e325d1e828373114f633683e429107d1221d25270baeabf"
require 'simplecov'
SimpleCov.start
"""

When I open the coverage report generated with `bundle exec rake test`
Then I should see the groups:
| name | coverage | files |
| All Files | 91.37% | 6 |

And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00% |
| lib/faked_project/some_class.rb | 80.00% |
| lib/faked_project/framework_specific.rb | 75.00% |
| lib/faked_project/meta_magic.rb | 100.00% |
| test/meta_magic_test.rb | 100.00% |
| test/some_class_test.rb | 100.00% |

# Note: faked_test.rb is not appearing here since that's the first unit test file
# loaded by Rake, and only there test_helper is required, which then loads simplecov
# and triggers tracking of all other loaded files! Solution for this would be to
# configure simplecov in this first test instead of test_helper.

And the report should be based upon:
| Unit Tests |

And a JSON coverage report should have been generated
And the JSON coverage report should match the output for the basic case
Loading