@@ -29,7 +29,7 @@ describe('--print with a promise', { concurrency: !process.env.TEST_PARALLEL },
2929 code : 0 ,
3030 signal : null ,
3131 stderr : '' ,
32- stdout : 'Promise { <pending> }\n' ,
32+ stdout : 'Promise { 42 }\n' ,
3333 } ) ;
3434 } ) ;
3535
@@ -50,7 +50,7 @@ describe('--print with a promise', { concurrency: !process.env.TEST_PARALLEL },
5050 it ( 'should output something if process exits before promise settles' , async ( ) => {
5151 const result = await spawnPromisified ( execPath , [
5252 '--print' ,
53- 'setTimeout(process.exit,100, 0);timers.promises.setTimeout(200)' ,
53+ 'setTimeout(process.exit, 100, 0);timers.promises.setTimeout(200)' ,
5454 ] ) ;
5555
5656 assert . deepStrictEqual ( result , {
@@ -61,6 +61,20 @@ describe('--print with a promise', { concurrency: !process.env.TEST_PARALLEL },
6161 } ) ;
6262 } ) ;
6363
64+ it ( 'should respect exit code when process exits before promise settles' , async ( ) => {
65+ const result = await spawnPromisified ( execPath , [
66+ '--print' ,
67+ 'setTimeout(process.exit, 100, 42);timers.promises.setTimeout(200)' ,
68+ ] ) ;
69+
70+ assert . deepStrictEqual ( result , {
71+ code : 42 ,
72+ signal : null ,
73+ stderr : '' ,
74+ stdout : 'Promise { <pending> }\n' ,
75+ } ) ;
76+ } ) ;
77+
6478 it ( 'should handle rejected promises' , async ( ) => {
6579 const result = await spawnPromisified ( execPath , [
6680 '--unhandled-rejections=none' ,
@@ -87,7 +101,52 @@ describe('--print with a promise', { concurrency: !process.env.TEST_PARALLEL },
87101 code : 0 ,
88102 signal : null ,
89103 stderr : '' ,
90- stdout : 'Promise { <pending> }\n' ,
104+ stdout : 'Promise { <rejected> 1 }\n' ,
105+ } ) ;
106+ } ) ;
107+
108+ it ( 'should handle thenable that resolves' , async ( ) => {
109+ const result = await spawnPromisified ( execPath , [
110+ '--unhandled-rejections=none' ,
111+ '--print' ,
112+ '({ then(r) { r(42) } })' ,
113+ ] ) ;
114+
115+ assert . deepStrictEqual ( result , {
116+ code : 0 ,
117+ signal : null ,
118+ stderr : '' ,
119+ stdout : '{ then: [Function: then] }\n' ,
120+ } ) ;
121+ } ) ;
122+
123+ it ( 'should handle thenable that rejects' , async ( ) => {
124+ const result = await spawnPromisified ( execPath , [
125+ '--unhandled-rejections=none' ,
126+ '--print' ,
127+ '({ then(_, r) { r(42) } })' ,
128+ ] ) ;
129+
130+ assert . deepStrictEqual ( result , {
131+ code : 0 ,
132+ signal : null ,
133+ stderr : '' ,
134+ stdout : '{ then: [Function: then] }\n' ,
135+ } ) ;
136+ } ) ;
137+
138+ it ( 'should handle Promise.prototype' , async ( ) => {
139+ const result = await spawnPromisified ( execPath , [
140+ '--unhandled-rejections=none' ,
141+ '--print' ,
142+ 'Promise.prototype' ,
143+ ] ) ;
144+
145+ assert . deepStrictEqual ( result , {
146+ code : 0 ,
147+ signal : null ,
148+ stderr : '' ,
149+ stdout : 'Object [Promise] {}\n' ,
91150 } ) ;
92151 } ) ;
93152} ) ;
0 commit comments