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