Skip to content

Commit

Permalink
Adding mocha and jshint / jscs
Browse files Browse the repository at this point in the history
  • Loading branch information
elicwhite committed Apr 7, 2015
1 parent ebab6ae commit 4868499
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 2 deletions.
40 changes: 40 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

module.exports = function(grunt) {
grunt.initConfig({
path_validator: {
js: {
src: [
'**/*[A-Z]*.js',
'!node_modules/**/*.js',
'!Gruntfile.js'
]
}
},

jscs: {
files: {
src: [
'**/*.js',
'!node_modules/**'
]
}
},

jshint: {
options: {
jshintrc: true
},
files: {
src: [
'**/*.js',
'!node_modules/**'
]
}
}
});

require('load-grunt-tasks')(grunt);

grunt.registerTask('style', ['path_validator', 'jshint', 'jscs']);
};
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@
},
"devDependencies": {
"coveralls": "^2.11.2",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "^0.11.1",
"grunt-jscs": "^1.6.0",
"grunt-path-validator": "^1.0.1",
"istanbul": "^0.3.13",
"jscs": "^1.12.0",
"jshint": "^2.6.3",
"load-grunt-tasks": "^3.1.0",
"mocha": "^2.2.1",
"mocha-sinon": "^1.1.4",
"sinon": "^1.14.1"
},
"engines": {
"node": ">=0.8.0"
},
"scripts": {
"test": "grunt style && mocha --color",
"travis": "grunt style && istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
}
}
4 changes: 4 additions & 0 deletions stash.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ StashService.prototype = {
}
};

if (process.env.NODE_ENV === 'test') {
StashService.prototype.verifyConfig = verifyConfig;
}

module.exports = StashService;
7 changes: 7 additions & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../.jshintrc",
"mocha": true,
"globals": {
"assert": false
}
}
4 changes: 4 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test/*.js
-R dot
-u bdd
--require test/support/setup
66 changes: 66 additions & 0 deletions test/stash-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict';

var StashService = require('../stash');

describe('module/stash', function() {
var stashService;
var options;

beforeEach(function() {
options = {
url: 'url',
user: 'user',
password: 'password'
};
});

describe('constructor', function() {
describe('with invalid args', function() {
it('throws with non object', function() {
assert.throws(function() {
stashService = new StashService();
});

assert.throws(function() {
stashService = new StashService('foo');
});
});

describe('throws without', function() {
afterEach(function() {
assert.throws(function() {
stashService = new StashService(options);
});
});

it('url', function() {
delete options.url;
});

it('user', function() {
delete options.user;
});

it('user', function() {
delete options.user;
});
});

it('does not throw with all args', function() {
assert.doesNotThrow(function() {
stashService = new StashService(options);
});
});
});
});

describe('functions', function() {
beforeEach(function() {
stashService = new StashService(options);
});

it('#serviceKey is stash', function() {
assert.equal(stashService.serviceKey, 'stash');
});
});
});
12 changes: 12 additions & 0 deletions test/support/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

process.env.NODE_ENV = 'test';

var chai = require('chai');

var sinon = require('sinon');
sinon.assert.expose(chai.assert, {
prefix: ''
});

global.assert = chai.assert;

0 comments on commit 4868499

Please sign in to comment.