jejacks0n / teaspoon

Teaspoon: Javascript test runner for Rails. Use Selenium, BrowserStack, or PhantomJS.
1.43k stars 243 forks source link

code coverage with expand_assets=false #436

Closed agieche closed 8 years ago

agieche commented 8 years ago

Hi,

we're trying to get code coverage via istanbul working with expand_assets=false. We're getting the following error message (coverage object is null, when using expand_assets=true, coverage object is defined):

$ bundle exec rake teaspoon

** Invoke teaspoon (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute teaspoon
Starting the Teaspoon server...
Teaspoon running default suite at http://127.0.0.1:63634/teaspoon/default
..

Finished in 2.28000 seconds
2 examples, 0 failures

Unable to generate text-summary coverage report:
/usr/local/lib/node_modules/istanbul/lib/collector.js:69
        Object.keys(coverage).forEach(function (key) {
               ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (native)
    at Object.Collector.add (/usr/local/lib/node_modules/istanbul/lib/collector.js:69:16)
    at /usr/local/lib/node_modules/istanbul/lib/command/report.js:111:27
    at Array.forEach (native)
    at /usr/local/lib/node_modules/istanbul/lib/command/report.js:109:19
    at /usr/local/lib/node_modules/istanbul/lib/util/file-matcher.js:39:20
    at Object.next (/usr/local/lib/node_modules/istanbul/node_modules/fileset/lib/fileset.js:43:14)
    at emitOne (events.js:77:13)
    at Fileset.emit (events.js:169:7)
    at Fileset.Glob._finish (/usr/local/lib/node_modules/istanbul/node_modules/fileset/node_modules/glob/glob.js:172:8)

versions:

$ teaspoon --version
1.1.1

$ ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]

teaspoon_env:

Teaspoon.configure do |config|
  config.mount_at = "/teaspoon"
  config.root = nil
  config.asset_paths = ["spec/javascripts", "spec/javascripts/stylesheets"]
  config.fixture_paths = ["spec/javascripts/fixtures"]

  config.suite do |suite|
    suite.use_framework :jasmine, "2.3.4"
    suite.matcher = "{spec/javascripts/desktop}/**/*_spec.{js,js.coffee,coffee,js.erb}"
    suite.helper = "spec_helper_desktop"
    suite.boot_partial = "boot"
    suite.body_partial = "body"
    suite.expand_assets = false
  end

  config.suite :mobile do |suite|
    suite.matcher = "{spec/javascripts/mobile}/**/*_spec.{js,js.coffee,coffee,js.erb}"
    suite.helper = "spec_helper_mobile"
  end

  config.use_coverage = true

  config.coverage do |coverage|
    coverage.reports = ["text-summary", 'html']
    coverage.ignore = [%r{.rvm}, %r{/lib/ruby/gems/}, %r{/vendor/assets/}, %r{/support/}, %r{/(.+)_helper.}, %r{/app/assets/javascripts/(.+)/vendor}, %r{/app/assets/javascripts/(.+)/vendor}, %r{/vendor/bundle}, %r{/spec/javascripts}]
    coverage.ignore = coverage.ignore.reject { |matcher| matcher.match('/spec_helper*.') }
  end
end

spec/javascripts/spec_helper_desktop.js

// Teaspoon includes some support files, but you can use anything from your own support path too.
// require support/jasmine-jquery-1.7.0
// require support/jasmine-jquery-2.0.0
// require support/jasmine-jquery-2.1.0
// require support/sinon
//
// PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion.
// Use this polyfill to avoid the confusion.
//= require support/phantomjs-shims
//= require support/factories
//= require support/promise
//= require desktop/application
//

spec/javascripts/spec_helper_mobile.js

// Teaspoon includes some support files, but you can use anything from your own support path too.
// require support/jasmine-jquery-1.7.0
// require support/jasmine-jquery-2.0.0
// require support/jasmine-jquery-2.1.0
// require support/sinon
//
// PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion.
// Use this polyfill to avoid the confusion.
//= require support/phantomjs-shims
//= require support/factories
//= require support/promise
//= require mobile/application
//

example spec: spec/javascripts/desktop/link_spec.js

describe('Link', function() {
    'use strict';
    it('should be available in global namespace', function() {
        expect(Link).toBeDefined();
    });
});

Is there an error within our config or is this an issue?

mikepack commented 8 years ago

Thank you for the excellent bug report. If you point your Gemfile at master, you should see a more friendly error message. The error you're seeing indicates the results could not be found because no files had been instrumented. In your case, they couldn't be found because you have /spec/javascripts in your ignore list and your helper is at .../spec/javascripts/spec_helper_desktop.js.