Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code coverage support #344

Merged
merged 4 commits into from
Dec 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ temp/
.idea
bin/venus-ERROR.AT.init.png
documentation
coverage/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ language: node_js
before_install:
- npm install
node_js:
- 0.8
- 0.10
34 changes: 34 additions & 0 deletions examples/mocha/code_coverage/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/** Some docblock comment stuff:
*
* Turnip greens yarrow ricebean rutabaga endive cauliflower sea lettuce
* kohlrabi amaranth water spinach avocado daikon napa cabbage asparagus winter
* purslane kale. Celery potato scallion desert raisin horseradish spinach
* carrot soko. Lotus root water spinach fennel kombu maize bamboo shoot green
* bean swiss chard seakale pumpkin onion chickpea gram corn pea. Brussels
* sprout coriander water chestnut gourd swiss chard wakame kohlrabi beetroot
* carrot watercress. Corn amaranth salsify bunya nuts nori azuki bean
* chickweed potato bell pepper artichoke.
*
*/
var testThing = {
/**
* Adds two numbers.
*/
add: function(num1, num2) {
return num1 + num2;
},

/**
* Subtracts num2 from num1.
*/
subtract: function(num1, num2) {
return num1 - num2;
},

/**
* Multiplies two numbers.
*/
multiply: function(num1, num2) {
return num1 * num2;
}
};
24 changes: 24 additions & 0 deletions examples/mocha/code_coverage/code.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @venus-library mocha
* @venus-code code.js
*/

describe('testThing', function() {
describe('.add()', function() {
it('should add numbers', function() {
expect(testThing.add(1, 1)).to.be(2);
});
});

describe('.multiply()', function() {
it('should multiply numbers', function() {
expect(testThing.multiply(2, 2)).to.be(4);
});
});

describe('.subtract()', function() {
it('should do subtraction', function() {
expect(testThing.subtract(5, 3)).to.be(2);
});
});
});
28 changes: 26 additions & 2 deletions lib/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
// Parse code coverage data
'use strict';

var fs = require('fs'),
path = require('path');
var fs = require('fs'),
logger = require('./util/logger'),
rmrf = require('rmrf');

function CodeCoverage() {}

Expand Down Expand Up @@ -109,6 +110,29 @@ CodeCoverage.prototype.parseBranches = function (data) {
* Write code coverage summary file
*/
CodeCoverage.prototype.writeSummary = function (data, isCodeCoverageEnabled, outputPath) {

// Write code coverage data
var istanbul = require('istanbul');
var reporter = new istanbul.Reporter();
var collector = new istanbul.Collector();

rmrf('./coverage');

data.forEach(function (d) {
collector.add(d);
});

reporter.add('html');
reporter.add('lcov');
reporter.add('text-summary');
reporter.add('cobertura');
reporter.add('clover');
reporter.add('json');

reporter.write(collector, true, function () {
logger.info('Wrote code coverage data to ./coverage');
});

var fileOutput =
['source file, total lines, code coverage, lines covered, lines not covered'];

Expand Down
7 changes: 6 additions & 1 deletion lib/testcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,12 @@ TestCase.prototype.copyFilesToHttpPath = function (files) {
if (this.instrumentCodeCoverage && path.instrumentable) {
// instrument the file with istanbul
promise.then(function () {
instrumenter = new Instrumenter();
instrumenter = new Instrumenter({
preserveComments: true,
noCompact: true,
embedSource: true,
noAutoWrap: true
});

fs.readFile(path.http, function (err, data) {
if (err) {
Expand Down
53 changes: 27 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,49 @@
"url": "https://github.com/linkedin/venus.js/issues"
},
"engines": {
"node": ">=0.8.0"
"node": ">=0.10.0"
},
"bin": {
"venus": "./bin/venus"
},
"license": "Apache 2.0",
"dependencies": {
"express": "3.6.0",
"socket.io": "0.8.7",
"socket.io-client": "0.9.6",
"async": "0.1.22",
"chokidar": "0.6.2",
"cli-prompt": "0.1.0",
"colors": "0.6.2",
"underscore": "1.3.3",
"i18n": "0.3.5",
"commander": "1.1.1",
"dustjs-linkedin": "0.6.0",
"consolidate": "0.3.0",
"winston": "0.6.1",
"json5": "0.1.0",
"portscanner": "0.1.3",
"underscore.string": "2.2.0rc",
"fs-tools": "0.2.2",
"async": "0.1.22",
"deferred": "0.6.5",
"dnode": "1.0.0",
"cli-prompt": "0.1.0",
"wrench": "1.4.3",
"useragent-parser": "0.1.1",
"istanbul": "0.1.27",
"mkdirp": "0.3.5",
"saucelabs": "0.0.9",
"sauce-connect-launcher": "0.1.3",
"dustjs-linkedin": "0.6.0",
"expect.js": "~0.2.0",
"chokidar": "0.6.2",
"express": "3.6.0",
"flavored-path": "0.0.8",
"fs-tools": "0.2.2",
"i18n": "0.3.5",
"istanbul": "0.3.4",
"json5": "0.1.0",
"mkdirp": "0.3.5",
"phantomjs": "1.9.7-8",
"portscanner": "0.1.3",
"rmrf": "1.0.2",
"sauce-connect-launcher": "0.1.3",
"saucelabs": "0.0.9",
"selenium-webdriver": "2.35.1",
"deferred": "0.6.5",
"socket.io": "0.8.7",
"socket.io-client": "0.9.6",
"underscore": "1.3.3",
"underscore.string": "2.2.0rc",
"useragent-parser": "0.1.1",
"when": "2.5.1",
"phantomjs": "1.9.7-8"
"winston": "0.6.1",
"wrench": "1.4.3"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-release": "^0.7.0",
"load-grunt-tasks": "^0.6.0",
"grunt": "0.4.5",
"grunt-release": "0.7.0",
"load-grunt-tasks": "0.6.0",
"mocha": "1.2.0",
"sinon": "1.3.4"
},
Expand Down