@@ -19,31 +19,52 @@ var promise = require('../').promise;
19
19
var remote = require ( '../remote' ) ;
20
20
21
21
describe ( 'DriverService' , function ( ) {
22
+ describe ( 'start()' , function ( ) {
23
+ var service ;
22
24
23
- describe ( 'start() fails if child-process dies' , function ( ) {
24
- var service = new remote . DriverService ( process . execPath , {
25
- port : 1234 ,
26
- args : [ '-e' , 'process.exit(1)' ]
27
- } )
25
+ beforeEach ( function ( ) {
26
+ service = new remote . DriverService ( process . execPath , {
27
+ port : 1234 ,
28
+ args : [ '-e' , 'process.exit(1)' ]
29
+ } ) ;
30
+ } ) ;
28
31
29
- after ( function ( done ) {
32
+ afterEach ( function ( done ) {
30
33
service . kill ( ) . thenFinally ( function ( ) {
31
34
done ( ) ;
32
35
} ) ;
33
36
} ) ;
34
37
35
- it ( '' , function ( done ) {
38
+ it ( 'fails if child-process dies ' , function ( done ) {
36
39
this . timeout ( 1000 ) ;
37
- service . start ( 500 ) . then ( function ( ) {
38
- done ( Error ( 'expected to fail' ) ) ;
39
- } , function ( e ) {
40
- try {
41
- assert . equal ( 'Server terminated early with status 1' , e . message ) ;
42
- done ( ) ;
43
- } catch ( e ) {
44
- done ( e ) ;
45
- }
46
- } ) ;
40
+ service . start ( 500 )
41
+ . then ( expectFailure . bind ( null , done ) , verifyFailure . bind ( null , done ) ) ;
47
42
} ) ;
43
+
44
+ it ( 'failures propagate through control flow if child-process dies' ,
45
+ function ( done ) {
46
+ this . timeout ( 1000 ) ;
47
+
48
+ promise . controlFlow ( ) . execute ( function ( ) {
49
+ promise . controlFlow ( ) . execute ( function ( ) {
50
+ return service . start ( 500 ) ;
51
+ } ) ;
52
+ } )
53
+ . then ( expectFailure . bind ( null , done ) , verifyFailure . bind ( null , done ) ) ;
54
+ } ) ;
55
+
56
+ function verifyFailure ( done , e ) {
57
+ try {
58
+ assert . ok ( ! ( e instanceof promise . CancellationError ) ) ;
59
+ assert . equal ( 'Server terminated early with status 1' , e . message ) ;
60
+ done ( ) ;
61
+ } catch ( ex ) {
62
+ done ( ex ) ;
63
+ }
64
+ }
65
+
66
+ function expectFailure ( done ) {
67
+ done ( Error ( 'expected to fail' ) ) ;
68
+ }
48
69
} ) ;
49
70
} ) ;
0 commit comments