Class: DeepCover::Reporter::Istanbul

Inherits:
Base
  • Object
show all
Defined in:
lib/deep_cover/reporter/istanbul.rb

Defined Under Namespace

Modules: Converters Classes: CoveredCodeConverter

Instance Attribute Summary

Attributes inherited from Base

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#analysis, #each, #initialize, #populate_stats

Methods included from Memoize

#freeze, included

Constructor Details

This class inherits a constructor from DeepCover::Reporter::Base

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/deep_cover/reporter/istanbul.rb', line 178

def available?
  `#{bin_path} --version` >= '11.' rescue false
end

.bin_pathObject



182
183
184
# File 'lib/deep_cover/reporter/istanbul.rb', line 182

def bin_path
  ::File.executable?('node_modules/.bin/nyc') ? 'node_modules/.bin/nyc' : 'nyc'
end

.report(coverage, **options) ⇒ Object



174
175
176
# File 'lib/deep_cover/reporter/istanbul.rb', line 174

def report(coverage, **options)
  new(coverage, options).report
end

Instance Method Details

#convertObject



144
145
146
147
148
# File 'lib/deep_cover/reporter/istanbul.rb', line 144

def convert
  each.to_a.to_h.transform_values  do |covered_code|
    CoveredCodeConverter.new(covered_code, **@options).convert
  end
end

#reportObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/deep_cover/reporter/istanbul.rb', line 158

def report
  output = @options[:output]
  dir = save.dirname
  unless [nil, false, '', 'false'].include? output
    output = File.expand_path(output)
    html = "--reporter=html --report-dir='#{output}'"
    if @options[:open]
      html += " && open '#{output}/index.html'"
    else
      msg = "\nHTML coverage written to: '#{output}/index.html'"
    end
  end
  `cd #{dir} && #{Istanbul.bin_path} report --exclude-after-remap=false --reporter=text #{html}` + msg.to_s
end

#save(dir: '.', name: '.nyc_output') ⇒ Object



150
151
152
153
154
155
156
# File 'lib/deep_cover/reporter/istanbul.rb', line 150

def save(dir: '.', name: '.nyc_output')
  path = Pathname.new(dir).expand_path.join(name)
  path.mkpath
  path.each_child(&:delete)
  path.join('deep_cover.json').write(JSON.pretty_generate(convert))
  path
end