Skip to content

Commit

Permalink
Merge pull request #849 from charlierudolph/cr-splitTests
Browse files Browse the repository at this point in the history
convert tests to mocha
  • Loading branch information
aearly committed Jul 20, 2015
2 parents 4101af3 + 7e3fcfc commit 2dae787
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 45 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Expand Up @@ -5,3 +5,9 @@ node_js:
- "iojs-v2.1.0"
sudo: false
after_success: npm run coveralls

# Needed to run Karma with Firefox on Travis
# http://karma-runner.github.io/0.13/plus/travis.html
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
12 changes: 12 additions & 0 deletions karma.conf.js
@@ -0,0 +1,12 @@
module.exports = function (config) {
config.set({
browsers: ['Firefox'],
files: ['mocha_test/*.js'],
frameworks: ['browserify', 'mocha'],
preprocessors: {
'mocha_test/*.js': ['browserify']
},
reporters: ['mocha'],
singleRun: true
});
}
44 changes: 44 additions & 0 deletions mocha_test/forever.js
@@ -0,0 +1,44 @@
var async = require('../lib/async');
var expect = require('chai').expect;
var isBrowser = require('./support/is_browser');

describe('forever', function(){
context('function is asynchronous', function(){
it('executes the function over and over until it yields an error', function(done){
var counter = 0;
addOne = function (callback) {
counter++;
if (counter === 50) {
return callback('too big!');
}
async.setImmediate(function () {
callback();
});
}
async.forever(addOne, function (err) {
expect(err).to.eql('too big!');
expect(counter).to.eql(50);
done();
});
})
});

context('function is synchronous', function(){
it('does not cause a stack overflow', function(done){
if (isBrowser()) return done(); // this will take forever in a browser
var counter = 0;
function addOne(callback) {
counter++;
if (counter === 50000) { // needs to be huge to potentially overflow stack in node
return callback('too big!');
}
callback();
}
async.forever(addOne, function (err) {
expect(err).to.eql('too big!');
expect(counter).to.eql(50000);
done();
});
});
});
});
4 changes: 4 additions & 0 deletions mocha_test/support/is_browser.js
@@ -0,0 +1,4 @@
module.exports = function() {
return (typeof process === "undefined") ||
(process + "" !== "[object process]"); // browserify
}
13 changes: 12 additions & 1 deletion package.json
Expand Up @@ -21,12 +21,19 @@
"devDependencies": {
"benchmark": "bestiejs/benchmark.js",
"bluebird": "^2.9.32",
"chai": "^3.1.0",
"coveralls": "^2.11.2",
"es6-promise": "^2.3.0",
"jscs": "^1.13.1",
"jshint": "~2.8.0",
"karma": "^0.13.2",
"karma-browserify": "^4.2.1",
"karma-firefox-launcher": "^0.1.6",
"karma-mocha": "^0.2.0",
"karma-mocha-reporter": "^1.0.2",
"lodash": "^3.9.0",
"mkdirp": "~0.5.1",
"mocha": "^2.2.5",
"native-promise-only": "^0.8.0-a",
"nodeunit": ">0.0.0",
"nyc": "^2.1.0",
Expand All @@ -47,7 +54,11 @@
]
},
"scripts": {
"test": "npm run-script lint && nodeunit test/test-async.js",
"mocha-node-test": "mocha mocha_test/",
"mocha-browser-test": "karma start",
"mocha-test": "npm run mocha-node-test && npm run mocha-browser-test",
"nodeunit-test": "nodeunit test/test-async.js",
"test": "npm run-script lint && npm run nodeunit-test && npm run mocha-test",
"lint": "jshint lib/*.js test/*.js perf/*.js && jscs lib/*.js test/*.js perf/*.js",
"coverage": "nyc npm test && nyc report",
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
Expand Down
44 changes: 0 additions & 44 deletions test/test-async.js
Expand Up @@ -85,50 +85,6 @@ function isBrowser() {
(process + "" !== "[object process]"); // browserify
}

exports['forever'] = {

'async': function (test) {
test.expect(2);
var counter = 0;
function addOne(callback) {
counter++;
if (counter === 50) {
return callback('too big!');
}
async.setImmediate(function () {
callback();
});
}
async.forever(addOne, function (err) {
test.equal(err, 'too big!');
test.equal(counter, 50);
test.done();
});
},

'sync': function (test) {
if (isBrowser()) {
// this will take forever in a browser
return test.done();
}
test.expect(2);
var counter = 0;
function addOne(callback) {
counter++;
if (counter === 50000) { // needs to be huge to potentially overflow stack in node
return callback('too big!');
}
callback();
}
async.forever(addOne, function (err) {
test.equal(err, 'too big!');
test.equal(counter, 50000);
test.done();
});
}

};

exports['applyEach'] = function (test) {
test.expect(5);
var call_order = [];
Expand Down

0 comments on commit 2dae787

Please sign in to comment.