UNPKG

1.71 kBJavaScriptView Raw
1
2/**
3 * Tests for Sync function
4 */
5
6var Sync = require('..'),
7 assert = require('assert');
8
9var runTest = module.exports = function(callback)
10{
11 var e;
12
13 try {
14
15 // Test returning value
16 Sync(function(){
17 return 'some value';
18 }, function(err, value){
19 assert.equal(value, 'some value');
20 })
21
22 // Test throws an exception
23 Sync(function(){
24 throw 'something went wrong';
25 }, function(err){
26 assert.equal(err, 'something went wrong');
27 })
28
29 // Test throws exception without callback
30 assert.throws(function(){
31 Sync(function(){
32 throw 'something went wrong';
33 })
34 }, 'something went wrong');
35
36 // Test callback throws exception
37 assert.throws(function(){
38 Sync(function(){
39
40 }, function(){
41 throw 'something went wrong';
42 })
43 }, 'something went wrong');
44
45 // Test fiber passing
46 Sync(function(fiber){
47 assert.ok(fiber instanceof Fiber);
48 })
49
50 // Test without callback
51 assert.doesNotThrow(function(){
52 Sync(function(){
53 return 'test';
54 })
55 })
56
57 // Test backwards capability
58 Sync.Fiber(function(){
59 return 'some value';
60 }, function(err, value){
61 assert.equal(value, 'some value');
62 })
63 }
64 catch (e) {
65 console.error(e.stack);
66 }
67
68 if (callback) {
69 callback(e);
70 }
71}
72
73if (!module.parent) {
74 runTest(function(){
75 console.log('%s done', __filename);
76 });
77}