1
1
var assert = require ( 'chai' ) . assert ;
2
2
var should = require ( 'chai' ) . should ( ) ;
3
- var EventProxy = require ( '../' ) ;
4
3
var pedding = require ( 'pedding' ) ;
5
- var fs = require ( 'fs' ) ;
4
+
5
+ try {
6
+ var EventProxy = require ( '../' ) ;
7
+ var http = require ( 'http' ) ;
8
+ var fs = require ( 'fs' ) ;
9
+ } catch ( e ) {
10
+ var EventProxy = require ( 'eventproxy' ) ;
11
+ var http = {
12
+ get : function ( options , callback ) {
13
+ setTimeout ( function ( ) {
14
+ callback ( {
15
+ statusCode : 200
16
+ } ) ;
17
+ } , 0 ) ;
18
+ }
19
+ } ;
20
+ var __filename = 'mock_file.txt' ;
21
+ var fs = {
22
+ readFile : function ( filename , encode , callback ) {
23
+ if ( typeof encode === 'function' ) {
24
+ callback = encode ;
25
+ encode = null ;
26
+ }
27
+ setTimeout ( function ( ) {
28
+ if ( filename === 'not exist file' ) {
29
+ return callback ( new Error ( 'ENOENT, open \'not exist file\'' ) ) ;
30
+ }
31
+ callback ( null , 'Foo bar baz' ) ;
32
+ } , 10 ) ;
33
+ }
34
+ } ;
35
+ }
6
36
7
37
describe ( "EventProxy" , function ( ) {
8
38
describe ( 'constructor' , function ( ) {
@@ -391,7 +421,7 @@ describe("EventProxy", function () {
391
421
done ( ) ;
392
422
} ) ;
393
423
fs . readFile ( __filename , ep . done ( 'data' ) ) ;
394
- require ( ' http' ) . get ( { host : 'cnodejs.org' } , function ( res ) {
424
+ http . get ( { host : 'cnodejs.org' } , function ( res ) {
395
425
should . exist ( res ) ;
396
426
res . statusCode . should . equal ( 200 ) ;
397
427
ep . emit ( 'cnodejs' , res ) ;
@@ -404,22 +434,22 @@ describe("EventProxy", function () {
404
434
405
435
it ( 'should success callback after all event emit' , function ( done ) {
406
436
done = pedding ( 3 , done ) ;
407
- var ep = EventProxy . create ( 'data' , 'dirs ' , 'cnodejs' , function ( data , dirs , cnodejs ) {
437
+ var ep = EventProxy . create ( 'data' , 'data2 ' , 'cnodejs' , function ( data , data2 , cnodejs ) {
408
438
should . exist ( data ) ;
409
- should . exist ( dirs ) ;
439
+ should . exist ( data2 ) ;
410
440
should . exist ( cnodejs ) ;
411
441
done ( ) ;
412
442
} , function ( err ) {
413
443
throw new Error ( 'should not call this' ) ;
414
444
} ) ;
415
445
fs . readFile ( __filename , ep . done ( 'data' ) ) ;
416
- require ( ' http' ) . get ( { host : 'cnodejs.org' } , function ( res ) {
446
+ http . get ( { host : 'cnodejs.org' } , function ( res ) {
417
447
assert . deepEqual ( res . statusCode , 200 ) ;
418
448
ep . emit ( 'cnodejs' , res ) ;
419
449
done ( ) ;
420
450
} ) ;
421
451
process . nextTick ( function ( ) {
422
- fs . readdir ( __dirname , ep . done ( 'dirs ' ) ) ;
452
+ fs . readFile ( __filename , ep . done ( 'data2 ' ) ) ;
423
453
done ( ) ;
424
454
} ) ;
425
455
} ) ;
@@ -442,7 +472,7 @@ describe("EventProxy", function () {
442
472
} ) ;
443
473
444
474
fs . readFile ( __filename , ep . done ( 'data' ) ) ;
445
- require ( ' http' ) . get ( { host : 'nodejs.org' } , function ( res ) {
475
+ http . get ( { host : 'nodejs.org' } , function ( res ) {
446
476
assert . deepEqual ( res . statusCode , 200 ) ;
447
477
ep . emit ( 'cnodejs' , res ) ;
448
478
done ( ) ;
@@ -460,7 +490,7 @@ describe("EventProxy", function () {
460
490
mockGet ( 'fooquery2' , ep . done ( 'mockGet2' ) ) ;
461
491
462
492
process . nextTick ( function ( ) {
463
- fs . readdir ( __dirname , ep . done ( 'dirs' ) ) ;
493
+ fs . readFile ( __filename , ep . done ( 'dirs' ) ) ;
464
494
done ( ) ;
465
495
} ) ;
466
496
} ) ;
0 commit comments