55// setup, the process _does not_ abort. 
66
77const  common  =  require ( '../common' ) ; 
8+ 
89const  assert  =  require ( 'assert' ) ; 
910const  domain  =  require ( 'domain' ) ; 
1011const  child_process  =  require ( 'child_process' ) ; 
1112
12- let  errorHandlerCalled  =  false ; 
13- 
1413const  tests  =  [ 
1514  function  nextTick ( )  { 
1615    const  d  =  domain . create ( ) ; 
1716
18-     d . once ( 'error' ,  function ( err )  { 
19-       errorHandlerCalled  =  true ; 
20-     } ) ; 
17+     d . once ( 'error' ,  common . mustCall ( ) ) ; 
2118
2219    d . run ( function ( )  { 
2320      process . nextTick ( function ( )  { 
@@ -29,9 +26,7 @@ const tests = [
2926  function  timer ( )  { 
3027    const  d  =  domain . create ( ) ; 
3128
32-     d . on ( 'error' ,  function ( err )  { 
33-       errorHandlerCalled  =  true ; 
34-     } ) ; 
29+     d . on ( 'error' ,  common . mustCall ( ) ) ; 
3530
3631    d . run ( function ( )  { 
3732      setTimeout ( function ( )  { 
@@ -43,9 +38,7 @@ const tests = [
4338  function  immediate ( )  { 
4439    const  d  =  domain . create ( ) ; 
4540
46-     d . on ( 'error' ,  function  errorHandler ( )  { 
47-       errorHandlerCalled  =  true ; 
48-     } ) ; 
41+     d . on ( 'error' ,  common . mustCall ( ) ) ; 
4942
5043    d . run ( function ( )  { 
5144      setImmediate ( function ( )  { 
@@ -57,9 +50,7 @@ const tests = [
5750  function  timerPlusNextTick ( )  { 
5851    const  d  =  domain . create ( ) ; 
5952
60-     d . on ( 'error' ,  function ( err )  { 
61-       errorHandlerCalled  =  true ; 
62-     } ) ; 
53+     d . on ( 'error' ,  common . mustCall ( ) ) ; 
6354
6455    d . run ( function ( )  { 
6556      setTimeout ( function ( )  { 
@@ -73,9 +64,7 @@ const tests = [
7364  function  firstRun ( )  { 
7465    const  d  =  domain . create ( ) ; 
7566
76-     d . on ( 'error' ,  function ( err )  { 
77-       errorHandlerCalled  =  true ; 
78-     } ) ; 
67+     d . on ( 'error' ,  common . mustCall ( ) ) ; 
7968
8069    d . run ( function ( )  { 
8170      throw  new  Error ( 'exceptional!' ) ; 
@@ -85,9 +74,7 @@ const tests = [
8574  function  fsAsync ( )  { 
8675    const  d  =  domain . create ( ) ; 
8776
88-     d . on ( 'error' ,  function  errorHandler ( )  { 
89-       errorHandlerCalled  =  true ; 
90-     } ) ; 
77+     d . on ( 'error' ,  common . mustCall ( ) ) ; 
9178
9279    d . run ( function ( )  { 
9380      const  fs  =  require ( 'fs' ) ; 
@@ -101,9 +88,7 @@ const tests = [
10188    const  net  =  require ( 'net' ) ; 
10289    const  d  =  domain . create ( ) ; 
10390
104-     d . on ( 'error' ,  function ( err )  { 
105-       errorHandlerCalled  =  true ; 
106-     } ) ; 
91+     d . on ( 'error' ,  common . mustCall ( ) ) ; 
10792
10893    d . run ( function ( )  { 
10994      const  server  =  net . createServer ( function ( conn )  { 
@@ -124,9 +109,7 @@ const tests = [
124109    const  d  =  domain . create ( ) ; 
125110    const  d2  =  domain . create ( ) ; 
126111
127-     d . on ( 'error' ,  function  errorHandler ( )  { 
128-       errorHandlerCalled  =  true ; 
129-     } ) ; 
112+     d . on ( 'error' ,  common . mustCall ( ) ) ; 
130113
131114    d . run ( function ( )  { 
132115      d2 . run ( function ( )  { 
@@ -139,9 +122,7 @@ const tests = [
139122    const  d  =  domain . create ( ) ; 
140123    const  d2  =  domain . create ( ) ; 
141124
142-     d2 . on ( 'error' ,  function  errorHandler ( )  { 
143-       errorHandlerCalled  =  true ; 
144-     } ) ; 
125+     d2 . on ( 'error' ,  common . mustCall ( ) ) ; 
145126
146127    d . run ( function ( )  { 
147128      d2 . run ( function ( )  { 
@@ -154,9 +135,7 @@ const tests = [
154135    const  d  =  domain . create ( ) ; 
155136    const  d2  =  domain . create ( ) ; 
156137
157-     d2 . on ( 'error' ,  function  errorHandler ( )  { 
158-       errorHandlerCalled  =  true ; 
159-     } ) ; 
138+     d2 . on ( 'error' ,  common . mustCall ( ) ) ; 
160139
161140    d . run ( function ( )  { 
162141      d2 . run ( function ( )  { 
@@ -172,9 +151,7 @@ const tests = [
172151    const  d  =  domain . create ( ) ; 
173152    const  d2  =  domain . create ( ) ; 
174153
175-     d2 . on ( 'error' ,  function  errorHandler ( )  { 
176-       errorHandlerCalled  =  true ; 
177-     } ) ; 
154+     d2 . on ( 'error' ,  common . mustCall ( ) ) ; 
178155
179156    d . run ( function ( )  { 
180157      d2 . run ( function ( )  { 
@@ -189,9 +166,7 @@ const tests = [
189166    const  d  =  domain . create ( ) ; 
190167    const  d2  =  domain . create ( ) ; 
191168
192-     d2 . on ( 'error' ,  function  errorHandler ( )  { 
193-       errorHandlerCalled  =  true ; 
194-     } ) ; 
169+     d2 . on ( 'error' ,  common . mustCall ( ) ) ; 
195170
196171    d . run ( function ( )  { 
197172      d2 . run ( function ( )  { 
@@ -206,9 +181,7 @@ const tests = [
206181    const  d  =  domain . create ( ) ; 
207182    const  d2  =  domain . create ( ) ; 
208183
209-     d2 . on ( 'error' ,  function  errorHandler ( )  { 
210-       errorHandlerCalled  =  true ; 
211-     } ) ; 
184+     d2 . on ( 'error' ,  common . mustCall ( ) ) ; 
212185
213186    d . run ( function ( )  { 
214187      d2 . run ( function ( )  { 
@@ -226,9 +199,6 @@ if (process.argv[2] === 'child') {
226199
227200  tests [ testIndex ] ( ) ; 
228201
229-   process . on ( 'exit' ,  function  onExit ( )  { 
230-     assert . strictEqual ( errorHandlerCalled ,  true ) ; 
231-   } ) ; 
232202}  else  { 
233203
234204  tests . forEach ( function ( test ,  testIndex )  { 
@@ -242,13 +212,10 @@ if (process.argv[2] === 'child') {
242212    testCmd  +=  `"${ process . argv [ 0 ] }   + 
243213               `"${ process . argv [ 1 ] } ${ testIndex }  ; 
244214
245-     const  child  =  child_process . exec ( testCmd ) ; 
246- 
247-     child . on ( 'exit' ,  function  onExit ( code ,  signal )  { 
248-       assert . strictEqual ( 
249-         code ,  0 ,  `Test at index ${ testIndex  
250-         }   should have exited with exit code 0 but instead exited with code ${ 
251-           code }   and signal ${ signal } ) ; 
252-     } ) ; 
215+     try  { 
216+       child_process . execSync ( testCmd ) ; 
217+     }  catch  ( e )  { 
218+       assert . fail ( undefined ,  undefined ,  `Test index ${ testIndex } ${ e }  ) ; 
219+     } 
253220  } ) ; 
254221} 
0 commit comments