Permalink
Browse files

Improvement/move to mocha (#551)

* Adds unit testing using Mocha and TestDouble for both Wallaby and CI

* Migrates first test from Jasmine+Jest to Mocha+TestDouble

* Adds missing dependency

* Moves new ddp tests into mocha
  • Loading branch information...
samhatoum committed Jan 6, 2017
1 parent fade6eb commit d0a7e3a3b1ab07e4eba2355fd0596368a96e8048
Showing with 126 additions and 54 deletions.
  1. +2 −0 .npmrc
  2. +12 −0 mocha-setup.js
  3. +4 −0 mocha.opts
  4. +16 −2 package.json
  5. +1 −52 src/__tests__/chimp-spec.js
  6. +75 −0 src/lib/chimp-spec.js
  7. +16 −0 wallaby-mocha.js
View
2 .npmrc
@@ -0,0 +1,2 @@
# Remove that annoying npm crap at the end of test runs
loglevel=silent
View
@@ -0,0 +1,12 @@
(function () {
const chai = require('chai');
chai.should();
global.expect = chai.expect;
global.assert = chai.assert;
const td = require('testdouble');
const quibble = require('quibble');
global.td = td;
td.reset();
quibble.ignoreCallsFromThisFile(require.main.filename);
})();
View
@@ -0,0 +1,4 @@
--require mocha-setup
--compilers js:babel-core/register
--reporter spec
--ui bdd
View
@@ -33,7 +33,8 @@
"lint": "eslint ./src",
"lintfix": "eslint ./src --fix",
"start": "node ./scripts/run.js",
"testonly": "npm run-script prepublish && node ./scripts/run-tests.js",
"testonly": "npm run testunit && npm run prepublish && node ./scripts/run-tests.js",
"testunit": "mocha --opts ./mocha.opts `node -e \"console.log(require('./package.json').mocha.tests.join(' '))\"`",
"test": "npm run lint && npm run testonly",
"publish-patch": "npm version patch; npm publish; git push; git push --tags",
"publish-minor": "npm version minor; npm publish; git push; git push --tags",
@@ -43,6 +44,17 @@
"bin": {
"chimp": "./bin/chimp.js"
},
"mocha": {
"files": [
"src/**/*.js",
"!src/__mocks__/**/*",
"!src/__tests__/**/*",
"!src/**/*-spec.js"
],
"tests": [
"src/lib/**/*-spec.js"
]
},
"jest": {
"testRunner": "<rootDir>/node_modules/jest-cli/src/testRunners/jasmine/jasmine2.js",
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
@@ -108,7 +120,9 @@
"git-release-notes": "0.0.2",
"jest-cli": "Sanjo/jest#7c71094",
"npm-watch": "^0.1.6",
"shelljs": "^0.7.5"
"quibble": "^0.4.0",
"shelljs": "^0.7.5",
"testdouble": "^1.10.1"
},
"bundledDependencies": [
"cucumber"
@@ -9,58 +9,7 @@ describe('Chimp', function () {
var Chimp = require('../lib/chimp');
describe('constructor', function () {
it('creates the processes array', function () {
expect(new Chimp().processes).toEqual(jasmine.any(Array));
});
it('created an options object if non are passed', function () {
var chimp = new Chimp();
expect(chimp.options).toBeDefined();
});
it('stores the options object', function () {
var myOptions = {};
var chimp = new Chimp(myOptions);
expect(chimp.options).toBe(myOptions);
});
it('puts all the options on the environment hash prefixed with [chimp.]', function () {
var myOptions = {
a: 1,
b: 'aString'
};
var chimp = new Chimp(myOptions);
expect(process.env['chimp.a']).toBe(myOptions.a.toString());
expect(process.env['chimp.b']).toBe(myOptions.b);
});
it('puts single ddp option on the environment hash as [chimp.ddp0] if only one provided', function () {
var myOptions = {
ddp: 'http://host:port'
};
var chimp = new Chimp(myOptions);
expect(process.env['chimp.ddp0']).toBe(myOptions.ddp.toString());
expect(process.env['chimp.ddp1']).toBeUndefined();
});
it('puts multiple ddp options on the environment hash as [chimp.ddpX] if multiple provided', function () {
var myOptions = {
ddp: ['http://host:port1', 'http://host:port2']
};
var chimp = new Chimp(myOptions);
expect(process.env['chimp.ddp0']).toBe(myOptions.ddp[0].toString());
expect(process.env['chimp.ddp1']).toBe(myOptions.ddp[1].toString());
});
// moved to src/lib/chimp-specs.js
});
describe('bin path', function () {
View
@@ -0,0 +1,75 @@
const Chimp = require('./chimp');
describe('Chimp', function () {
before(function () {
const emptyFn = function () {
};
td.replace('async', {});
td.replace('path', {resolve: emptyFn, join: emptyFn});
td.replace('chokidar', {});
td.replace('underscore', {});
td.replace('./log', {});
td.replace('freeport', {});
td.replace('xolvio-ddp', {});
td.replace('hapi', {});
td.replace('./ddp-watcher', {});
td.replace('colors', {});
td.replace('./boolean-helper', {});
td.replace('./mocha/mocha.js', {});
td.replace('./jasmine/jasmine.js', {});
td.replace('./cucumberjs/cucumber.js', {});
td.replace('./phantom.js', {});
td.replace('./chromedriver.js', {});
td.replace('./consoler.js', {});
td.replace('./selenium.js', {});
td.replace('./simian-reporter.js', {});
});
describe('constructor', function () {
beforeEach(function () {
this.chimp = new Chimp();
});
it('should create a new instance', function () {
expect(this.chimp).not.to.equal(null);
});
it('should initialize a processes array', function () {
expect(this.chimp.processes).to.be.instanceof(Array);
});
it('should initialize an options object if no options are provided', function () {
expect(this.chimp.options).to.be.instanceOf(Object);
});
it('should store the options object if provided', function () {
const myOptions = {};
const chimp = new Chimp(myOptions);
expect(chimp.options).to.equal(myOptions);
});
it('should store all the provided options on the environment hash prefixed with [chimp.]', function () {
const myOptions = {a: 1, b: 'aString'};
const chimp = new Chimp(myOptions);
expect(process.env['chimp.a']).to.equal(myOptions.a.toString());
expect(process.env['chimp.b']).to.equal(myOptions.b);
});
it('puts single ddp option on the environment hash as [chimp.ddp0] if only one provided', function () {
const myOptions = {
ddp: 'http://host:port'
};
const chimp = new Chimp(myOptions);
expect(process.env['chimp.ddp0']).to.equal(myOptions.ddp.toString());
expect(process.env['chimp.ddp1']).to.be.undefined;
});
it('puts multiple ddp options on the environment hash as [chimp.ddpX] if multiple provided', function () {
const myOptions = {
ddp: ['http://host:port1', 'http://host:port2']
};
const chimp = new Chimp(myOptions);
expect(process.env['chimp.ddp0']).to.equal(myOptions.ddp[0].toString());
expect(process.env['chimp.ddp1']).to.equal(myOptions.ddp[1].toString());
});
});
});
View
@@ -0,0 +1,16 @@
module.exports = (wallaby) => {
const path = require('path');
const packageJson = require(`${wallaby.localProjectDir}/package.json`);
return {
debug: false,
testFramework: 'mocha',
files: packageJson.mocha.files,
tests: packageJson.mocha.tests,
compilers: {'**/*.js': wallaby.compilers.babel()},
env: {type: 'node'},
workers: {initial: 1, regular: 1, recycle: true},
setup: () => {
require(`${wallaby.localProjectDir}/mocha-setup`);
},
}
};

0 comments on commit d0a7e3a

Please sign in to comment.