5
5
// setup, the process _does not_ abort.
6
6
7
7
const common = require ( '../common' ) ;
8
+
8
9
const assert = require ( 'assert' ) ;
9
10
const domain = require ( 'domain' ) ;
10
11
const child_process = require ( 'child_process' ) ;
11
12
12
- let errorHandlerCalled = false ;
13
-
14
13
const tests = [
15
14
function nextTick ( ) {
16
15
const d = domain . create ( ) ;
17
16
18
- d . once ( 'error' , function ( err ) {
19
- errorHandlerCalled = true ;
20
- } ) ;
17
+ d . once ( 'error' , common . mustCall ( ) ) ;
21
18
22
19
d . run ( function ( ) {
23
20
process . nextTick ( function ( ) {
@@ -29,9 +26,7 @@ const tests = [
29
26
function timer ( ) {
30
27
const d = domain . create ( ) ;
31
28
32
- d . on ( 'error' , function ( err ) {
33
- errorHandlerCalled = true ;
34
- } ) ;
29
+ d . on ( 'error' , common . mustCall ( ) ) ;
35
30
36
31
d . run ( function ( ) {
37
32
setTimeout ( function ( ) {
@@ -43,9 +38,7 @@ const tests = [
43
38
function immediate ( ) {
44
39
const d = domain . create ( ) ;
45
40
46
- d . on ( 'error' , function errorHandler ( ) {
47
- errorHandlerCalled = true ;
48
- } ) ;
41
+ d . on ( 'error' , common . mustCall ( ) ) ;
49
42
50
43
d . run ( function ( ) {
51
44
setImmediate ( function ( ) {
@@ -57,9 +50,7 @@ const tests = [
57
50
function timerPlusNextTick ( ) {
58
51
const d = domain . create ( ) ;
59
52
60
- d . on ( 'error' , function ( err ) {
61
- errorHandlerCalled = true ;
62
- } ) ;
53
+ d . on ( 'error' , common . mustCall ( ) ) ;
63
54
64
55
d . run ( function ( ) {
65
56
setTimeout ( function ( ) {
@@ -73,9 +64,7 @@ const tests = [
73
64
function firstRun ( ) {
74
65
const d = domain . create ( ) ;
75
66
76
- d . on ( 'error' , function ( err ) {
77
- errorHandlerCalled = true ;
78
- } ) ;
67
+ d . on ( 'error' , common . mustCall ( ) ) ;
79
68
80
69
d . run ( function ( ) {
81
70
throw new Error ( 'exceptional!' ) ;
@@ -85,9 +74,7 @@ const tests = [
85
74
function fsAsync ( ) {
86
75
const d = domain . create ( ) ;
87
76
88
- d . on ( 'error' , function errorHandler ( ) {
89
- errorHandlerCalled = true ;
90
- } ) ;
77
+ d . on ( 'error' , common . mustCall ( ) ) ;
91
78
92
79
d . run ( function ( ) {
93
80
const fs = require ( 'fs' ) ;
@@ -101,9 +88,7 @@ const tests = [
101
88
const net = require ( 'net' ) ;
102
89
const d = domain . create ( ) ;
103
90
104
- d . on ( 'error' , function ( err ) {
105
- errorHandlerCalled = true ;
106
- } ) ;
91
+ d . on ( 'error' , common . mustCall ( ) ) ;
107
92
108
93
d . run ( function ( ) {
109
94
const server = net . createServer ( function ( conn ) {
@@ -124,9 +109,7 @@ const tests = [
124
109
const d = domain . create ( ) ;
125
110
const d2 = domain . create ( ) ;
126
111
127
- d . on ( 'error' , function errorHandler ( ) {
128
- errorHandlerCalled = true ;
129
- } ) ;
112
+ d . on ( 'error' , common . mustCall ( ) ) ;
130
113
131
114
d . run ( function ( ) {
132
115
d2 . run ( function ( ) {
@@ -139,9 +122,7 @@ const tests = [
139
122
const d = domain . create ( ) ;
140
123
const d2 = domain . create ( ) ;
141
124
142
- d2 . on ( 'error' , function errorHandler ( ) {
143
- errorHandlerCalled = true ;
144
- } ) ;
125
+ d2 . on ( 'error' , common . mustCall ( ) ) ;
145
126
146
127
d . run ( function ( ) {
147
128
d2 . run ( function ( ) {
@@ -154,9 +135,7 @@ const tests = [
154
135
const d = domain . create ( ) ;
155
136
const d2 = domain . create ( ) ;
156
137
157
- d2 . on ( 'error' , function errorHandler ( ) {
158
- errorHandlerCalled = true ;
159
- } ) ;
138
+ d2 . on ( 'error' , common . mustCall ( ) ) ;
160
139
161
140
d . run ( function ( ) {
162
141
d2 . run ( function ( ) {
@@ -172,9 +151,7 @@ const tests = [
172
151
const d = domain . create ( ) ;
173
152
const d2 = domain . create ( ) ;
174
153
175
- d2 . on ( 'error' , function errorHandler ( ) {
176
- errorHandlerCalled = true ;
177
- } ) ;
154
+ d2 . on ( 'error' , common . mustCall ( ) ) ;
178
155
179
156
d . run ( function ( ) {
180
157
d2 . run ( function ( ) {
@@ -189,9 +166,7 @@ const tests = [
189
166
const d = domain . create ( ) ;
190
167
const d2 = domain . create ( ) ;
191
168
192
- d2 . on ( 'error' , function errorHandler ( ) {
193
- errorHandlerCalled = true ;
194
- } ) ;
169
+ d2 . on ( 'error' , common . mustCall ( ) ) ;
195
170
196
171
d . run ( function ( ) {
197
172
d2 . run ( function ( ) {
@@ -206,9 +181,7 @@ const tests = [
206
181
const d = domain . create ( ) ;
207
182
const d2 = domain . create ( ) ;
208
183
209
- d2 . on ( 'error' , function errorHandler ( ) {
210
- errorHandlerCalled = true ;
211
- } ) ;
184
+ d2 . on ( 'error' , common . mustCall ( ) ) ;
212
185
213
186
d . run ( function ( ) {
214
187
d2 . run ( function ( ) {
@@ -226,9 +199,6 @@ if (process.argv[2] === 'child') {
226
199
227
200
tests [ testIndex ] ( ) ;
228
201
229
- process . on ( 'exit' , function onExit ( ) {
230
- assert . strictEqual ( errorHandlerCalled , true ) ;
231
- } ) ;
232
202
} else {
233
203
234
204
tests . forEach ( function ( test , testIndex ) {
@@ -242,13 +212,10 @@ if (process.argv[2] === 'child') {
242
212
testCmd += `"${ process . argv [ 0 ] } " --abort-on-uncaught-exception ` +
243
213
`"${ process . argv [ 1 ] } " child ${ testIndex } ` ;
244
214
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
+ }
253
220
} ) ;
254
221
}
0 commit comments