propshaft-js-coverage 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ module Propshaft
2
+ module Js
3
+ module Coverage
4
+ class Compiler < Propshaft::Compiler
5
+ class << self
6
+ @@context = nil
7
+
8
+ def configure
9
+ yield config
10
+ end
11
+
12
+ def config
13
+ @config ||= Configuration.new
14
+ end
15
+ end
16
+
17
+ def compile(asset, input)
18
+ if Propshaft::Js::Coverage::Compiler.config.should_process
19
+ return input unless Propshaft::Js::Coverage::Compiler.config.should_process.call(asset.path.to_s)
20
+ end
21
+
22
+ begin
23
+ covered_source = $context.call("instrument", input, asset.path.to_s)
24
+ rescue => e
25
+ warn "Error instrumenting #{asset.path}: #{e}"
26
+ return input
27
+ end
28
+ covered_source
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ module Propshaft
2
+ module Js
3
+ module Coverage
4
+ class Configuration
5
+ attr_accessor :should_process
6
+
7
+ def initialize
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Propshaft
4
+ module Js
5
+ module Coverage
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "propshaft"
4
+ require "mini_racer"
5
+ require_relative "coverage/version"
6
+ require_relative "coverage/configuration"
7
+ require_relative "coverage/compiler"
8
+
9
+ $context = MiniRacer::Context.new
10
+ $context.eval("var instrument, instrumenterReady = false;")
11
+ gem_root = File.expand_path '../../../..', __FILE__
12
+ $context.load(File.expand_path("#{gem_root}/js/instrumenter/dist/main.js"))
13
+
14
+ # wait for the instrumenter to be ready
15
+ 5.times do
16
+ ready = $context.eval("instrumenterReady")
17
+ break if ready
18
+ sleep(1)
19
+ end
20
+
21
+ module Propshaft
22
+ module Js
23
+ module Coverage
24
+ class Error < StandardError; end
25
+ # Your code goes here...
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: propshaft-js-coverage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yoann Lecuyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: propshaft
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: mini_racer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.16.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.16.0
41
+ description: Adds a propshaft compiler to add coverage to your JavaScript files
42
+ email:
43
+ - yoann.lecuyer@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG.md
49
+ - LICENSE
50
+ - README.md
51
+ - js/instrumenter/dist/main.js
52
+ - lib/propshaft/js/coverage.rb
53
+ - lib/propshaft/js/coverage/compiler.rb
54
+ - lib/propshaft/js/coverage/configuration.rb
55
+ - lib/propshaft/js/coverage/version.rb
56
+ homepage: https://github.com/ylecuyer/propshaft-js-coverage
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ homepage_uri: https://github.com/ylecuyer/propshaft-js-coverage
61
+ source_code_uri: https://github.com/ylecuyer/propshaft-js-coverage
62
+ changelog_uri: https://github.com/ylecuyer/propshaft-js-coverage/blob/master/CHANGELOG.md
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 3.0.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.3.26
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Add coverage to your JavaScript files
82
+ test_files: []