| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,93 @@ | |||
| 1 | + import { spawnPromisified } from '../common/index.mjs'; | ||
| 2 | + import assert from 'node:assert'; | ||
| 3 | + import { execPath } from 'node:process'; | ||
| 4 | + import { describe, it } from 'node:test'; | ||
| 5 | + | ||
| 6 | + | ||
| 7 | + describe('--print with a promise', { concurrency: true }, () => { | ||
| 8 | + it('should handle directly-fulfilled promises', async () => { | ||
| 9 | + const result = await spawnPromisified(execPath, [ | ||
| 10 | + '--print', | ||
| 11 | + 'Promise.resolve(42)', | ||
| 12 | + ]); | ||
| 13 | + | ||
| 14 | + assert.deepStrictEqual(result, { | ||
| 15 | + code: 0, | ||
| 16 | + signal: null, | ||
| 17 | + stderr: '', | ||
| 18 | + stdout: 'Promise { 42 }\n', | ||
| 19 | + }); | ||
| 20 | + }); | ||
| 21 | + | ||
| 22 | + it('should handle promises fulfilled after one tick', async () => { | ||
| 23 | + const result = await spawnPromisified(execPath, [ | ||
| 24 | + '--print', | ||
| 25 | + 'Promise.resolve().then(()=>42)', | ||
| 26 | + ]); | ||
| 27 | + | ||
| 28 | + assert.deepStrictEqual(result, { | ||
| 29 | + code: 0, | ||
| 30 | + signal: null, | ||
| 31 | + stderr: '', | ||
| 32 | + stdout: 'Promise { <pending> }\n', | ||
| 33 | + }); | ||
| 34 | + }); | ||
| 35 | + | ||
| 36 | + it('should handle promise that never settles', async () => { | ||
| 37 | + const result = await spawnPromisified(execPath, [ | ||
| 38 | + '--print', | ||
| 39 | + 'new Promise(()=>{})', | ||
| 40 | + ]); | ||
| 41 | + | ||
| 42 | + assert.deepStrictEqual(result, { | ||
| 43 | + code: 0, | ||
| 44 | + signal: null, | ||
| 45 | + stderr: '', | ||
| 46 | + stdout: 'Promise { <pending> }\n', | ||
| 47 | + }); | ||
| 48 | + }); | ||
| 49 | + | ||
| 50 | + it('should output something if process exits before promise settles', async () => { | ||
| 51 | + const result = await spawnPromisified(execPath, [ | ||
| 52 | + '--print', | ||
| 53 | + 'setTimeout(process.exit,100, 0);timers.promises.setTimeout(200)', | ||
| 54 | + ]); | ||
| 55 | + | ||
| 56 | + assert.deepStrictEqual(result, { | ||
| 57 | + code: 0, | ||
| 58 | + signal: null, | ||
| 59 | + stderr: '', | ||
| 60 | + stdout: 'Promise { <pending> }\n', | ||
| 61 | + }); | ||
| 62 | + }); | ||
| 63 | + | ||
| 64 | + it('should handle rejected promises', async () => { | ||
| 65 | + const result = await spawnPromisified(execPath, [ | ||
| 66 | + '--unhandled-rejections=none', | ||
| 67 | + '--print', | ||
| 68 | + 'Promise.reject(1)', | ||
| 69 | + ]); | ||
| 70 | + | ||
| 71 | + assert.deepStrictEqual(result, { | ||
| 72 | + code: 0, | ||
| 73 | + signal: null, | ||
| 74 | + stderr: '', | ||
| 75 | + stdout: 'Promise { <rejected> 1 }\n', | ||
| 76 | + }); | ||
| 77 | + }); | ||
| 78 | + | ||
| 79 | + it('should handle promises that reject after one tick', async () => { | ||
| 80 | + const result = await spawnPromisified(execPath, [ | ||
| 81 | + '--unhandled-rejections=none', | ||
| 82 | + '--print', | ||
| 83 | + 'Promise.resolve().then(()=>Promise.reject(1))', | ||
| 84 | + ]); | ||
| 85 | + | ||
| 86 | + assert.deepStrictEqual(result, { | ||
| 87 | + code: 0, | ||
| 88 | + signal: null, | ||
| 89 | + stderr: '', | ||
| 90 | + stdout: 'Promise { <pending> }\n', | ||
| 91 | + }); | ||
| 92 | + }); | ||
| 93 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments