Git Product home page Git Product logo

isparta's Introduction

๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€





๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€





isparta Build Status NPM version No Maintenance Intended

Isparta is a code coverage tool for ES6 using babel.

Its intention is to be used with karma and karma-coverage, which provides code coverage reports using istanbul.

CHANGELOG

Installation

Isparta can be installed using

$ npm install --save-dev isparta

Usage

Not all the istanbul command/options are available with isparta
Consult isparta -h for more information

Here is an example to run a coverage over mocha tests

babel-node node_modules/isparta/bin/isparta cover --report text --report html node_modules/mocha/bin/_mocha -- --reporter dot   

douglasduteil/study-node-path-es6 demo the working cli

With Karma

To use isparta, set the instrumenter for the JavaScript file type to isparta.

coverageReporter: {
  // configure the reporter to use isparta for JavaScript coverage
  // Only on { "karma-coverage": "douglasduteil/karma-coverage#next" }
  instrumenters: { isparta : require('isparta') },
  instrumenter: {
    '**/*.js': 'isparta'
  }
}

But can customize the babel options thanks to my fork

// Note that you ".babelrc" will be the default options for babel.
var babelMoreOptions = { presets: 'es2015' };

// [...]

coverageReporter: {
  // configure the reporter to use isparta for JavaScript coverage
  // Only on { "karma-coverage": "douglasduteil/karma-coverage#next" }
  instrumenters: { isparta : require('isparta') },
  instrumenter: {
    '**/*.js': 'isparta'
  },
  instrumenterOptions: {
    isparta: { babel : babelMoreOptions }
  }
}

License

Copyright ยฉ 2014 Douglas Duteil <[email protected]>
This work is free. You can redistribute it and/or modify it under the
terms of the Do What The Fuck You Want To Public License, Version 2,
as published by Sam Hocevar. See the LICENCE file for more details.

isparta's People

Contributors

austinpray avatar douglasduteil avatar felixkl avatar gregberge avatar hypercubed avatar jednano avatar lukescott avatar mattlewis92 avatar olegskl avatar renovate[bot] avatar roman01la avatar samshull avatar simenb avatar swatinem avatar taion avatar tbrisbout avatar tyronemichael avatar yhsiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

isparta's Issues

Add possibility to pass arguments to commad

With istanbul it's possible to pass mocha "--resursive" flag

istanbul cover node_modules/mocha/bin/_mocha -- --recursive

