| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8bd3cb2 commit a8b21fd
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,7 +119,10 @@ function evalScript(name, body, breakFirstLine, print, shouldLoadESM = false) { | |||
| 119 | 119 | }); | |
| 120 | 120 | if (print) { | |
| 121 | 121 | const { log } = require('internal/console/global'); | |
| 122 | - log(result); | ||
| 122 | + | ||
| 123 | + process.on('exit', () => { | ||
| 124 | + log(result); | ||
| 125 | + }); | ||
| 123 | 126 | } | |
| 124 | 127 | ||
| 125 | 128 | if (origModule !== undefined) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,7 @@ describe('--print with a promise', { concurrency: !process.env.TEST_PARALLEL }, | |||
| 29 | 29 | code: 0, | |
| 30 | 30 | signal: null, | |
| 31 | 31 | stderr: '', | |
| 32 | - stdout: 'Promise { <pending> }\n', | ||
| 32 | + stdout: 'Promise { 42 }\n', | ||
| 33 | 33 | }); | |
| 34 | 34 | }); | |
| 35 | 35 | ||
@@ -50,7 +50,7 @@ describe('--print with a promise', { concurrency: !process.env.TEST_PARALLEL }, | |||
| 50 | 50 | it('should output something if process exits before promise settles', async () => { | |
| 51 | 51 | const result = await spawnPromisified(execPath, [ | |
| 52 | 52 | '--print', | |
| 53 | - 'setTimeout(process.exit,100, 0);timers.promises.setTimeout(200)', | ||
| 53 | + 'setTimeout(process.exit, 100, 0);timers.promises.setTimeout(200)', | ||
| 54 | 54 | ]); | |
| 55 | 55 | ||
| 56 | 56 | assert.deepStrictEqual(result, { | |
@@ -61,6 +61,20 @@ describe('--print with a promise', { concurrency: !process.env.TEST_PARALLEL }, | |||
| 61 | 61 | }); | |
| 62 | 62 | }); | |
| 63 | 63 | ||
| 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 | + | ||
| 64 | 78 | it('should handle rejected promises', async () => { | |
| 65 | 79 | const result = await spawnPromisified(execPath, [ | |
| 66 | 80 | '--unhandled-rejections=none', | |
@@ -87,7 +101,52 @@ describe('--print with a promise', { concurrency: !process.env.TEST_PARALLEL }, | |||
| 87 | 101 | code: 0, | |
| 88 | 102 | signal: null, | |
| 89 | 103 | 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', | ||
| 91 | 150 | }); | |
| 92 | 151 | }); | |
| 93 | 152 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments