2
2
3
3
var assert = require ( 'assert' ) ;
4
4
var run = require ( './helpers' ) . runMochaJSON ;
5
+ var fork = require ( 'child_process' ) . fork ;
6
+ var path = require ( 'path' ) ;
5
7
var args = [ ] ;
6
8
7
9
describe ( 'this.timeout()' , function ( ) {
@@ -18,4 +20,56 @@ describe('this.timeout()', function () {
18
20
done ( ) ;
19
21
} ) ;
20
22
} ) ;
23
+
24
+ describe ( '0 (no timeout)' , function ( ) {
25
+ this . timeout ( 10 * 1000 ) ;
26
+
27
+ it ( 'does not spuriously end async tests that miss calling `done`' , function ( done ) {
28
+ var child = fork ( path . join ( __dirname , '..' , '..' , 'bin' , '_mocha' ) , [ path . join ( __dirname , 'fixtures' , 'timeout-0-done.fixture.js' ) ] , { silent : true } ) ;
29
+ child . on ( 'error' , function ( error ) {
30
+ if ( timeout ) { clearTimeout ( timeout ) ; }
31
+ if ( done ) { done ( error ) ; }
32
+ done = null ;
33
+ } ) ;
34
+ var timeout ;
35
+ child . on ( 'message' , function ( ) {
36
+ timeout = setTimeout ( function ( ) {
37
+ child . kill ( 'SIGINT' ) ;
38
+ if ( done ) { done ( ) ; }
39
+ done = null ;
40
+ } , 5000 ) ;
41
+ } ) ;
42
+ child . on ( 'exit' , fail ) ;
43
+ child . on ( 'close' , fail ) ;
44
+ function fail ( ) {
45
+ clearTimeout ( timeout ) ;
46
+ if ( done ) { done ( new Error ( 'Test ended despite disabled timeout!' ) ) ; }
47
+ done = null ;
48
+ }
49
+ } ) ;
50
+
51
+ it ( 'does not spuriously end promise tests that never resolve' , function ( done ) {
52
+ var child = fork ( path . join ( __dirname , '..' , '..' , 'bin' , '_mocha' ) , [ path . join ( __dirname , 'fixtures' , 'timeout-0-promise.fixture.js' ) ] , { silent : true } ) ;
53
+ child . on ( 'error' , function ( error ) {
54
+ if ( timeout ) { clearTimeout ( timeout ) ; }
55
+ if ( done ) { done ( error ) ; }
56
+ done = null ;
57
+ } ) ;
58
+ var timeout ;
59
+ child . on ( 'message' , function ( ) {
60
+ timeout = setTimeout ( function ( ) {
61
+ child . kill ( 'SIGINT' ) ;
62
+ if ( done ) { done ( ) ; }
63
+ done = null ;
64
+ } , 5000 ) ;
65
+ } ) ;
66
+ child . on ( 'exit' , fail ) ;
67
+ child . on ( 'close' , fail ) ;
68
+ function fail ( ) {
69
+ clearTimeout ( timeout ) ;
70
+ if ( done ) { done ( new Error ( 'Test ended despite disabled timeout!' ) ) ; }
71
+ done = null ;
72
+ }
73
+ } ) ;
74
+ } ) ;
21
75
} ) ;
0 commit comments