jscov 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +97 -0
- data/Rakefile +10 -0
- data/app/controllers/jscov/application_controller.rb +5 -0
- data/app/controllers/jscov/coverages_controller.rb +14 -0
- data/config/routes.rb +3 -0
- data/lib/jscov.rb +28 -0
- data/lib/jscov/configuration.rb +16 -0
- data/lib/jscov/coverage.rb +13 -0
- data/lib/jscov/engine.rb +5 -0
- data/lib/jscov/helper.rb +26 -0
- data/lib/jscov/railtie.rb +11 -0
- data/lib/jscov/rspec.rb +7 -0
- data/lib/jscov/version.rb +3 -0
- data/lib/tasks/jscov_tasks.rake +4 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f29b1e1e112c912b6a7213210d3f156c9ca57e2ec7e01a2c5c9c1770051d7156
|
4
|
+
data.tar.gz: 5db3557ea568399e5de364d93fa6f7ba6beaad43f91b5e3dc2bf10d7beba48ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca06dc98ada7976f0edaab3935cb89c1ea8808f0f40b16ba444350f7f97c6ddad2a5a2804d0c359924f00c411a46403bbf0a80ccf91608f2dacfde4a5d959f45
|
7
|
+
data.tar.gz: 413eb1782c2cc65351c3b28fadb030d5fc79d4a3747dce8cb31596acc3f66ae68791a398d2774eaf0b099f02b2865ec8a0701bf14a6963eb78064ae31d67e8d6
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 Kazuki Nishikawa
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# Jscov
|
2
|
+
|
3
|
+
Collect JavaScript code coverages. It works with [istanbul](https://istanbul.js.org/).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'jscov'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
```bash
|
14
|
+
$ bundle
|
15
|
+
```
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
```bash
|
19
|
+
$ gem install jscov
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Install [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul).
|
25
|
+
|
26
|
+
```bash
|
27
|
+
$ yarn add -D babel-plugin-istanbul
|
28
|
+
```
|
29
|
+
|
30
|
+
And setup it. In babel.config.js:
|
31
|
+
|
32
|
+
```js
|
33
|
+
module.exports = function (api) {
|
34
|
+
// ....
|
35
|
+
return {
|
36
|
+
plugins: [
|
37
|
+
// ...
|
38
|
+
isTestEnv && 'babel-plugin-istanbul' // Add this
|
39
|
+
].filter(Boolean)
|
40
|
+
}
|
41
|
+
}
|
42
|
+
```
|
43
|
+
|
44
|
+
Mount `Jscov::Engine`. In route.rb:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
if Jscov.enabled?
|
48
|
+
mount Jscov::Engine => "/jscov"
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
Insert `jscov_script_tag` in your layout file:
|
53
|
+
|
54
|
+
```html
|
55
|
+
<html>
|
56
|
+
<head>
|
57
|
+
<%= jscov_script_tag %>
|
58
|
+
</head>
|
59
|
+
...
|
60
|
+
</html>
|
61
|
+
```
|
62
|
+
|
63
|
+
Load rspec helper. In spec/rails_helper.rb:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
require 'jscov/rspec'
|
67
|
+
```
|
68
|
+
|
69
|
+
Run `NODE_ENV=test RAILS_ENV=test bin/rails assets:precompile` for generating js codes that applied `istanbul`:
|
70
|
+
|
71
|
+
```bash
|
72
|
+
NODE_ENV=test RAILS_ENV=test bin/rails assets:precompile
|
73
|
+
```
|
74
|
+
|
75
|
+
OK, run rspec! It will dump collected coverage files in `tmp/jscov`.
|
76
|
+
The collected coverages can be output as a report using [nyc](https://github.com/istanbuljs/nyc).
|
77
|
+
|
78
|
+
```bash
|
79
|
+
$ npx nyc report --temp-dir=tmp/jscov
|
80
|
+
```
|
81
|
+
|
82
|
+
## Configuration
|
83
|
+
|
84
|
+
In `config/initializers/jscov.rb`, you can configure the following values.
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
Jscov.configure do |config|
|
88
|
+
# config.enabled = Rails.env.test?
|
89
|
+
# config.coverage_report_dir_path = Rails.root.join("tmp/jscov")
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
Contribution directions go here.
|
95
|
+
|
96
|
+
## License
|
97
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "jscov/coverage"
|
2
|
+
|
3
|
+
module Jscov
|
4
|
+
class CoveragesController < ApplicationController
|
5
|
+
skip_before_action :verify_authenticity_token
|
6
|
+
|
7
|
+
def create
|
8
|
+
raw_data = JSON.parse(params[:coverage])
|
9
|
+
coverage = Jscov::Coverage.new(raw_data)
|
10
|
+
coverage.save
|
11
|
+
head :no_content
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/config/routes.rb
ADDED
data/lib/jscov.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "securerandom"
|
2
|
+
require "jscov/engine"
|
3
|
+
require "jscov/railtie"
|
4
|
+
require "jscov/configuration"
|
5
|
+
|
6
|
+
module Jscov
|
7
|
+
class << self
|
8
|
+
def configuration
|
9
|
+
@configuration ||= Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure
|
13
|
+
yield configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
delegate :enabled?, to: :configuration
|
17
|
+
|
18
|
+
def new_coverage_file_path
|
19
|
+
configuration.coverage_report_dir_path.join("jscov_#{Time.current.to_i}_#{SecureRandom.uuid}.json")
|
20
|
+
end
|
21
|
+
|
22
|
+
def clean!
|
23
|
+
dir_path = configuration.coverage_report_dir_path
|
24
|
+
FileUtils.rm_f(Dir.glob(dir_path.join("jscov_*.json")))
|
25
|
+
FileUtils.mkdir_p(dir_path)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Jscov
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :enabled, :coverage_report_dir_path
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
reset!
|
7
|
+
end
|
8
|
+
|
9
|
+
alias enabled? enabled
|
10
|
+
|
11
|
+
def reset!
|
12
|
+
self.enabled = Rails.env.test?
|
13
|
+
self.coverage_report_dir_path = Rails.root.join("tmp/jscov")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/jscov/engine.rb
ADDED
data/lib/jscov/helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Jscov
|
2
|
+
module Helper
|
3
|
+
def jscov_script_tag
|
4
|
+
return unless Jscov.enabled?
|
5
|
+
|
6
|
+
javascript_tag jscov_javascript_code
|
7
|
+
end
|
8
|
+
|
9
|
+
def jscov_javascript_code
|
10
|
+
<<~JS
|
11
|
+
(function () {
|
12
|
+
window.addEventListener('unload', uploadCoverage)
|
13
|
+
|
14
|
+
function uploadCoverage () {
|
15
|
+
const cov = window.__coverage__
|
16
|
+
if (!cov) { return }
|
17
|
+
|
18
|
+
const data = new FormData()
|
19
|
+
data.append('coverage', JSON.stringify(cov))
|
20
|
+
navigator.sendBeacon('#{jscov.coverages_path}', data)
|
21
|
+
}
|
22
|
+
})()
|
23
|
+
JS
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/jscov/rspec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jscov
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kazuki Nishikawa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionview
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Jscov is a Rails Engine for collecting JavaScript code coverages.
|
56
|
+
email:
|
57
|
+
- kzkn@users.noreply.github.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- app/controllers/jscov/application_controller.rb
|
66
|
+
- app/controllers/jscov/coverages_controller.rb
|
67
|
+
- config/routes.rb
|
68
|
+
- lib/jscov.rb
|
69
|
+
- lib/jscov/configuration.rb
|
70
|
+
- lib/jscov/coverage.rb
|
71
|
+
- lib/jscov/engine.rb
|
72
|
+
- lib/jscov/helper.rb
|
73
|
+
- lib/jscov/railtie.rb
|
74
|
+
- lib/jscov/rspec.rb
|
75
|
+
- lib/jscov/version.rb
|
76
|
+
- lib/tasks/jscov_tasks.rake
|
77
|
+
homepage: https://github.com/kzkn/jscov
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubygems_version: 3.0.3
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Collect JavaScript code coverages.
|
100
|
+
test_files: []
|