With isparta - no :(

root@fe860db3efc2:/srv# isparta  cover node_modules/mocha/bin/_mocha -- --recursive
'--recursive' expects a value


Usage: node isparta cover <cmd> [options]

cmd     ES6 js files to cover (using 6to5)

Options:
   --config <path-to-config>   the configuration file to use, defaults to .istanbul.yml
   --report <format>           report format, defaults to ['lcv']
   --root <path>               the root path to look for files to instrument, defaults to .
   -v, --verbose               verbose mode

transparently adds coverage information to a node command. Saves coverage.json and reports at the end of execution

Command line output

Thank you for this! Finally I can use Istanbul/Karma coverage with Babel. One thing: how do you get full command line text-summary output as shown in your demo?

full-text-summary

I only get top level stats and have to open the HTML report to drill down, but I'd like to set my karma config to output all stats as you have done.

top-level-summary

Here is my karma.conf.js:

var istanbul = require('browserify-istanbul'),
    isparta  = require('isparta');

module.exports =  function (config) {

    config.set({
        basePath: './',

        files: [
            './client/src/main.js',
            './client/src/components/**/*.js'
        ],

        preprocessors: {
            './client/**/*.js': ['browserify', 'babel', 'coverage']
        },

        browserify: {
            debug: true,
            transform: [
                istanbul({
                    instrumenter: isparta
                })
            ]
        },

        coverageReporter: {
            type : 'lcov',
            dir : 'reports/coverage/',
            reporters: [
                { type: 'html', subdir: '.' },
                { type: 'text-summary'}
            ]
        },

        browsers: ['Chrome'],
        frameworks: ['mocha', 'chai', 'browserify'],
        reporters: ['spec', 'coverage'],
        port: 9876,
        colors: true
    });
};

Coverage on more than one file

I cannot seem to get isparta to do coverage on more than one file. I am using Tape so when I run the following command node_modules/.bin/isparta cover test/*.js, it only reports coverage on the first file in that directory. Any ideas?

Am I still supposed to use the karma-coverage fork?

I'm trying karma coverage 0.3.1. karma-runner/karma-coverage/pull/130 was merged, but I'm getting the following error:

ERROR [coverage]: [TypeError: Cannot read property 'split' of undefined]
TypeError: Cannot read property 'split' of undefined
    at HtmlReport.Report.mix.writeDetailPage (/Users/lukescott/Documents/Projects/webconnex/director-js/node_modules/istanbul/lib/report/html.js:395:30)
    at /Users/lukescott/Documents/Projects/webconnex/director-js/node_modules/istanbul/lib/report/html.js:472:26
    at SyncFileWriter.extend.writeFile (/Users/lukescott/Documents/Projects/webconnex/director-js/node_modules/istanbul/lib/util/file-writer.js:57:9)
    at FileWriter.extend.writeFile (/Users/lukescott/Documents/Projects/webconnex/director-js/node_modules/istanbul/lib/util/file-writer.js:147:23)
    at /Users/lukescott/Documents/Projects/webconnex/director-js/node_modules/istanbul/lib/report/html.js:471:24
    at Array.forEach (native)
    at HtmlReport.Report.mix.writeFiles (/Users/lukescott/Documents/Projects/webconnex/director-js/node_modules/istanbul/lib/report/html.js:465:23)
    at /Users/lukescott/Documents/Projects/webconnex/director-js/node_modules/istanbul/lib/report/html.js:467:22
    at Array.forEach (native)
    at HtmlReport.Report.mix.writeFiles (/Users/lukescott/Documents/Projects/webconnex/director-js/node_modules/istanbul/lib/report/html.js:465:23)

It works with the fork though.

Statements/Branches/Lines coverage numbers seem wrong

@douglasduteil

First off, thanks for the tool. It seems like it's working well.

I am having one issue with it though, which is the coverage numbers are off. For example, it claims this file contains 34 branches, which is incorrect. It only contains one. I'm guessing it's calculating this from the actual compiled Babel output.

Is there anyway around this?

screen shot 2015-06-24 at 9 14 58 pm

cli: how to use `.es6` extension both for src and tests?

$ babel-node node_modules/.bin/isparta cover node_modules/.bin/_mocha -- test/*.es6

...

4 passing (7ms)

No coverage information was collected, exit without writing coverage information

original istanbul cover has -i option for this:

      -i <include-pattern> [-i <include-pattern>]
              one or more fileset patterns e.g. "**/*.js"

Babel CSS Imports

I've been struggling with this issue all day and I think this project is probably the right place to raise this, but if not my sincere apologies.

I am using isparta in my project react-demo and in my app.js file I have the following line:

import '../node_modules/css-reset/reset.css';

This is fine and compiles great with webpack, since I can specify a bunch of loaders to use, so babel knows how to translate *.css files.

Now that I'm using isparta as part of gulp-istanbul I don't (think I) have a way to tell babel to parse it via the css-loader.

I think at this stage it could really just ignore any imports that are not in a config, but maybe there is already a way of solving this, I just haven't managed to find.

My gulp task looks like the following:

import { Instrumenter } from 'isparta';

gulp.task('unit_tests', function(cb) {
  gulp.src(['src/**/*.js'])
    .pipe(istanbul({
      instrumenter: Instrumenter,
      includeUntested: true
    }))
    .pipe(istanbul.hookRequire())
    .on('finish', function() {
      gulp.src(['src/**/*.spec.js'])
        .pipe(mocha())
        .pipe(istanbul.writeReports())
        .pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } }))
        .on('end', cb);
    });
});

Maybe if there was a way to say:

instrumenter: Instrumenter({
    loaders: [{
      test: /\.css$/,
      loader: 'null-loader'
    }]
});

Thanks for the help, and also for the outstanding work done on isparta. It's been a great experience using the project.

Error: Object.assign is not a function

