@@ -76,9 +76,9 @@ describe('ESM: unsettled and rejected promises', { concurrency: !process.env.TES
76
76
fixtures . path ( 'es-modules/tla/unresolved.mjs' ) ,
77
77
] ) ;
78
78
79
- assert . match ( stderr , / W a r n i n g : D e t e c t e d u n s e t t l e d t o p - l e v e l a w a i t a t .+ u n r e s o l v e d \. m j s : 1 / ) ;
79
+ assert . match ( stderr , / W a r n i n g : D e t e c t e d u n s e t t l e d t o p - l e v e l a w a i t a t .+ u n r e s o l v e d \. m j s : 5 \b / ) ;
80
80
assert . match ( stderr , / a w a i t n e w P r o m i s e / ) ;
81
- assert . strictEqual ( stdout , '' ) ;
81
+ assert . strictEqual ( stdout , 'the exit listener received code: 13\n ' ) ;
82
82
assert . strictEqual ( code , 13 ) ;
83
83
} ) ;
84
84
@@ -88,9 +88,11 @@ describe('ESM: unsettled and rejected promises', { concurrency: !process.env.TES
88
88
fixtures . path ( 'es-modules/tla/unresolved.mjs' ) ,
89
89
] ) ;
90
90
91
- assert . strictEqual ( stderr , '' ) ;
92
- assert . strictEqual ( stdout , '' ) ;
93
- assert . strictEqual ( code , 13 ) ;
91
+ assert . deepStrictEqual ( { code, stdout, stderr } , {
92
+ code : 13 ,
93
+ stdout : 'the exit listener received code: 13\n' ,
94
+ stderr : '' ,
95
+ } ) ;
94
96
} ) ;
95
97
96
98
it ( 'should throw for a rejected TLA promise via stdin' , async ( ) => {
@@ -104,15 +106,17 @@ describe('ESM: unsettled and rejected promises', { concurrency: !process.env.TES
104
106
assert . strictEqual ( code , 1 ) ;
105
107
} ) ;
106
108
107
- it ( 'should exit for an unsettled TLA promise and respect explicit exit code via stdin ' , async ( ) => {
109
+ it ( 'should exit for an unsettled TLA promise and respect explicit exit code' , async ( ) => {
108
110
const { code, stderr, stdout } = await spawnPromisified ( execPath , [
109
111
'--no-warnings' ,
110
112
fixtures . path ( 'es-modules/tla/unresolved-withexitcode.mjs' ) ,
111
113
] ) ;
112
114
113
- assert . strictEqual ( stderr , '' ) ;
114
- assert . strictEqual ( stdout , '' ) ;
115
- assert . strictEqual ( code , 42 ) ;
115
+ assert . deepStrictEqual ( { code, stdout, stderr } , {
116
+ code : 42 ,
117
+ stdout : 'the exit listener received code: 42\n' ,
118
+ stderr : '' ,
119
+ } ) ;
116
120
} ) ;
117
121
118
122
it ( 'should throw for a rejected TLA promise and ignore explicit exit code via stdin' , async ( ) => {
@@ -158,4 +162,33 @@ describe('ESM: unsettled and rejected promises', { concurrency: !process.env.TES
158
162
assert . strictEqual ( stdout , '' ) ;
159
163
assert . strictEqual ( code , 13 ) ;
160
164
} ) ;
165
+
166
+ describe ( 'with exit listener' , ( ) => {
167
+ it ( 'the process exit event should provide the correct code' , async ( ) => {
168
+ const { code, stderr, stdout } = await spawnPromisified ( execPath , [
169
+ fixtures . path ( 'es-modules/tla/unresolved-with-listener.mjs' ) ,
170
+ ] ) ;
171
+
172
+ assert . match ( stderr , / W a r n i n g : D e t e c t e d u n s e t t l e d t o p - l e v e l a w a i t a t / ) ;
173
+ assert . strictEqual ( stdout ,
174
+ 'the exit listener received code: 13\n' +
175
+ 'process.exitCode inside the exist listener: 13\n'
176
+ ) ;
177
+ assert . strictEqual ( code , 13 ) ;
178
+ } ) ;
179
+
180
+ it ( 'should exit for an unsettled TLA promise and respect explicit exit code in process exit event' , async ( ) => {
181
+ const { code, stderr, stdout } = await spawnPromisified ( execPath , [
182
+ '--no-warnings' ,
183
+ fixtures . path ( 'es-modules/tla/unresolved-withexitcode-and-listener.mjs' ) ,
184
+ ] ) ;
185
+
186
+ assert . deepStrictEqual ( { code, stdout, stderr } , {
187
+ code : 42 ,
188
+ stdout : 'the exit listener received code: 42\n' +
189
+ 'process.exitCode inside the exist listener: 42\n' ,
190
+ stderr : '' ,
191
+ } ) ;
192
+ } ) ;
193
+ } ) ;
161
194
} ) ;
0 commit comments