Jscov
Collect JavaScript code coverages. It works with istanbul.
Installation
Add this line to your application's Gemfile:
gem 'jscov'
And then execute:
$ bundle
Or install it yourself as:
$ gem install jscov
Usage
Install babel-plugin-istanbul.
$ yarn add -D babel-plugin-istanbul
And setup it. In babel.config.js:
module.exports = function (api) {
// ....
return {
plugins: [
// ...
isTestEnv && 'babel-plugin-istanbul' // Add this
].filter(Boolean)
}
}
Mount Jscov::Engine
. In route.rb:
if Jscov.enabled?
mount Jscov::Engine => "/jscov"
end
Insert jscov_script_tag
in your layout file:
<html>
<head>
<%= jscov_script_tag %>
</head>
...
</html>
Load rspec helper. In spec/rails_helper.rb:
require 'jscov/rspec'
Run NODE_ENV=test RAILS_ENV=test bin/rails assets:precompile
for generating js codes that applied istanbul
:
NODE_ENV=test RAILS_ENV=test bin/rails assets:precompile
OK, run rspec! It will dump collected coverage files in tmp/jscov
.
The collected coverages can be output as a report using nyc.
$ npx nyc report --temp-dir=tmp/jscov
Configuration
In config/initializers/jscov.rb
, you can configure the following values.
Jscov.configure do |config|
# config.enabled = Rails.env.test?
# config.coverage_report_dir_path = Rails.root.join("tmp/jscov")
end
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.