summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcharlierudolph <charles.rudolph@originate.com>2015-07-17 15:47:29 -0700
committercharlierudolph <charles.rudolph@originate.com>2015-07-17 15:47:29 -0700
commita23d3a2250923b082bb4bb73167dd04c9906c07d (patch)
tree68673b2b1707c425f98fb7ef2db1c0c6caef40e4
parentbb21b4ad61dacad5393df894ea5f2add7a8937b3 (diff)
downloadasync-a23d3a2250923b082bb4bb73167dd04c9906c07d.tar.gz
mocha tests
-rw-r--r--karma.conf.js11
-rw-r--r--mocha_test/forever_test.js44
-rw-r--r--mocha_test/support.js8
-rw-r--r--package.json12
-rwxr-xr-xtest/test-async.js44
5 files changed, 74 insertions, 45 deletions
diff --git a/karma.conf.js b/karma.conf.js
new file mode 100644
index 0000000..9300887
--- /dev/null
+++ b/karma.conf.js
@@ -0,0 +1,11 @@
+module.exports = function (config) {
+ config.set({
+ browsers: ['Chrome'],
+ files: ['mocha_test/**/*_test.js'],
+ frameworks: ['browserify', 'mocha'],
+ preprocessors: {
+ 'mocha_test/**/*_test.js': ['browserify']
+ },
+ singleRun: true
+ });
+}
diff --git a/mocha_test/forever_test.js b/mocha_test/forever_test.js
new file mode 100644
index 0000000..ca9c80e
--- /dev/null
+++ b/mocha_test/forever_test.js
@@ -0,0 +1,44 @@
+var async = require('../lib/async');
+var expect = require('chai').expect;
+var isBrowser = require('./support').isBrowser;
+
+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();
+ });
+ });
+ });
+});
diff --git a/mocha_test/support.js b/mocha_test/support.js
new file mode 100644
index 0000000..f4e231b
--- /dev/null
+++ b/mocha_test/support.js
@@ -0,0 +1,8 @@
+support = {}
+
+support.isBrowser = function() {
+ return (typeof process === "undefined") ||
+ (process + "" !== "[object process]"); // browserify
+}
+
+module.exports = support
diff --git a/package.json b/package.json
index e2707b9..22c072d 100644
--- a/package.json
+++ b/package.json
@@ -21,12 +21,18 @@
"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-chrome-launcher": "^0.2.0",
+ "karma-mocha": "^0.2.0",
"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",
@@ -47,7 +53,11 @@
]
},
"scripts": {
- "test": "npm run-script lint && nodeunit test/test-async.js",
+ "mocha-node-test": "mocha mocha_test/",
+ "mocha-browser-tests": "karma start",
+ "mocha-test": "npm run mocha-node-test && npm run mocha-browser-tests",
+ "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"
diff --git a/test/test-async.js b/test/test-async.js
index fdb949b..ddfb063 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -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 = [];