simplecov-ruby / simplecov-html Goto Github PK
View Code? Open in Web Editor NEWHTML formatter for SimpleCov code coverage tool for ruby 1.9+
Home Page: http://github.com/colszowka/simplecov
License: MIT License
HTML formatter for SimpleCov code coverage tool for ruby 1.9+
Home Page: http://github.com/colszowka/simplecov
License: MIT License
In the context where we use simplecov
(-html
), it is much more practical to have the result in a single HTML file, with the assets included in base64-encoded form.
I implemented this in a quick and dirty way (using sprockets), but it works.
You can have a look at it here: eins78@939548d
I would not send this commit as a PR, but if there is general interest in this feature it could be cleaned up.
btw:
A quick comparison of file sizes shows that in our case it actually gets smaller (I guess because only referenced assets are included).
It seems that coverage percents aren't correctly sorted according to their float value but rather treated as strings as reported over here: simplecov-ruby/simplecov#781 (comment)
we should fix that :)
There have been a lot of great fixes since the last release, can we make a new release? v0.12.3...main
Thanks!
I require and configure SimpleCov in my rspec spec_helper file. Version 0.4.0 gives me the following error when running 'rspec spec':
'simplecov-html.rb:113:in `require': no such file to load -- simplecov-html/version (LoadError)'
Version 0.3.9 works fine.
Hey guys,
Was trying to update to the latest rubocop version but got this output in the console:
gems/gems/simplecov-html-0.10.2/.rubocop.yml: Style/AccessModifierIndentation has the wrong namespace - should be Layout
gems/gems/simplecov-html-0.10.2/.rubocop.yml: Style/FileName has the wrong namespace - should be Naming
gems/gems/simplecov-html-0.10.2/.rubocop.yml: Style/SpaceInsideHashLiteralBraces has the wrong namespace - should be Layout
Error: The `Style/TrailingCommaInLiteral` cop no longer exists. Please use `Style/TrailingCommaInArrayLiteral` and/or `Style/TrailingCommaInHashLiteral` instead.
(obsolete configuration found in gems/gems/simplecov-html-0.10.2/.rubocop.yml, please update it)
We should update the configuration files.
Thanks!
Please add
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
to views/layout.erb
Given that we have multiple different tests or specs run. In case of RubyMine these runs have separated reports hence they aren't merged by simplecov. It would be very nice for report generator to take multiple file paths and merge results in one html.
E.g.: I have to reports:
The first has 100% in foo.rb and 20% in foo_test.rb
The second one has 100% in foo_helper.rb and 20% on other lines in foo_test.rb
Then I expect to get one html with 100% for foo, foo_helper and 40% (or less if lines intersect) for foo_test.
This is a follow-up of simplecov-ruby/simplecov#679
I'm having a 100% test coverage with some missed lines
I suggest to stick with using Float#floor
instead of round
as simplecov does.
The changes would be in :
Are you open to merge pull requests? I can submit one
I am kind of tired of seeing this every time I run my test suite :o) - I hope it can be fixed.
/usr/local/lib/ruby/gems/2.2.0/gems/simplecov-html-0.8.0/lib/simplecov-html.rb:58: warning: possibly useless use of a variable in void context
I'm trying to generate an inline-html report using an external JS library. Encountered an issue due to a missing asset that is referenced in the code.
simplecov-html/views/layout.erb
Line 9 in d268588
Filing an issue in case you'd like to fix this.
For example, if I'm looking at coverage/index.html
and I open up the to_do.rb
file to see the coverage, I would like the URL to be updated to reflect the specific file that I'm looking at. Something like coverage/index.html#specs/models/to_do.rb
.
This would allow two main things:
Thoughts?
It's currently not possible to use the HTML output without using at least
script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline';
Which isn't desired, and requires extra configuration when setting up a coverage page in Jenkins
RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.
via e.g.
spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']
Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.
There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.
I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!
Appendix:
If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies
p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.
Hi,
For some reason, it's not possible to scroll the source listings that simplecov-html creates with the keyboard in Chrome, even when you click inside the scrollable div.
I think this issue stems from the fact this library does not clear out the coverage
directory before it runs. If it simply removed the coverage
directory before starting, it should fix this error.
Related issue: #134 -- when this one is fixed, that one will also likely be fixed.
rails new --skip-bootsnap temp
cd temp
bundle config set --local path 'vendor'
bundle add simplecov
printf 'require "simplecov"\nSimpleCov.start "rails"\n' >>test/test_helper.rb
chmod -R a-w vendor
bin/rails test
# Run tests again to produce the error
bin/rails test
The second rails test
fails with the following error message:
Running 0 tests in a single process (parallelization threshold is 50)
Run options: --seed 46566# Running:
Formatter SimpleCov::Formatter::HTMLFormatter failed with Errno::EACCES: Permission denied @ rb_sysopen - /tmp/ndz.eFIwFv/temp/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc.png (/home/h3xx/.rbenv/versions/3.3.0/lib/ruby/3.3.0/fileutils.rb:2279:in `initialize')
For https://gitlab-org.gitlab.io/gitlab/coverage-ruby/ it would be nice to show MB on the loading progress bar. The page itself is 163 MB. Quite a huge coverage to load.
While rubygems is loaded by default on 1.9+, there are situations where it is desirable not to load it, and you can use ruby's --disable=gem
flag to disable it. We're trying to update RSpec's travis builds to run with rubygems disable, and are running into unitinialized constant by your use of Gem::Version
:
Can this version constraint be moved into the gemspec? That would allow bundler to ensure this and simplecov are compatible, where as it can't due that when it's purely a runtime check like you have now.
Based on the Gemfile.lock I believe that simplecov-html makes use of rack version 2.2.3
That Rack version is has vulnerability CVE-2022-30123 (crafted requests that can cause shell escape sequences).
The solution is to rebuild using rack >= 2.2.3.1
This also fixes CVE-2022-30122.
I am having a strange issue where the report in the HTML format is not created every time my test suite is ran. Even though I run rake test
several times a day, my index.html
report is 6 days old and I can't seem to have it refreshed with my latest run data.
In the test_helper.rb
, I have:
require 'simplecov'
SimpleCov.command_name 'test:unit'
SimpleCov.coverage_dir('coverage/api/unit')
And my .simplecov
file contains:
# rubocop:disable Style/FileName
require 'simplecov-lcov'
require 'simplecov-summary'
SimpleCov.coverage_dir('coverage/api')
SimpleCov.maximum_coverage_drop(0.5)
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::LcovFormatter,
SimpleCov::Formatter::SummaryFormatter
])
SimpleCov.profiles.define('adgear') do
load_profile('rails')
# [ bunch of regular add_filter and add_group('Some Name', 'some/path')
end
SimpleCov.start('adgear')
# rubocop:enable Style/FileName
When I try to use SimpleCov.at_exit { }
block, it is not executed (I tried raising an error in this block, output a hello_world
, write a file, but nothing is executed from my custom block).
Using:
simplecov-0.16.1
simplecov-html-0.10.2
Hi @colszowka
I'd like to reuse your simplecov-html project and port it onto Oracle PLSQL for Oracle code coverage reporting with utPLSQL v3.
Would you be OK with that? There would still be a footer pointing to simplecov-html project as the original source for the report.
The recent datatables upgrade apparently enabled pagination by default.
We don't query an servers or something and I think our browsers can handle this "big data", so I would suggest to disable paging.
Potential compromise: set the default page length to 500 or 1000 (although then the fact that there is pagination at all would not be so visible)
π’
The position of the search field is also a bit unintuitive
I'm getting an odd IOError when running simplecov with feature tests, but not just on specs:
/Users/tansaku/.rvm/gems/ruby-2.2.2/gems/simplecov-html-0.9.0/lib/simplecov-html.rb:21:in `write': not opened for writing (IOError)
from /Users/tansaku/.rvm/gems/ruby-2.2.2/gems/simplecov-html-0.9.0/lib/simplecov-html.rb:21:in `puts'
from /Users/tansaku/.rvm/gems/ruby-2.2.2/gems/simplecov-html-0.9.0/lib/simplecov-html.rb:21:in `puts'
from /Users/tansaku/.rvm/gems/ruby-2.2.2/gems/simplecov-html-0.9.0/lib/simplecov-html.rb:21:in `format'
from /Users/tansaku/.rvm/gems/ruby-2.2.2/gems/simplecov-0.9.2/lib/simplecov/result.rb:46:in `format!'
from /Users/tansaku/.rvm/gems/ruby-2.2.2/gems/simplecov-0.9.2/lib/simplecov/configuration.rb:158:in `block in at_exit'
from /Users/tansaku/.rvm/gems/ruby-2.2.2/gems/simplecov-0.9.2/lib/simplecov/defaults.rb:54:in `call'
from /Users/tansaku/.rvm/gems/ruby-2.2.2/gems/simplecov-0.9.2/lib/simplecov/defaults.rb:54:in `block in <top (required)>'
Our project has features in a features directory, straight off the root, and specs in a spec directory also straight off root. I get the above running "rspec features" but don't get it when running "rspec" or "rspec spec".
Everything still seems to work in terms of the simplecov output, but gets this error thrown as well ...
I'd like to avoid the output message in the console.
Could we add an option to not display the message?
When working on Puma tests to mimic systemd, ran into a rather odd error. The following code:
https://github.com/colszowka/simplecov-html/blob/9ec41504ab139fabfaddfc786dfdab5d6aca0bab/lib/simplecov-html.rb#L22-L24
threw errors as below:
Fabulous run in 2.374952s, 5.4738 runs/s, 29.4743 assertions/s.
13 runs, 70 assertions, 0 failures, 0 errors, 0 skips
SimpleCov.coverage_path puma/coverage
SimpleCov.coverage_path puma/coverage
Traceback (most recent call last):
4: from simplecov-html-0.10.2/lib/simplecov-html.rb:22:in `format'
3: from simplecov-html-0.10.2/lib/simplecov-html.rb:22:in `open'
2: from simplecov-html-0.10.2/lib/simplecov-html.rb:23:in `block in format'
1: from simplecov-html-0.10.2/lib/simplecov-html.rb:23:in `puts'
simplecov-html-0.10.2/lib/simplecov-html.rb:23:in `write': Bad file descriptor (Errno::EBADF)
2: from simplecov-html-0.10.2/lib/simplecov-html.rb:22:in `format'
1: from simplecov-html-0.10.2/lib/simplecov-html.rb:22:in `open'
simplecov-html-0.10.2/lib/simplecov-html.rb:22:in `close': Bad file descriptor @ fptr_finalize_flush - C:/Greg/GitHub/puma/coverage/index.html (Errno::EBADF)
rake aborted!
Command failed with status (1)
There's 'odd things' in the tests re fd's, etc, but the tests seem stable. When I changed the above code to the following, everything runs fine:
File.write(
File.join(output_path, "index.html"),
template("layout").result(binding),
mode: "wb"
)
Why I'm getting the errors with File.open
, but not File.write
, I'm not sure, as I always considered them equivalent. Anyway, would this be accepted as a PR?
In version 0.11.0
, when I open a coverage page (with anchor, like http://coverage.core.ips.net/#8fa08b9ca3d22133f6daaa36049fcd5a9e1ef472
), after some of the code in this page has changed, I can directly refresh the page, then the new code and coverage situation can be displayed.
But in version 0.12.0
, when I do this (something even there is no change with the code), the page will be in loading status endlessly (the progress bar will act continuously, but no code and coverage displayed). This happens in all the coverage pages.
I'm not sure whether this is a new feature in version 0.12.0
or a bug, maybe maintainers can check this?
See screenshot below from Travis, which is showing deprecated Rubocop rules in the latest published gem (v.0.10.2):
This causes hard failures in dependent apps that require modern (>= ~v.0.74) Rubocop compliance during builds.
It appears that the necessary updates to the .rubocop.yml
file have been made in the master branch, but a new gem version has not been published. Please publish an updated version to fix the deprecation warnings and hard failure. Thanks.
Hi,
First of all, thanks for providing such good lib!
We are using a CI tool that only takes one html as report. Which doesn't include the assets dir. I am think if we can move our images / stylesheets / javascripts to a CDN. Or just put all of them in the bottom of the html page. So the coverage folder will only have one html page (index.html).
Thanks,
Hao
I'm using simplecov-html 0.4.3. My project doesn't use Bundler so I haven't got a Gemfile. When I require 'simplecov'
Ruby crashes with a message which you see in this issue's title. The problem doesn't occur when I create an empty Gemfile. The problem can be solved by removing first two lines from simplecov-html.rb:
#require 'bundler'
#Bundler.setup(:default)
If an existing symbolic link exists inside the coverage
directory, it can overwrite arbitrary files elsewhere on the system.
This is also true for hard-linked files.
This library MUST remove the files in the coverage
before attempting to overwrite them in order to fix this security issue.
echo "Don't delete me!" >~/super-important-file.txt
# Set up a rails project with SimpleCov coverage testing
rails new --skip-bootsnap temp
cd temp
bundle add simplecov
printf 'require "simplecov"\nSimpleCov.start "rails"\n' >>test/test_helper.rb
# Set up our symlink attack vector
mkdir -p coverage
ln -s ~/super-important-file.txt coverage/index.html
# Run the test -- this OVERWRITES ~/super-important-file.txt
bin/rails test
cat ~/super-important-file.txt
# Our file has been replaced with HTML :-(
This is only an example, but imagine if you were running tests as root.
Related issue: #133 -- when this one is fixed, that one will also likely be fixed.
Hi,
This is more of a question than an issue I have with the gem. I was wondering if you were interested in someone investing time to work on the UI. It seems a little outdated and there is some small UX issues that can be worked on.
Iβm interested in integrating a basic Bootstrap interface. This wonβt add to much dependencies and I think it will improve the overall experience.
If it is something youβre interested in, Iβll be happy to work on it.
Keep up the good work, this gem is essential to our workflow :)
βοΈ
This is sort of a small thing, but when I ran my whole test suite just now, the command line said, "Coverage report generated for /path/to/bin/rspec spec to /path/to/project/coverage. 62.5% covered.", but the web UI said 93.08%. The 93% is the correct one.
After doing some experimentation, it seems like the command line output percentage varies a lot. It said 88.63, then I ran just one file and it said 58.62 (that one file does NOT test half my application) and then I ran the whole suite again and it continues to say 58.62. Though all that, the web interface has said 93.08%.
I looked at the code, but wouldn't sort it out. I may try to give it a look later on, but wanted to bring up the issue before I forgot in case I don't have time.
Reference Issue simplecov-ruby/simplecov#659.
Javascript error in version '0.12.0'.
Uncaught Error: Syntax error, unrecognized expression: a.src_link[href=#4eb942230860ef99bbe56de21801de7c3054304f]
at Function.w.error (<anonymous>:1:28701)
at w.tokenize (<anonymous>:2:1891)
at w.select (<anonymous>:2:2156)
at Function.w [as find] (<anonymous>:1:17673)
at Te.fn.init.find (<anonymous>:2:4445)
at new Te.fn.init (<anonymous>:2:5054)
at Te (<anonymous>:1:14075)
at HTMLDocument.<anonymous> (<anonymous>:7:5122)
at t (<anonymous>:2:9165)
at a (<anonymous>:2:9471)
I ran unit test with simplecov-html 0.11.0
, no error occurred.
But when I upgrade simplecov-html
into version 0.12.0
, when I open some of the code coverage items(including nearly all the controllers and more than half of the helpers, but the coverage percentage value is correct), this error is thrown.
My ruby version is 2.6.5
, rails version is 6.0.2.1
, simplecov version is 0.18.2
.
Hello,
Recent simplecov fail with this error:
lib/simplecov-html.rb:82:in `timeago': undefined method `iso8601' for 2012-05-13 14:41:38 +0200:Time (NoMethodError)
This is because Time#iso8601 is only defined when 'time' is required, as it is an extension.
So I believe requiring 'time' in simplecov-html should solve this issue.
This color doesn't work for color blind people.
simplecov-html/assets/stylesheets/screen.css
Line 287 in 3a30b47
As reported in #15, the colorbox plugin should be updated to the latest version to ensure as few browser compatibility problems as possible can happen.
css files reference files as assets/0.10.0/images/ui-icons_888888_256x240.png
, though in reality these assets are located at assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png
Moved from simplecov-ruby/simplecov#1 posted by dmathieu:
The files content isn't escaped. So if there's HTML in it (like in dynamic_form for example), the html fields are rendered in the page unescaped.
When a source file includes non-ASCII characters i.e. Hiragana,
generated HTML contains source popups with broken characters.
Source:
MSG = "γγ―γγ"
Expected: (simplecov-html 1.11.0)
1. MSG = "γγ―γγ"
Actual: (simplecov-html 1.12.0)
1. MSG = "<?><?><?><?><?><?><?><?><?><?><?><?>"
Note: <?>
seems to be a unicode replacement character.
Using simplecov-html reports while doing active development is a bit painful right now:
My suggestion is to implement what some other HTML coverage generators do (i.e. Python's coverage package) - or, for that matter, GitHub when viewing source files or gists - and make each line number a named anchor and link to that anchor so that users can save their location in the file.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.