Z:\project\node_modules\isparta\lib\cli.js:197
    _istanbul.hook.hookRequire(matchFn, transformer, Object.assign({ verbose:
                                                            ^
TypeError: undefined is not a function

Babel 6 Support

Can't run tests under a project that uses babel 6 because isparta depends on babel 5...

npm package is completely broken

/lib folder is in .gitignore
/src folder is in .npmignore
so if i install this module by "npm install --save-dev douglasduteil/isparta" comand ill have almost empty folder in node_modules, without sources and without build (thx to @deepsweet, he broke package with bd87110 commit ). current node_modules/isparta structure is:

bin
node_modules
LICENSE
package.json
README.md
.npmignore

Push karma-coverage changes upstream?

Have you talked with the karma-coverage team about pushing your changes upstream that allow you to support arbitrary instrumentation and have more control over the the passed options?

I npm installed isparta + 6to5 + your karma-coverage fork to quickly get coverage working on a project with es6 modules that wasn't working with any of the esprima-harmony/esprima-fs based workarounds I tried.

At the very least having isparta becoming a valid option against the main karma-coverage repo would be nice.

Transformation error; return original code

Hello,

when I run

babel-node node_modules/.bin/isparta cover --report html node_modules/.bin/_mocha -- --recursive

I get the following error:

Transformation error; return original code
{ [Error: Line 1: Unexpected token ILLEGAL]
  lineNumber: 1,
  description: 'Unexpected token ILLEGAL',
  index: 0 }
Creating a pool connected to localhost:28015

Although tests pass and report is generated after the error...

I downgraded from 3.0.4 to 3.0.2 and error disappered.

Thanks

Not reporting "Only executed" and "ignored" statements

When running Istanbul with the default interpreter, I get an I to mark conditional statements that are never passed and an E to mark statements that are always executed.

Example:

// to test:
var testMe = function(do) {
  if (do) {
    do = 'ok';
 ย }
  return do
}

// the if should be marked as I
it('should mark it as ignored', function() {
  testMe();
});

// the if should be marked as E
it('should mark it as ignored', function() {
  testMe(true);
});

Only if you run both test cases on the function, Istanbul marks the function with green

As of 3.0.3, isparta is not recognized as a valid module.

npm install output for isparta:

Error when trying a manual require:

> require('isparta')
Error: Cannot find module 'isparta'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at repl:1:1
    at REPLServer.defaultEval (repl.js:132:27)
    at bound (domain.js:254:14)
    at REPLServer.runBound [as eval] (domain.js:267:12)
    at REPLServer.<anonymous> (repl.js:279:12)
    at REPLServer.emit (events.js:107:17)

isparta doesn't forward exit code in case of failures

The docs give this line as an example:

babel-node node_modules/.bin/isparta cover --report text --report lcovonly --root ./src node_modules/.bin/_mocha

The problem is it seems it doesn't forward the test exit status code properly, so we get successes instead of failures:

screen shot 2015-07-16 at 10 35 36

isparta v.3.0.3

Shebang is not handled

Getting the following error from command line:

Transformation error; return original code
{ [Error: Line 1: Unexpected token ILLEGAL]
  lineNumber: 1,
  description: 'Unexpected token ILLEGAL',
  index: 0 }

Esprima has said that they will not support this. While, istanbul supports this feature with test case covered.

It seems add a similar hack before pass transformed code to Esprima near here is OK.

TypeError: Cannot set property 'covered' of undefined

I've set up the custom fork and all, and it seems to be generating coverage for a few files, but then it bombs out with this error:

TypeError: Cannot set property 'covered' of undefined
    at /x/x/x/x/x/x/node_modules/istanbul/lib/report/html.js:175:66
    at Array.forEach (native)
    at annotateLines (/x/x/x/x/x/x/node_modules/istanbul/lib/report/html.js:173:28)
    at HtmlReport.Report.mix.writeDetailPage (/x/x/x/x/x/x/node_modules/istanbul/lib/report/html.js:395:9)
    at /x/x/x/x/x/x/node_modules/istanbul/lib/report/html.js:461:26
    at SyncFileWriter.extend.writeFile (/x/x/x/x/x/x/node_modules/istanbul/lib/util/file-writer.js:57:9)
    at FileWriter.extend.writeFile (/x/x/x/x/x/x/node_modules/istanbul/lib/util/file-writer.js:147:23)
    at /x/x/x/x/x/x/node_modules/istanbul/lib/report/html.js:460:24
    at Array.forEach (native)
    at HtmlReport.Report.mix.writeFiles (/x/x/x/x/x/x/node_modules/istanbul/lib/report/html.js:454:23)

Any ideas?

Karma server crashing with isparta/istambul

I have a grunt karma configuration with browserify options like this:

browserify: {
    debug: true,
    transform: [['browserify-istanbul', {instrumenter: require('isparta')}]]
}

When I run grunt karma:unit:start watch, the server never starts and I get an anonymous ">> Error" with no explanation, even with --verbose. The server is not running, and so the tests can't run.

grunt karma:once (with singleRun: true) works great.

I wouldn't expect this to have anything to do with isparta except that when I change my browserify options to simply

transform: ['babelify']

Then it works fine (though of course coverage isn't right)

My config roughly looks like this:

{
        options: {
            basePath: '',
            frameworks: ['browserify', 'jasmine'],

            preprocessors: {
                '<%= config.source %>/**/!(*spec|templates).js': [ 'browserify']
            },

            browserify: {
                debug: true,
                transform: [['browserify-istanbul', {instrumenter: require('isparta')}]]
                //This one works:
                //transform: [['babelify', { 'sourceMapRelative': '<%= config.source %>' }]]
            },

            reporters: ['dots', 'coverage'],
            coverageReporter: {
                reporters: [
                    { type: 'html' }
                ]
            },
            port: 9888,
            logLevel: 'INFO',
            browsers: ['PhantomJS']
        },
        unit: {
            background: true,
            singleRun: false,
            files: {
                src: ["<%= config.source %>/**/*.js"]
            }
        },
        once: {
            singleRun: true,
            files: '<%= karma.unit.files %>'
        }
    }

SyntaxError - Unable to run isparta.

I'm trying to run isparta with mocha using the following command:
babel-node node_modules/.bin/isparta cover node_modules/.bin/_mocha

The result is

project\node_modules\.bin\isparta:4
case `uname` in
^^^^

SyntaxError: Unexpected token case
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:413:25)
    at Module._extensions..js (module.js:452:10)
    at Object.require.extensions.(anonymous function) [as .js] (
project\node_modules\babel-core\lib\api\register\node.js:214:7)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at Object.<anonymous> (project\node_modules\babel\lib\_babel-node.js:144:25)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)

I use Windows, Node 4.2.1 and Babel 5.8.23
What I'm doing wrong?

How to cover JSX / React components?

isparta only covers *.js files. How can I enable coverage for *.jsx files? I already added the .jsx extension to my .istanbul.yml but unfortunately it's not working.

package.json

  "scripts": {
    "prepublish": "gulp",
    "test": "mocha --colors --compilers js:babel/register --require test/setup.js test/*.js*",
    "posttest": "babel-node node_modules/.bin/isparta cover node_modules/.bin/_mocha"
  },

.istanbul.yml

instrumentation:
  root: src
  extensions:
    - .js
    - .jsx

Coverage seems to be incorrect

I am using karma-coverage and I am getting like 98%+ coverage on all of my files and I know my tests don't exercise that much of the code. Any idea why the coverage is falsely high?

It's like it's only reporting for what the tests run for and not the remainder of the JS in each file.

TypeError with project based on gulp-angular Yeoman boilerplate

I installed isparta which made a lot of changes to my package.json - including "karma-coverage": "douglasduteil/karma-coverage#next"

However, now I can't run my tests at all. (Yes, gulp test worked flawlessly before.)

[10:37:35] Finished 'scripts:test' after 7.73 s
[10:37:35] Starting 'test'...
[BABEL] Note: The code generator has deoptimised the styling of "./.tmp/serve/app/index.module.js" as it exceeds the max of "100KB".
PhantomJS 1.9.8 (Mac OS X 0.0.0) ERROR
  TypeError: 'undefined' is not an object (evaluating 'u._')
  at /Users/keith/Code/whamserver-prod/src/apps/DefaultWithGulp/.tmp/serve/app/index.module.js:9


[10:37:41] 'test' errored after 6.22 s
[10:37:41] Error: Failed 1 tests.
    at /Users/keith/Code/whamserver-prod/src/apps/DefaultWithGulp/gulp/unit-tests.js:41:22
    at removeAllListeners (/Users/keith/Code/whamserver-prod/src/apps/DefaultWithGulp/node_modules/karma/lib/server.js:329:7)
    at Server.<anonymous> (/Users/keith/Code/whamserver-prod/src/apps/DefaultWithGulp/node_modules/karma/lib/server.js:340:9)
    at Server.g (events.js:260:16)
    at emitNone (events.js:72:20)
    at Server.emit (events.js:166:7)
    at emitCloseNT (net.js:1518:8)
    at doNTCallback1 (node.js:418:9)
    at process._tickCallback (node.js:340:17)
Keiths-MacBook-Pro:DefaultWithGulp keith$ 

Trouble using with 6to5ify

I'm trying to get code coverage reports for an app I'm writing, which is intended to be consumed in an iOS or Android webview. Because of severe bandwidth restrictions, I'm swapping out the backbone dependency through a mapping in my package.json's browser node. This works in browserify, but apparently isparta doesn't read this. This silently fails and causes my coverage to report 100% coverage, but when I run it from command line I get an error about this dependency. Any idea how I can get proper instrumentation on my Browserified 6to5 code?

Include doesn't work

I tried to scan .es6 files source with include options but seem not work!
If replace my source code in .js it works.
This is the command:

./node_modules/.bin/babel-node ./node_modules/.bin/isparta cover --include "**/*.es6" -v ./node_modules/.bin/_mocha -- "./test/**/*.es6" --compilers js:babel/register --require "./test/index.js"

This is the verbose output:

Using configuration
-------------------
verbose: true
instrumentation:
    root: .
    extensions:
        - .js
    default-excludes: true
    excludes: []
    embed-source: false
    variable: __coverage__
    compact: true
    preserve-comments: false
    complete-copy: false
    save-baseline: false
    baseline-file: ./coverage/coverage-baseline.json
    include-all-sources: false
    include-pid: false
    preload-sources: false
reporting:
    print: summary
    reports:
        - lcov
    dir: ./coverage
    watermarks:
        statements: [50, 80]
        lines: [50, 80]
        functions: [50, 80]
        branches: [50, 80]
    report-config:
        clover: {file: clover.xml}
        cobertura: {file: cobertura-coverage.xml}
        json: {file: coverage-final.json}
        json-summary: {file: coverage-summary.json}
        lcovonly: {file: lcov.info}
        teamcity: {file: null}
        text: {file: null, maxCols: 0}
        text-lcov: {file: lcov.info}
        text-summary: {file: null}
hooks:
    hook-run-in-context: false
    post-require-hook: null
    handle-sigint: false
check:
    global:
        statements: 0
        lines: 0
        branches: 0
        functions: 0
        excludes: []
    each:
        statements: 0
        lines: 0
        branches: 0
        functions: 0
        excludes: []

-------------------

Isparta options : 
  { '0': 'cover',
  '--': 
   [ './test/**/*.es6',
     '--compilers',
     'js:babel/register',
     '--require',
     './test/index.js' ],
  include: [ '**/*.es6', './node_modules/.bin/_mocha' ],
  verbose: true,
  cmd: './node_modules/.bin/_mocha',
  _: [ 'cover', './node_modules/.bin/_mocha' ],
  report: 'lcv' }
Running: node /Users/lug/Projects/pr221/node_modules/.bin/_mocha ./test/**/*.es6 --compilers js:babel/register --require ./test/index.js

passing AMD defined files along with es6 files (import) breaks the output

Well, ATM I'm working on a project where some of the files are sort of "legacy" ones (They are defined with AMD syntax), alongside with es6 files (Using import).

The thing is, whenever I try to use isparta on the es5 along with the es6 ones, the es5 files gets screwed up. For example:

// requests.js
define(['jquery'], function($) {
return $.ajax(...);
});

and then on the karma output I will get:

TypeError: 'undefined' is not an object (evaluating '$.ajax')

What am I doing wrong here?

Ignoring Statements, Branches, etc.?

@nathancahill and I are seeing statements and branches ignored, even though there are no ignore comments in our source code. It looks like this:

=============================== Coverage summary ===============================
Statements   : 100% ( 138/138 ), 10 ignored
Branches     : 98.61% ( 71/72 ), 9 ignored
Functions    : 100% ( 12/12 )
Lines        : 100% ( 69/69 )
================================================================================

Any idea why code is being ignored for seemingly no reason? Or maybe the report is off somehow?

No element indexed by 1

Hello, I'm trying to setup isparta to replace istanbul. I've replaced my karma-coverage module with @douglasduteil custom one. Is there anything else that I'm missing here? If I just use regular karma-coverage then my tests run.

Error.

19 09 2015 22:43:56.243:ERROR [preprocessor.coverage]: No element indexed by 1
  at d:/Web/GitHub/angularjs-unit-testing-patterns/example/packages/app.js
19 09 2015 22:43:56.244:ERROR [preprocessor.babel]: Not a string or buffer
 at d:/Web/GitHub/angularjs-unit-testing-patterns/example/packages/app.js

karma.conf.js

(function () {

  'use strict';

  module.exports = function (config) {
    config.set({
      basePath: '',
      frameworks: [
        'chai',
        'mocha',
        'sinon'
      ],
      files: [
        'example/libs/angular/angular.js',
        'example/libs/angular-ui-router/release/angular-ui-router.js',
        'node_modules/angular-mocks/angular-mocks.js',
        'example/packages/**/*.js',
        'example/**/*.spec.js',
        'example/**/*.html'
      ],
      preprocessors: {
        '**/example/packages/**/*.js': 'babel',
        '**/example/packages/**/!(*.spec).js': 'coverage',
        '**/*.html': 'ng-html2js'
      },
      exclude: [],
      reporters: ['mocha', 'coverage'],
      port: 9876,
      colors: true,
      logLevel: config.LOG_INFO,
      autoWatch: false,
      browsers: ['PhantomJS'],
      singleRun: true,
      coverageReporter: {
        instrumenters: {
          isparta: require('isparta')
        },
        instrumenter: {
          '**/example/packages/**/*.js': 'isparta'
        },
        reporters: [
          {
            type: 'text-summary'
          },
          {
            type: 'html',
            dir: 'reports/coverage'
          }
        ]

      },
      ngHtml2JsPreprocessor: {
        stripPrefix: 'example/',
        moduleName: 'karma.templates'
      },
      babelPreprocessor: {
        options: {
          sourceMap: 'inline'
        },
        filename: function (file) {
          return file.originalPath.replace(/\.js$/, '.es5.js');
        },
        sourceFileName: function (file) {
          return file.originalPath;
        }
      }
    });
  };

})();

How to skip statements/functions?

This function is only called when there is an error (it displays an error dialog on web page). It is not useful to test the coverage of this function.

screen shot 2015-03-05 at 17 11 26

In Istanbul, you could use /* istanbul skip next */, but it doesn't work in Isparta. I also tried /* isparta ignore next */ without success.

Publish nomnom fork

Hey,

Could you publish your nomnom-fork to npm? I'd like to use isparta on a box that has no access to the internet, but does have access to npm through a proxy

isparta binary doesn't work because methods are nested under 'default'

Here the methods of nomnom are nested under default and here isparta tries to access them from the root.

As a result:

/usr/local/lib/node_modules/isparta/lib/cli.js:36
nomnom.command("cover").help("transparently adds coverage information to a nod
       ^
TypeError: Object #<Object> has no method 'command'
    at Object.<anonymous> (/usr/local/lib/node_modules/isparta/lib/cli.js:36:8)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/isparta/bin/isparta:2:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

Do not print to console

I would prefer if my coverage reports were generated, but isparta did not print to the console. Is there an option for this?

Unable to pass include information to istanbul

I was trying to make sure that a certain file was loaded first by isparta / istanbul by passing --include path/to/first.js --include **/*.js, however this didn't seem to 'make it to istanbul'. It seems to go wrong on this line:

includes: opts.includes || config.instrumentation.extensions()

Since ops.includes is read there where the actual option is called ops.include as far as I can tell. I didn't open a pull request since I was unsure whether you wanted to make the cli argument --includes (that would be nicely symmetrical with --excludes) or that you wanted to fix this on the line mentioned above. I would guess the former, however the commandline argument is a 'public api' of course. Then again: I don't think those includes are working anyway.

Object.assign is not a function

Since #55 (comment) and pull request #61 I get a

Loading config: /Users/me/Development/my_project/.istanbul.yml
/Users/me/Development/my_project/node_modules/isparta/lib/cli.js:197
    _istanbul.hook.hookRequire(matchFn, transformer, Object.assign({ verbose:
                                                            ^
TypeError: Object.assign is not a function
    at prepareCoverage (/Users/me/Development/my_project/node_modules/isparta/lib/cli.js:197:61)
    at /Users/me/Development/my_project/node_modules/isparta/lib/cli.js:187:7
    at /Users/me/Development/my_project/node_modules/isparta/node_modules/istanbul/lib/util/file-matcher.js:68:16
    at /Users/me/Development/my_project/node_modules/isparta/node_modules/istanbul/node_modules/async/lib/async.js:52:16
    at /Users/me/Development/my_project/node_modules/isparta/node_modules/istanbul/node_modules/async/lib/async.js:363:13
    at /Users/me/Development/my_project/node_modules/isparta/node_modules/istanbul/node_modules/async/lib/async.js:52:16
    at done (/Users/me/Development/my_project/node_modules/isparta/node_modules/istanbul/node_modules/async/lib/async.js:248:21)
    at /Users/me/Development/my_project/node_modules/isparta/node_modules/istanbul/node_modules/async/lib/async.js:44:16
    at /Users/me/Development/my_project/node_modules/isparta/node_modules/istanbul/node_modules/async/lib/async.js:360:17

I am using iojs v2.5.0

No `includeUntested` Option?

I am wondering if there is any includeUntested option as there is in instanbul? I would think it would be useful to know where completely untested code factors into the equation.

merge efforts into istanbul?

Hi, istanbul author here.

Would it make sense to add options to istanbul to make what you are doing possible directly in it?

Example:

  • Allow a pre-loader hook that istanbul respects for babel transforms to es6 files
  • Add source map support

My vested interest in this is that there are many other applications other than ES6 where source maps for instance is useful (e.g. minification/ bundling use cases for es5)

etc.

[Study result]: wrong coverage skipping format for functions

The additional babel functions aren't ignored !

code coverage report for study node path es6 index js

Parts of the generated coverage result are wrong. I'm assigning skip at the location level for all the metrics but for the functions it's suppose to be assigned at the root of the metric.

Expected metric models

  • For a statements
{
  "0": {
      "start": {
          "line": 7,
          "column": 0
      },
      "end": {
          "line": 7,
          "column": 13
      },
      "skip": true
  }
}
  • For a functions
{
  "0": {
    "name": "foo",
    "line": 16,
    "loc": {
      "start": {
        "line": 16,
        "column": 0
      },
      "end": {
        "line": 16,
        "column": 15
      }
    },
    "skip": true
  }
}
  • For a branches
{
  "0": {
    "line": 12,
    "type": "cond-expr",
    "locations": [{
      "start": {
        "line": 12,
        "column": 19
      },
      "end": {
        "line": 12,
        "column": 20
      },
      "skip": true
    }, {
      "start": {
        "line": 12,
        "column": 23
      },
      "end": {
        "line": 12,
        "column": 24
      },
      "skip": true
    }]
  }
}

check coverage option

It would be awesome if there was a way to set coverage thresholds directly on the cover call or if there was a way to add the check-coverage method from istanbul I'd love that.

Specifically running into this problem here:
pocesar/grunt-mocha-istanbul#45

Happy to code it up if needed.

The license prevents corporate using

Hey,
first of all thanks for awesome work!

It may sound like a silly request but can you substitute your license by something more friendly for corporate layers? In our project we have to receive juridical approval about using open-source libraries. Likely they won't be happy with this license ;)

Thanks!

TAP/tape support

I am using tap for tests and while it does let you tap in coverage enabling a --coverage flag, I am not sure how to make it work with isparta or ES6.

Note: compare Istanbul and Isparta html reporter result

"Virgin" code (not touched by the 6to5 transformers) can cover through Istanbul and Isparta.
We expect both to result with the same coverage data.

  • Data Diff
rm -rf coverage-es5 &&  istanbul cover --dir coverage-es5 --report json  _mocha && \
python -mjson.tool coverage-es5/coverage-final.json > coverage-es5/coverage.json && \
rm -rf coverage-es6 &&  isparta cover --dir coverage-es6 --report json  _mocha && \
python -mjson.tool coverage-es6/coverage-final.json > coverage-es6/coverage.json && \
vimdiff  coverage-es5/coverage.json  coverage-es6/coverage.json 
  • Visual Diff
rm -rf coverage-es5 &&  istanbul cover --dir coverage-es5 --report html  _mocha && \
rm -rf coverage-es6 &&  isparta cover --dir coverage-es6 --report html  _mocha && \
google-chrome coverage-es6/index.html coverage-es5/index.html

Error: Don't hotlink Babel files.

I'm using a gulp setup very similar to this:

https://github.com/babel/babel-library-boilerplate

Has been working, but recently has begun throwing this error when running gulp commands.

/Users/nackjicholson/repos/jobs-service/node_modules/isparta/node_modules/babel-core/lib/babel/tools/protect.js:15
    throw new Error("Don't hotlink internal Babel files.");
          ^
Error: Don't hotlink internal Babel files.
    at Object.exports.default (/Users/nackjicholson/repos/jobs-service/node_modules/isparta/node_modules/babel-core/lib/babel/tools/protect.js:15:11)
    at Object.<anonymous> (/Users/nackjicholson/repos/jobs-service/node_modules/isparta/node_modules/babel-core/lib/babel/api/node.js:42:28)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)
    at Function.Module._load (module.js:306:12)
    at Module.require (module.js:361:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/nackjicholson/repos/jobs-service/node_modules/isparta/lib/instrumenter.js:25:23)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)
    at Function.Module._load (module.js:306:12)
    at Module.require (module.js:361:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/nackjicholson/repos/jobs-service/node_modules/isparta/lib/isparta.js:19:21)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)
    at Function.Module._load (module.js:306:12)
    at Module.require (module.js:361:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/nackjicholson/repos/jobs-service/gulp/test.js:4:15)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)
    at Function.Module._load (module.js:306:12)
    at Module.require (module.js:361:17)
    at require (module.js:380:17)
    at requireDir (/Users/nackjicholson/repos/jobs-service/node_modules/require-dir/index.js:116:33)
    at Object.<anonymous> (/Users/nackjicholson/repos/jobs-service/gulpfile.js:2:23)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)
    at Function.Module._load (module.js:306:12)
    at Module.require (module.js:361:17)
    at require (module.js:380:17)
    at Liftoff.handleArguments (/Users/nackjicholson/.nvm/versions/io.js/v2.2.1/lib/node_modules/gulp/bin/gulp.js:116:3)
    at Liftoff.<anonymous> (/Users/nackjicholson/.nvm/versions/io.js/v2.2.1/lib/node_modules/gulp/node_modules/liftoff/index.js:192:16)
    at module.exports (/Users/nackjicholson/.nvm/versions/io.js/v2.2.1/lib/node_modules/gulp/node_modules/liftoff/node_modules/flagged-respawn/index.js:17:3)
    at Liftoff.<anonymous> (/Users/nackjicholson/.nvm/versions/io.js/v2.2.1/lib/node_modules/gulp/node_modules/liftoff/index.js:185:9)
    at /Users/nackjicholson/.nvm/versions/io.js/v2.2.1/lib/node_modules/gulp/node_modules/liftoff/index.js:159:9
    at /Users/nackjicholson/.nvm/versions/io.js/v2.2.1/lib/node_modules/gulp/node_modules/v8flags/index.js:79:12
    at /Users/nackjicholson/.nvm/versions/io.js/v2.2.1/lib/node_modules/gulp/node_modules/v8flags/index.js:35:7
    at doNTCallback0 (node.js:408:9)
    at process._tickCallback (node.js:337:13)
    at Function.Module.runMain (module.js:469:11)
    at startup (node.js:117:18)
    at node.js:946:3

gulp babel and isparta

For some reason I can't use the normal ES6 imports with isparta in my gulpfile. If I use require it all works correctly, runs all my tests and covers all my code. But when I change over to use import I get:

$ gulp mocha
[14:54:55] Requiring external module babel/register
[14:54:56] Using gulpfile ~/Work/XXX/gulpfile.babel.js
[14:54:56] Starting 'istanbul'...

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: Unable to parse /Users/ed/Work/XXX/src/chat.js

Line 1: Unexpected reserved word

gulpfile:

import gulp from 'gulp'
import istanbul from 'gulp-istanbul'
// import isparta from 'isparta' // Doesn't work
const isparta = require('isparta') // Works
import mocha from 'gulp-mocha'

gulp.task('istanbul', cb => {
  gulp.src(['./src/**/*.js'])
    .pipe(istanbul({
      instrumenter: isparta.Instrumenter,
      includeUntested: true,
      babel: { stage: 0 }
    }))
    .pipe(istanbul.hookRequire())
    .on('finish', cb)
})

gulp.task('mocha', ['istanbul'], () => {
  return gulp.src('./test/**/*.js')
    .pipe(mocha({
      reporter: 'spec'
    }))
    .pipe(istanbul.writeReports({
      dir: './coverage',
      reportOpts: {dir: './coverage'},
      reporters: ['lcovonly']
    }))
})

Babel can't parse _mocha

When running

babel-node node_modules/.bin/isparta cover --report html node_modules/.bin/_mocha

As suggested by the README, I encounter this error:

Transformation error; return original code
{ [SyntaxError: /Users/leebyron/src/graphql-js/node_modules/mocha/bin/_mocha: 'return' outside of function (392:2)]
  pos: 9902,
  loc: { line: 392, column: 2 },
  raisedAt: 9908,
  _babel: true,
  codeFrame: '  390 |   \u001b[32m}\u001b[39m\u001b[34m\u001b[1m)\u001b[22m\u001b[39m\u001b[1m;\u001b[22m\n  391 | \n> 392 |   \u001b[36mreturn\u001b[39m\u001b[1m;\u001b[22m\n      |   ^\n  393 | \u001b[32m}\u001b[39m\n  394 | \n  395 | \u001b[90m// load\u001b[39m' }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.