Skip to content

Commit

Permalink
migrating tests from vows to mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Apr 14, 2016
1 parent 6ae0334 commit 42e29c6
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 384 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ CVS/
.com.apple.timemachine.supported
coverage/
.idea/
artifacts
11 changes: 11 additions & 0 deletions .istanbul.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
reporting:
reports:
- lcov
- text
- text-summary
check:
global:
statements: 95
lines: 95
branches: 90
functions: 100
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ before_install:
node_js:
- "0.10"
- "0.12"
- "4.1"
- "4"
1 change: 1 addition & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var setDefaults = function(parsed) {
if (parsed === undefined) {
parsed = clean();
}
/*istanbul ignore else*/
if (parsed.color === undefined) {
parsed.color = chalk.supportsColor;
}
Expand Down
5 changes: 2 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ exports.init = function(options, callback) {

Object.keys(data).sort().forEach(function(item) {
if (!data[item].licenses) {
/*istanbul ignore else*/
/*istanbul ignore next*/
if (colorize) {
data[item].licenses = chalk.bold.red(UNKNOWN);
} else {
Expand Down Expand Up @@ -240,6 +240,7 @@ exports.init = function(options, callback) {
if (inputError === null && Object.keys(sorted).length === 1) {
Object.keys(sorted).forEach(function forEachCallback(item) {
var tempItem = chalk.stripColor(item);
/*istanbul ignore else*/
if (tempItem === 'undefined@undefined') {
inputError = new Error('No Npm Packages Found');
}
Expand All @@ -251,7 +252,6 @@ exports.init = function(options, callback) {
});
};

/*istanbul ignore next*/
exports.print = function(sorted) {
console.log(exports.asTree(sorted));
};
Expand Down Expand Up @@ -328,7 +328,6 @@ exports.asMarkDown = function(sorted, customFormat) {
return text;
};

/*istanbul ignore next*/
exports.parseJson = function(jsonPath) {
if (typeof jsonPath !== 'string') {
return new Error('did not specify a path');
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
"detectionizr": "*",
"format-package-json": "^0.2.0",
"git-contributors": "^0.2.3",
"istanbul": "*",
"istanbul": "^0.4.3",
"jenkins-mocha": "^2.6.0",
"jshint": "~1.1.0",
"queue": "^1.0.0",
"request": "^2.34.0",
"vows": "0.8.0",
"yui-lint": "~0.1.1"
},
"keywords": [
Expand All @@ -57,8 +57,8 @@
"scripts": {
"contrib": "./scripts/contrib.js",
"pretest": "jshint --config ./node_modules/yui-lint/jshint.json ./lib/",
"test": "istanbul cover --print both vows -- --spec ./tests/*.js",
"posttest": "istanbul check-coverage --statements 95 --functions 100 --lines 95 --branches 90"
"test": "jenkins-mocha ./tests/*.js",
"posttest": "istanbul check-coverage"
},
"preferGlobal": "true",
"bugs": {
Expand Down
34 changes: 13 additions & 21 deletions tests/bin-test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
var vows = require('vows'),
assert = require('assert'),
var assert = require('assert'),
path = require('path'),
spawn = require('child_process').spawn;

var tests = {
bin: {
topic: function() {
var test = this;
spawn(
'node', [path.join(__dirname, '../bin/license-checker')], {
stdio: 'ignore'
}
).on('exit', function(code) {
test.callback(code === 0);
});
},
'exits with code 0': function(code) {
assert.ok(code);
},
}
};

vows.describe('license-checker').addBatch(tests).export(module);
describe('bin/license-checker', function() {
this.timeout(8000);
it('should exit 0', function(done) {
spawn('node', [path.join(__dirname, '../bin/license-checker')], {
cwd: path.join(__dirname, '../'),
stdio: 'ignore'
}).on('exit', function(code) {
assert.equal(code, 0);
done();
});
});

});
161 changes: 60 additions & 101 deletions tests/license.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,63 @@
var vows = require('vows'),
assert = require('assert'),
var assert = require('assert'),
license = require('../lib/license');

var tests = {
loading: {
topic: function() {
return license;
},
'should be a function': function(topic) {
assert.isFunction(topic);
}
},
'undefined check': {
topic: function() {
return license(undefined);
},
'should return Undefined': function(data) {
assert.equal(data, 'Undefined');
}
},
'MIT check': {
topic: function() {
return license('asdf\nasdf\nasdf\nPermission is hereby granted, free of charge, to any');
},
'should return MIT': function(data) {
assert.equal(data, 'MIT*');
}
},
'MIT word check': {
topic: function() {
return license('asdf\nasdf\nMIT\nasdf\n');
},
'should return MIT': function(data) {
assert.equal(data, 'MIT*');
}
},
'BSD check': {
topic: function() {
return license('asdf\nRedistribution and use in source and binary forms, with or without\nasdf\n');
},
'should return BSD': function(data) {
assert.equal(data, 'BSD*');
}
},
'BSD word check': {
topic: function() {
return license('asdf\nasdf\nBSD\nasdf\n');
},
'should return BSD': function(data) {
assert.equal(data, 'BSD*');
}
},
'Apache word check': {
topic: function() {
return license('asdf\nasdf\nApache License\nasdf\n');
},
'should return Apache': function(data) {
assert.equal(data, 'Apache*');
}
},
'WTF check': {
topic: function() {
return license('DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE');
},
'should return WTFPL': function(data) {
assert.equal(data, 'WTFPL*');
}
},
'WTF word check': {
topic: function() {
return license('asdf\nasdf\nWTFPL\nasdf\n');
},
'should return WTFPL': function(data) {
assert.equal(data, 'WTFPL*');
}
},
'ISC check': {
topic: function() {
return license('asdfasdf\nThe ISC License\nasdfasdf');
},
'should return ISC': function(data) {
assert.equal(data, 'ISC*');
}
},
'ISC word check': {
topic: function() {
return license('asdf\nasdf\nISC\nasdf\n');
},
'should return ISC': function(data) {
assert.equal(data, 'ISC*');
}
},
'Check for null': {
topic: function() {
return license('this is empty, hi');
},
'should return null': function(data) {
assert.equal(data, null);
}
}
};
describe('license parser', function() {

vows.describe('licenses').addBatch(tests).export(module);
it('should export a function', function() {
assert.equal(typeof license, 'function');
});

it('undefined check', function() {
assert.equal(license(undefined), 'Undefined');
});

it('MIT check', function() {
var data = license('asdf\nasdf\nasdf\nPermission is hereby granted, free of charge, to any');
assert.equal(data, 'MIT*');
});

it('MIT word check', function() {
var data = license('asdf\nasdf\nMIT\nasdf\n');
assert.equal(data, 'MIT*');
});

it('BSD check', function() {
var data = license('asdf\nRedistribution and use in source and binary forms, with or without\nasdf\n');
assert.equal(data, 'BSD*');
});

it('BSD word check', function() {
var data = license('asdf\nasdf\nBSD\nasdf\n');
assert.equal(data, 'BSD*');
});

it('Apache word check', function() {
var data = license('asdf\nasdf\nApache License\nasdf\n');
assert.equal(data, 'Apache*');
});

it('WTF check', function() {
var data = license('DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE');
assert.equal(data, 'WTFPL*');
});

it('WTF word check', function() {
var data = license('asdf\nasdf\nWTFPL\nasdf\n');
assert.equal(data, 'WTFPL*');
});

it('ISC check', function() {
var data = license('asdfasdf\nThe ISC License\nasdfasdf');
assert.equal(data, 'ISC*');
});

it('ISC word check', function() {
var data = license('asdf\nasdf\nISC\nasdf\n');
assert.equal(data, 'ISC*');
});

it('Check for null', function() {
var data = license('this is empty, hi');
assert.equal(data, null);
});
});
Loading

0 comments on commit 42e29c6

Please sign in to comment.