Skip to content

Commit

Permalink
Changed test suite to use mocha for #10; WIP
Browse files Browse the repository at this point in the history
Update the test suite to use Mocha. This tests results in creation of
the model objects in /models. The ultimate goal is to create unit tests
that are not dependent upon the actual database, in order to enforce
separation.

- package.json - Changed the npm test command to use a test runner named
  `test.js` which starts mocha with some configuration options set. Also
  added other packages to be used with testing, including:
  * lodash
  * factory-girl
  * factory-girl-sequelize
  * faker

- test.js - Test runner starting Mocha with standard options.

- specs/index-spec.js - Old supertest based test that no longer applies.

- specs/models/AccountSpec.js - Unit test that checks the functionality
  of the Accont model.

- models/Account.js - Changed the jshint to use 4 spaces.
  • Loading branch information
msnyon committed Jan 30, 2016
1 parent 4f90ef2 commit 123032c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 35 deletions.
2 changes: 1 addition & 1 deletion models/Account.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* jshint indent: 2 */
/* jshint indent: 4 */

module.exports = function(sequelize, DataTypes) {
return sequelize.define('Account', {
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"start": "grunt",
"test": "NODE_ENV=test mocha specs"
"test": "NODE_ENV=test node test.js"
},
"dependencies": {
"async": "^0.9.x",
Expand All @@ -20,6 +20,7 @@
"express-session": "^1.11.3",
"helmet": "^0.7.x",
"jade": "^1.x.x",
"lodash": "^4.1.0",
"method-override": "^2.x.x",
"morgan": "^1.x.x",
"passport": "^0.2.x",
Expand All @@ -40,6 +41,9 @@
"bootstrap": "^3.x.x",
"chai": "^3.2.0",
"chai-as-promised": "^5.1.0",
"factory-girl": "^2.2.2",
"factory-girl-sequelize": "^1.0.0",
"faker": "^3.0.1",
"font-awesome": "^4.1.0",
"grunt": "^0.4.x",
"grunt-cli": "^0.1.13",
Expand Down
33 changes: 0 additions & 33 deletions specs/index-spec.js

This file was deleted.

26 changes: 26 additions & 0 deletions specs/models/AccountSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var chai = require('chai');
var expect = chai.expect;
var _ = require('lodash');
var sinon = require('sinon');
var faker = require('faker');
var factory = require('factory-girl');
var models = require(process.cwd() + '/models/index');


describe('Models/Account', function () {
beforeEach(function (done) {
AccountModel = models.Account;
done();
});

afterEach(function (done) {
AccountModel = models.Account;
done();
});

describe('account', function () {
it('should be true', function () {
expect(models.Account).to.be.an('object');
});
});
});
38 changes: 38 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var _ = require('lodash');
var Mocha = require('mocha');
var fs = require('fs');
var path = require('path');

var testConfig = {
NODE_ENV: 'test'
};

_.each(testConfig, function(value, key){
process.env[key] = value;
});

var mocha = new Mocha({
timeout: 60000,
reporter: "spec"
});

["specs/models"].forEach(function(pathName){
// Here is an example:
fs.readdirSync(pathName).filter(function(file){
// Only keep the .js files
return file.substr(-3) === '.js';

}).forEach(function(file){
mocha.addFile(
path.join(pathName, file)
);
});
});

mocha.run(function(failures){
process.on('exit', function () {
process.exit(failures);
});

process.exit(0);
});

0 comments on commit 123032c

Please sign in to comment.