11cb0ef41Sopenharmony_ciimport { spawnPromisified } from '../common/index.mjs';
21cb0ef41Sopenharmony_ciimport assert from 'node:assert';
31cb0ef41Sopenharmony_ciimport { execPath } from 'node:process';
41cb0ef41Sopenharmony_ciimport { describe, it } from 'node:test';
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_cidescribe('--trace-uncaught', () => {
81cb0ef41Sopenharmony_ci  it('prints a trace on process exit for uncaught errors', async () => {
91cb0ef41Sopenharmony_ci    const { code, signal, stderr } = await spawnPromisified(execPath, [
101cb0ef41Sopenharmony_ci      '--trace-uncaught',
111cb0ef41Sopenharmony_ci      '--eval',
121cb0ef41Sopenharmony_ci      `throw {
131cb0ef41Sopenharmony_ci        get stack() {
141cb0ef41Sopenharmony_ci          throw new Error('weird throw but ok');
151cb0ef41Sopenharmony_ci        },
161cb0ef41Sopenharmony_ci        get name() {
171cb0ef41Sopenharmony_ci          throw new Error('weird throw but ok');
181cb0ef41Sopenharmony_ci        },
191cb0ef41Sopenharmony_ci      };`,
201cb0ef41Sopenharmony_ci    ]);
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci    assert.match(stderr, /^Thrown at:$/m);
231cb0ef41Sopenharmony_ci    assert.match(stderr, /^ {4}at \[eval\]:1:1$/m);
241cb0ef41Sopenharmony_ci    assert.strictEqual(code, 1);
251cb0ef41Sopenharmony_ci    assert.strictEqual(signal, null);
261cb0ef41Sopenharmony_ci  });
271cb0ef41Sopenharmony_ci});
28