0

I writting an app using Backbone/Marionette and RequireJS with AMD-style modules and I trying to add a coverage step to it, but, when running istanbul cover myTestFile.js, istanbul throws this error:

__cov_EsyvGtIcLKP7TgjU5WMSQw.s['1']++;define(function(require){__cov_EsyvGtIcL define is not defined

I don't how to fix this as I've never done coverage for browser side code and this is my first time using AMD style module.

Istanbul also says a coverage report was written, so I don't understand if that means that it actually ran successfully or not.

Any pointers would be of great help. Here's the complete output of the istanbul cover mytestfile.js command (with some detauls changed):

=============================================================================
Writing coverage object [/Users/myuser/src/myapp/coverage/coverage.json]
Writing coverage reports at [/Users/myuser/src/myapp/coverage]
=============================================================================

=============================== Coverage summary ===============================
Statements   : 5% ( 1/20 )
Branches     : 0% ( 0/2 )
Functions    : 0% ( 0/5 )
Lines        : 5% ( 1/20 )
================================================================================
/Users/myuser/src/myapp/app/myapp/app-collection.js:9
__cov_EsyvGtIcLKP7TgjU5WMSQw.s['1']++;define(function(require){__cov_EsyvGtIcL
                                      ^
ReferenceError: define is not defined
    at Object.<anonymous> (/Users/mysuser/src/myapp/app/myapp/app-collection.js:9:39)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/istanbul/lib/hook.js:107:24)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/myuser/src/myapp/test/specs/applications-tests.js:9:25)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
Hugo
  • 6,244
  • 8
  • 37
  • 43
  • 1
    The `istanbul cover test.js` runs the test script in *Node*, which is very different than running in the browser, where it is supposed to run. Take a look at [Karma](http://karma-runner.github.io). – Nikos Paraskevopoulos Jul 21 '15 at 07:26
  • @NikosParaskevopoulos Ended up using Karma. A couple of hours setting up the config for RequireJS with Karma was enough to have it working – Hugo Sep 16 '15 at 21:52

0 Answers0