1import '../common/index.mjs'; 2import assert from 'assert'; 3import child_process from 'child_process'; 4import 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} 83 84{ 85 // Calling process.exit() in .mjs should return status 0 86 const { status, stdout, stderr } = child_process.spawnSync( 87 process.execPath, 88 [fixtures.path('es-modules/tla/process-exit.mjs')], 89 { encoding: 'utf8' }); 90 assert.deepStrictEqual([status, stdout, stderr], [0, '', '']); 91} 92 93{ 94 // Calling process.exit() in worker thread shouldn't influence main thread 95 const { status, stdout, stderr } = child_process.spawnSync( 96 process.execPath, 97 [fixtures.path('es-modules/tla/unresolved-with-worker-process-exit.mjs')], 98 { encoding: 'utf8' }); 99 assert.deepStrictEqual([status, stdout, stderr], [13, '', '']); 100} 101