GithubHelp home page GithubHelp logo

simplecov-ruby / simplecov-html Goto Github PK

View Code? Open in Web Editor NEW
72.0 9.0 117.0 1.13 MB

HTML formatter for SimpleCov code coverage tool for ruby 1.9+

Home Page: http://github.com/colszowka/simplecov

License: MIT License

Ruby 10.12% JavaScript 46.59% CSS 35.28% HTML 8.01%

simplecov-html's Introduction

Default HTML formatter for SimpleCov

Note: To learn more about SimpleCov, check out the main repo at https://github.com/simplecov-ruby/simplecov

Generates a nice HTML report of your SimpleCov ruby code coverage results on Ruby 2.4+ using client-side Javascript quite extensively.

Note on Patches/Pull Requests

The formatter itself has no actual tests. Instead, it is tested in the cucumber features of simplecov itself. If you modify the formatter, please make sure the simplecov test suites still pass by doing the following:

  • Clone simplecov into the parent directory of your simplecov-html checkout
  • cd there, run bundle
  • You should end up with all dev dependencies installed and simplecov-html being used from your disk
  • Run the tests (units and features)

Please remember to add tests if you add functionality.

Important: If you modify the JS/CSS assets, you'll have to precompile them using rake assets:compile - otherwise, your changes will not be included in your coverage reports.

Copyright

Copyright (c) 2010-2013 Christoph Olszowka. See LICENSE for details.

simplecov-html's People

Contributors

akamike avatar amatsuda avatar bf4 avatar chetan avatar ciddennis avatar colszowka avatar dependabot[bot] avatar fatkodima avatar frankh avatar guapolo avatar justinsteele avatar koenpunt avatar koic avatar kriechi avatar luislavena avatar lukejahnke avatar magneland avatar matthewtusker avatar mlarraz avatar nishidayuya avatar pat avatar pragtob avatar pschambacher avatar sachin21 avatar sferik avatar smortex avatar som4ik avatar tobyhs avatar xaviershay avatar yyamanoi1222 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplecov-html's Issues

Symbolic link attack within `coverage` directory can overwrite files elsewhere

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.

Steps to repro:

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.

Fails with `Errno::EACCES: Permission denied @ rb_sysopen` if vendor files are read-only

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.

Steps to repro:

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')

Version info

  • Ruby version: 3.3.0
  • Rails version: 7.1.3.2

Update colorbox

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.

Feature proposal: line number anchors

Using simplecov-html reports while doing active development is a bit painful right now:

  1. I'm looking at the coverage report for a file, and find some missing lines. Let's say, hypothetically, they're lines 503-505.
  2. Add tests that I think cover those lines and re-run my rspec rake task.
  3. Refresh the coverage report in my browser and... I'm back at the top of the page and need to scroll to line 503 again.

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.

Regression: non-ASCII characters are broken

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.

Could not locate Gemfile (Bundler::GemfileNotFound)

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)

Missing asset referenced

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.

<link rel="icon" type="image/png" href="<%= assets_path('favicon.png') %>" />

Filing an issue in case you'd like to fix this.

wrong assets paths

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

Feature Request: Update URL with file path.

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:

  1. A history so you can go back on the browser to previous files, etc.
  2. Reload the page after re-running the specs for that file and see the updated coverage.

Thoughts?

Disable pagination

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)

Appendix

Screenshots

Before

image

After

😢

The position of the search field is also a bit unintuitive

image

IOError

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 ...

Disagreement about coverage percentage

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.

Annoying warning

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

Error when requiring simplecov in spec_helper.rb

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.

License missing from gemspec

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.

Feature proposal: Inline assets

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).

  • index.html + ./assets: 584K
  • index.html with inline: 564K

Feature proposal: use CDN for assets or put them inline

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

Cannot refresh coverage page directly in version '0.12.0'

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?

Reuse of simplecov-html for utPLSQL v3

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.

CVE-2022-30123 : rack (2.2.3)

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.

Content-Security-Policy (CSP) violations

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

Modern interface

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 :)

✌️

Use Float#floor instead of Float#round

This is a follow-up of simplecov-ruby/simplecov#679

I'm having a 100% test coverage with some missed lines

image (5)

I suggest to stick with using Float#floor instead of round as simplecov does.

The changes would be in :

  • lib/simplecov-html.rb:41
  • lib/simplecov-html.rb:42
  • views/covered_percent.erb:2
  • views/file_list.erb:10
  • views/file_list.erb:61
  • views/file_list.erb:66
  • views/file_list.erb:68

Are you open to merge pull requests? I can submit one

Please publish new gem with updated .rubocop.yml

See screenshot below from Travis, which is showing deprecated Rubocop rules in the latest published gem (v.0.10.2):

Screen Shot 2019-08-02 at 10 33 54 PM

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.

Feature proposal: multiple coverages in one html

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.

Can't be used without rubygems loaded

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:

https://github.com/colszowka/simplecov-html/blob/65238a35cda44956e87dd520086095cbf1f2370d/lib/simplecov-html.rb#L8

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.

NoMethodError: undefined method `iso8601' for Time

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.

Javascript error in version '0.12.0', some pages cannot be open

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.

Errors in File.open

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?

Rubocop v0.64 (latest) not compatible with simplecov-html v0.10.2 (latest)

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!

HTML report not generated not every time

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.