diff options
author | ezubarev <zubarev.eugene@gmail.com> | 2016-05-06 11:54:47 +0600 |
---|---|---|
committer | ezubarev <zubarev.eugene@gmail.com> | 2016-05-06 11:54:47 +0600 |
commit | f71051575026ba91cf595594dd9b245d5c448852 (patch) | |
tree | cd33f5ec92d77fca9c51cb9fbfccb87f69813d5b | |
parent | 5dac23157a21f471993ce263ee73a517f32c8e61 (diff) | |
download | async-f71051575026ba91cf595594dd9b245d5c448852.tar.gz |
Convert timeout tests to mocha
-rw-r--r-- | mocha_test/timeout.js | 40 | ||||
-rwxr-xr-x | test/test-async.js | 73 |
2 files changed, 32 insertions, 81 deletions
diff --git a/mocha_test/timeout.js b/mocha_test/timeout.js index 7608124..c59f006 100644 --- a/mocha_test/timeout.js +++ b/mocha_test/timeout.js @@ -1,5 +1,5 @@ var async = require('../lib'); -var expect = require('chai').expect; +var assert = require('assert'); describe('timeout', function () { @@ -17,9 +17,33 @@ describe('timeout', function () { }, 50) ], function(err, results) { - expect(err.message).to.equal('Callback function "asyncFn" timed out.'); - expect(err.code).to.equal('ETIMEDOUT'); - expect(results[0]).to.equal('I didn\'t time out'); + assert(err.message === 'Callback function "asyncFn" timed out.'); + assert(err.code === 'ETIMEDOUT'); + assert(err.info === undefined); + assert(results[0] === 'I didn\'t time out'); + done(); + }); + }); + + it('timeout with series and info', function (done) { + var info = { custom: 'info about callback' }; + async.series([ + async.timeout(function asyncFn(callback) { + setTimeout(function() { + callback(null, 'I didn\'t time out'); + }, 25); + }, 50), + async.timeout(function asyncFn(callback) { + setTimeout(function() { + callback(null, 'I will time out'); + }, 75); + }, 50, info) + ], + function(err, results) { + assert(err.message === 'Callback function "asyncFn" timed out.'); + assert(err.code === 'ETIMEDOUT'); + assert(err.info === info); + assert(results[0] === 'I didn\'t time out'); done(); }); }); @@ -38,11 +62,11 @@ describe('timeout', function () { }, 50) ], function(err, results) { - expect(err.message).to.equal('Callback function "asyncFn" timed out.'); - expect(err.code).to.equal('ETIMEDOUT'); - expect(results[0]).to.equal('I didn\'t time out'); + assert(err.message === 'Callback function "asyncFn" timed out.'); + assert(err.code === 'ETIMEDOUT'); + assert(err.info === undefined); + assert(results[0] === 'I didn\'t time out'); done(); }); }); - }); diff --git a/test/test-async.js b/test/test-async.js index c7613d0..763fb31 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -1054,76 +1054,3 @@ exports['asyncify'] = { return promises; }, {}) }; - -exports['timeout'] = function (test) { - test.expect(4); - - async.series([ - async.timeout(function asyncFn(callback) { - setTimeout(function() { - callback(null, 'I didn\'t time out'); - }, 50); - }, 200), - async.timeout(function asyncFn(callback) { - setTimeout(function() { - callback(null, 'I will time out'); - }, 300); - }, 150) - ], - function(err, results) { - test.ok(err.message === 'Callback function "asyncFn" timed out.'); - test.ok(err.code === 'ETIMEDOUT'); - test.ok(err.info === undefined); - test.ok(results[0] === 'I didn\'t time out'); - test.done(); - }); -}; - -exports['timeout with info'] = function (test) { - test.expect(4); - - var info = { custom: 'info about callback' }; - async.series([ - async.timeout(function asyncFn(callback) { - setTimeout(function() { - callback(null, 'I didn\'t time out'); - }, 50); - }, 200), - async.timeout(function asyncFn(callback) { - setTimeout(function() { - callback(null, 'I will time out'); - }, 300); - }, 150, info) - ], - function(err, results) { - test.ok(err.message === 'Callback function "asyncFn" timed out.'); - test.ok(err.code === 'ETIMEDOUT'); - test.ok(err.info === info); - test.ok(results[0] === 'I didn\'t time out'); - test.done(); - }); -}; - -exports['timeout with parallel'] = function (test) { - test.expect(4); - - async.parallel([ - async.timeout(function asyncFn(callback) { - setTimeout(function() { - callback(null, 'I didn\'t time out'); - }, 50); - }, 200), - async.timeout(function asyncFn(callback) { - setTimeout(function() { - callback(null, 'I will time out'); - }, 300); - }, 150) - ], - function(err, results) { - test.ok(err.message === 'Callback function "asyncFn" timed out.'); - test.ok(err.code === 'ETIMEDOUT'); - test.ok(err.info === undefined); - test.ok(results[0] === 'I didn\'t time out'); - test.done(); - }); -}; |