propshaft-js-coverage 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 45b0cdef5510748a7220025542d359c363f5dafc42235c2243182b1aa8a0fc8a
4
+ data.tar.gz: 16336ae2f0629cb95dc0f024b15b96dc8ea500fa3aba8d883e73c88732b0fc6b
5
+ SHA512:
6
+ metadata.gz: 120ff098be347f3910e42eed790333a6361fa8a9948d76137d76ebac6347bdc31596bb7dd402d7c7f97ecd40f89a45aab9b41c9c3d6911f9ad082cbb4cff7ce1
7
+ data.tar.gz: 58b8084d25f2609fc8cd356c72adca3580fae24f22f0076d4932507849578587f9abf9024ce872c05273ac5a820e7f64488ea8d360908746a18e4cfed2a0bf59
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ Unreleased
2
+ ==========
3
+
4
+ **Key breaking changes:**
5
+
6
+ New features:
7
+
8
+ Updated features:
9
+
10
+ Removed features:
11
+
12
+ Internal improvements:
13
+
14
+ Testing improvements:
15
+
16
+ Others:
17
+
18
+ v0.1.0
19
+ ======
20
+
21
+ * Initial release
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Yoann Lecuyer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Installation
2
+
3
+ Add this line to your application's Gemfile:
4
+
5
+ ```ruby
6
+ gem 'propshaft-js-coverage'
7
+ ```
8
+
9
+ Add the compiler to propshaft
10
+
11
+ ```ruby
12
+ # config/initializers/assets.rb
13
+
14
+ if ENV["COVERAGE"]
15
+ Propshaft::Js::Coverage::Compiler.configure do |config|
16
+ config.should_process = ->(path) {
17
+ return false if path.match?(/vendor\/assets\//)
18
+ return false if path.match?(/gems\//)
19
+ return true
20
+ }
21
+ end
22
+
23
+ Rails.application.config.assets.compilers << [
24
+ "text/javascript", Propshaft::Js::Coverage::Compiler
25
+ ]
26
+ end
27
+ ```
28
+
29
+ Get the coverage reports after running your tests
30
+
31
+ ```ruby
32
+ # test/application_system_test_case.rb
33
+
34
+ require "test_helper"
35
+
36
+ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
37
+ def teardown
38
+ __coverage__ = page.evaluate_script <<-JS
39
+ JSON.stringify((typeof __coverage__ !== 'undefined') ? __coverage__ : null)
40
+ JS
41
+
42
+ if __coverage__ != "null"
43
+ File.write("#{JS_COVERAGE_DIR}/#{Time.now.to_i.to_s}.json", __coverage__)
44
+ end
45
+
46
+ super
47
+ end
48
+ end
49
+ ```
50
+
51
+ Convert to lcov and generate html report
52
+
53
+ ```bash
54
+ nyc report --reporter=lcov --temp-dir tmp/js-coverage --report-dir tmp/js-coverage
55
+ genhtml -q -o ./coverage ./tmp/js-coverage/lcov.info ./coverage/lcov/simplecov.lcov
56
+ ```
57
+
58
+ # How it works
59
+
60
+ This gem uses istanbul instrumenter to add coverage to your javascript files. It will add a global variable `__coverage__` to your javascript files. You can then use this variable to get the coverage report.
61
+
62
+ # Configuration
63
+
64
+ TBD
65
+
66
+ # Contributing
67
+
68
+ Clone the repo and run `bundle install` to install the dependencies.
69
+
70
+ Prepare the js script by running `yarn install` and `yarn run build` in the `js/instrumenter` directory.
71
+
72
+ # Release
73
+
74
+ Run `./scripts/release.sh` to release a new version after updating the version in `lib/propshaft/js/coverage/version.rb`.