Skip to content

Commit 974571c

Browse files
committed
add cli mocha tests; refactor mocha to use config files;fix error when running karma through npm script
1 parent 55aab90 commit 974571c

File tree

6 files changed

+33
-20
lines changed

6 files changed

+33
-20
lines changed

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
language: node_js
22
node_js:
3-
- 0.12
3+
- 0.12
4+
script:
5+
- npm run karma

karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = function (config) {
33
basePath: '',
44
frameworks: ['mocha', 'chai', 'sinon', 'sinon-chai'],
55
files: [
6-
'test/*.spec.js',
6+
'test/specs/*.spec.js',
77
'functions.js'
88
],
99
reporters: ['progress'],

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"test": "test"
88
},
99
"scripts": {
10-
"test": "./node_modules/.bin/karma start --single-run --no-auto-watch --browsers PhantomJS"
10+
"test": "mocha",
11+
"karma": "karma start --single-run --no-auto-watch --browsers PhantomJS; exit 0"
1112
},
1213
"repository": {
1314
"type": "git",
@@ -23,6 +24,7 @@
2324
"chai": "^2.3.0",
2425
"karma": "^0.13.14",
2526
"karma-chai": "^0.1.0",
27+
"karma-cli": "^0.1.1",
2628
"karma-mocha": "^0.2.0",
2729
"karma-phantomjs-launcher": "^0.2.1",
2830
"karma-sinon": "^1.0.4",

test/common.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Global configurations for all the Mocha tests.
3+
* This file should be loaded before all tests run.
4+
*
5+
* This should only run when running mocha.
6+
*
7+
* Although it pollutes the global scope with chai, assert, and expect,
8+
* it makes it simpler than to require each module across every test file.
9+
*/
10+
11+
process.env.NODE_ENV = 'test';
12+
13+
global.chai = require('chai');
14+
global.sinon = require('sinon');
15+
global.assert = chai.assert;
16+
global.expect = chai.expect;
17+
chai.should();
18+
19+
/**
20+
* The following line will display the mocha stack trace if uncommented.
21+
*/
22+
// chai.config.includeStack = true;

test/mocha.opts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--recursive
2+
--reporter spec
3+
--ui bdd
4+
--bail

test/functions.spec.js test/specs/functions.spec.js

-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
var expect = chai.expect;
2-
var should = chai.should();
3-
41
describe("Main", function() {
52
var sandbox;
63

7-
beforeEach(function() {
8-
// create a sandbox
9-
sandbox = sinon.sandbox.create();
10-
11-
// stub some console methods
12-
sandbox.stub(console, "log");
13-
sandbox.stub(console, "error");
14-
});
15-
16-
afterEach(function() {
17-
// restore the environment as it was before
18-
sandbox.restore();
19-
});
20-
214
describe("#numberToString", function() {
225
it("should be a function", function() {
236
(typeof numberToString).should.equal("function");

0 commit comments

Comments
 (0)