|
| 1 | +import '../common/index.mjs'; |
| 2 | +import assert from 'assert'; |
| 3 | +import child_process from 'child_process'; |
| 4 | +import fixtures from '../common/fixtures.js'; |
| 5 | + |
| 6 | +{ |
| 7 | + // Unresolved TLA promise, --eval |
| 8 | + const { status, stdout, stderr } = child_process.spawnSync( |
| 9 | + process.execPath, |
| 10 | + ['--input-type=module', '--eval', 'await new Promise(() => {})'], |
| 11 | + { encoding: 'utf8' }); |
| 12 | + assert.deepStrictEqual([status, stdout, stderr], [13, '', '']); |
| 13 | +} |
| 14 | + |
| 15 | +{ |
| 16 | + // Rejected TLA promise, --eval |
| 17 | + const { status, stdout, stderr } = child_process.spawnSync( |
| 18 | + process.execPath, |
| 19 | + ['--input-type=module', '-e', 'await Promise.reject(new Error("Xyz"))'], |
| 20 | + { encoding: 'utf8' }); |
| 21 | + assert.deepStrictEqual([status, stdout], [1, '']); |
| 22 | + assert.match(stderr, /Error: Xyz/); |
| 23 | +} |
| 24 | + |
| 25 | +{ |
| 26 | + // Unresolved TLA promise with explicit exit code, --eval |
| 27 | + const { status, stdout, stderr } = child_process.spawnSync( |
| 28 | + process.execPath, |
| 29 | + ['--input-type=module', '--eval', |
| 30 | + 'process.exitCode = 42;await new Promise(() => {})'], |
| 31 | + { encoding: 'utf8' }); |
| 32 | + assert.deepStrictEqual([status, stdout, stderr], [42, '', '']); |
| 33 | +} |
| 34 | + |
| 35 | +{ |
| 36 | + // Rejected TLA promise with explicit exit code, --eval |
| 37 | + const { status, stdout, stderr } = child_process.spawnSync( |
| 38 | + process.execPath, |
| 39 | + ['--input-type=module', '-e', |
| 40 | + 'process.exitCode = 42;await Promise.reject(new Error("Xyz"))'], |
| 41 | + { encoding: 'utf8' }); |
| 42 | + assert.deepStrictEqual([status, stdout], [1, '']); |
| 43 | + assert.match(stderr, /Error: Xyz/); |
| 44 | +} |
| 45 | + |
| 46 | +{ |
| 47 | + // Unresolved TLA promise, module file |
| 48 | + const { status, stdout, stderr } = child_process.spawnSync( |
| 49 | + process.execPath, |
| 50 | + [fixtures.path('es-modules/tla/unresolved.mjs')], |
| 51 | + { encoding: 'utf8' }); |
| 52 | + assert.deepStrictEqual([status, stdout, stderr], [13, '', '']); |
| 53 | +} |
| 54 | + |
| 55 | +{ |
| 56 | + // Rejected TLA promise, module file |
| 57 | + const { status, stdout, stderr } = child_process.spawnSync( |
| 58 | + process.execPath, |
| 59 | + [fixtures.path('es-modules/tla/rejected.mjs')], |
| 60 | + { encoding: 'utf8' }); |
| 61 | + assert.deepStrictEqual([status, stdout], [1, '']); |
| 62 | + assert.match(stderr, /Error: Xyz/); |
| 63 | +} |
| 64 | + |
| 65 | +{ |
| 66 | + // Unresolved TLA promise, module file |
| 67 | + const { status, stdout, stderr } = child_process.spawnSync( |
| 68 | + process.execPath, |
| 69 | + [fixtures.path('es-modules/tla/unresolved-withexitcode.mjs')], |
| 70 | + { encoding: 'utf8' }); |
| 71 | + assert.deepStrictEqual([status, stdout, stderr], [42, '', '']); |
| 72 | +} |
| 73 | + |
| 74 | +{ |
| 75 | + // Rejected TLA promise, module file |
| 76 | + const { status, stdout, stderr } = child_process.spawnSync( |
| 77 | + process.execPath, |
| 78 | + [fixtures.path('es-modules/tla/rejected-withexitcode.mjs')], |
| 79 | + { encoding: 'utf8' }); |
| 80 | + assert.deepStrictEqual([status, stdout], [1, '']); |
| 81 | + assert.match(stderr, /Error: Xyz/); |
| 82 | +} |
0 commit comments