Showing posts with label istanbul. Show all posts
Showing posts with label istanbul. Show all posts

Tuesday, August 22, 2017

istanbul-instrumenter-loader: coverage issues don't match source

Leave a Comment

I'm using istanbul-instrumenter-loader to try to generate code coverage reports for my untranspiled es6 code, and while everything runs fine, the issues reported in the generated HTML output doesn't seem to line up with the actual source.

For example:

Incorrect coverage output

(in case the image is removed) A const declaration has 3 "if statement not covered" after it, even though there is no such statement or any code at all after that line. Sometimes "statement not covered" is marked in the middle of a string, or in an object declaration, or across multiple statements, etc etc.

Here's my Karma config file:

module.exports = function(config) {     config.set({         basePath: '../../',         frameworks: [ 'qunit' ],          files: [             'test/index.js',              // Session tickets             { pattern: 'test/tickets/*.json', watched: true, included: false, served: true }          ],          preprocessors: {             'test/index.js': 'webpack'         },         webpack: {             module: {                 rules: [{                     test: /\.js$/,                     exclude: /node_modules/,                     loaders: ['istanbul-instrumenter-loader', 'babel-loader']                 },                 {                     test: /\.vue$/,                     loaders: ['vue-loader']                 },                 {                     test: /\.png$/,                     loaders: ['url-loader']                 }]             }         },         reporters: [ 'coverage-istanbul', 'progress' ],         coverageIstanbulReporter: {             type: 'html',             dir: './coverage'             fixWebpackSourcePaths: true         },         port: 9876,         colors: true,         logLevel: config.LOG_INFO,         autoWatch: true,         browsers: [ 'Chrome' ],         browserNoActivityTimeout: 30000,         singleRun: true,         concurrency: Infinity,         client: {             captureConsole: true         },         browserConsoleLogOptions: {             terminal: true,             level: ''         }     }) }; 

1 Answers

Answers 1

karma-coverage and karma-webpack seem to be working together

"karma": "^0.12.28", "karma-coverage": "^0.2.7", "karma-sourcemap-loader": "^0.3.2", "karma-webpack": "^1.3.1", "webpack": "^1.4.14" 

Have you configured correctly , you can get more here https://github.com/webpack-contrib/istanbul-instrumenter-loader

and can u provide a a sample for your js file/spec

Read More

Saturday, March 19, 2016

Running mocha tests from node

Leave a Comment

I am trying to run my mocha tests from node . The ultimate goal is to add code-coverage via istanbul/blanket and generate a lcov file for input into sonar for code coverage.

This is a sample project on which I am trying https://github.com/rajarshigoswami/Todos

The mocha tests are under https://github.com/rajarshigoswami/Todos/tree/master/test/mocha

The tests are running from browser, but when I am trying via node, it wont pick up any of the spec files.

How to use : run : npm install then : grunt

My questions are :

  1. What am I missing or doing wrong here?
  2. How do I integrate blanket.js/istanbul to generate lcov files

3 Answers

Answers 1

I would change a few things. Simply add this to package.json

"scripts": {   "test":   "./node_modules/.bin/istanbul test ./node_modules/.bin/_mocha -- -R spec" } 

Now, when you do npm test it runs mocha and istambul

This article will help you

Answers 2

There's a few options depending what you need to do:

1) So firstly it would be good to know what you actually mean by running tests in node? For example I use to mocha to test server-side code for my node.js applications. It just runs the tests without relying on any specific environment (except node.js obviously). Without any other tools simply run mocha your/custom/test/directory/ (that assume your mocha is installed globally). So as long as your view test don't rely on being run in a Web Browser you're good.

2) If what you just want run your front-end tests without need of opening SpecRunner.html manually in a web browser, I highly recommend using karma test runner, with a headless browser like PhantomJS.

3) Finally if you already have the grunt installed just grab the mocha-istanbul npm module. The configuration is really simple:

mocha_istanbul: {     coverage: {         // where your tests leave         src: 'server/tests',         options: {             // instrument only spec files             mask: '*.spec.js',             // output a human readable website             // (along site regular test summary produced by mocha)             reportFormats: ['html']         }     } } 

So as you can see there are some options out there. Just grab the one that suits your project the best.

Answers 3

your problem is that you are trying to test code that using requirejs

in order for the you mocha spec to work with phantom and requirejs on a grunt task runner you can use grunt-mocha-phantomjs

for you other issue of using istambol check this link (this link is more suitable for your purpose because its use backbone also (-: )

Read More