@@ -2,10 +2,6 @@ var createDefaultStream = require('./lib/default_stream');
2
2
var Render = require ( './lib/render' ) ;
3
3
var Test = require ( './lib/test' ) ;
4
4
5
- exports = module . exports = createHarness ( ) ;
6
- exports . createHarness = createHarness ;
7
- exports . Test = Test ;
8
-
9
5
var canEmitExit = typeof process !== 'undefined' && process
10
6
&& typeof process . on === 'function'
11
7
;
@@ -20,6 +16,10 @@ var onexit = (function () {
20
16
return function ( cb ) { stack . push ( cb ) } ;
21
17
} ) ( ) ;
22
18
19
+ exports = module . exports = createHarness ( ) ;
20
+ exports . createHarness = createHarness ;
21
+ exports . Test = Test ;
22
+
23
23
function createHarness ( conf_ ) {
24
24
var pending = [ ] ;
25
25
var running = false ;
@@ -29,11 +29,30 @@ function createHarness (conf_) {
29
29
var only = false ;
30
30
var closed = false ;
31
31
var out = new Render ( ) ;
32
+ if ( ! conf_ ) conf_ = { } ;
33
+
34
+ var tests = [ ] ;
35
+ var exitInterval = conf_ . exitInterval !== false && canEmitExit
36
+ && typeof process . _getActiveHandles === 'function'
37
+ && setInterval ( function ( ) {
38
+ if ( process . _getActiveHandles ( ) . length === 1 ) {
39
+ tests . forEach ( function ( t ) { t . _exit ( ) } ) ;
40
+ }
41
+ } , 200 ) ;
42
+
43
+ var exitCode = 0 ;
44
+ var exit = function ( c ) { exitCode = c } ;
45
+
46
+ out . on ( 'end' , function ( ) {
47
+ clearInterval ( exitInterval ) ;
48
+ process . exit ( exitCode ) ;
49
+ } ) ;
32
50
33
51
var test = function ( name , conf , cb ) {
34
52
count ++ ;
35
53
var t = new Test ( name , conf , cb ) ;
36
- if ( ! conf || typeof conf !== 'object' ) conf = conf_ || { } ;
54
+ tests . push ( t ) ;
55
+ if ( ! conf || typeof conf !== 'object' ) conf = conf_ ;
37
56
38
57
if ( conf . exit !== false ) {
39
58
onexit ( function ( code ) {
@@ -43,7 +62,7 @@ function createHarness (conf_) {
43
62
out . close ( ) ;
44
63
}
45
64
if ( ! code && ! t . _ok && ( ! only || name === only ) ) {
46
- process . exit ( 1 ) ;
65
+ exit ( 1 ) ;
47
66
}
48
67
} ) ;
49
68
}
@@ -101,7 +120,7 @@ function createHarness (conf_) {
101
120
out . close ( ) ;
102
121
}
103
122
if ( conf . exit !== false && canExit && ! t . _ok ) {
104
- process . exit ( 1 ) ;
123
+ exit ( 1 ) ;
105
124
}
106
125
} ) ;
107
126
}
0 commit comments