|
1 |
| -// Flags: --report-uncaught-exception |
2 | 1 | 'use strict';
|
3 | 2 | // Test producing a report on uncaught exception.
|
4 | 3 | const common = require('../common');
|
5 | 4 | const assert = require('assert');
|
| 5 | +const childProcess = require('child_process'); |
6 | 6 | const helper = require('../common/report');
|
7 | 7 | const tmpdir = require('../common/tmpdir');
|
8 |
| -const error = new Error('test error'); |
9 | 8 |
|
10 |
| -tmpdir.refresh(); |
11 |
| -process.report.directory = tmpdir.path; |
| 9 | +if (process.argv[2] === 'child') { |
| 10 | + throw new Error('test error'); |
| 11 | +} |
12 | 12 |
|
13 |
| -process.on('uncaughtException', common.mustCall((err) => { |
14 |
| - assert.strictEqual(err, error); |
15 |
| - const reports = helper.findReports(process.pid, tmpdir.path); |
| 13 | +tmpdir.refresh(); |
| 14 | +const child = childProcess.spawn(process.execPath, [ |
| 15 | + '--report-uncaught-exception', |
| 16 | + __filename, |
| 17 | + 'child', |
| 18 | +], { |
| 19 | + cwd: tmpdir.path, |
| 20 | +}); |
| 21 | +child.on('exit', common.mustCall((code) => { |
| 22 | + assert.strictEqual(code, 1); |
| 23 | + const reports = helper.findReports(child.pid, tmpdir.path); |
16 | 24 | assert.strictEqual(reports.length, 1);
|
17 |
| - helper.validate(reports[0]); |
18 |
| -})); |
19 | 25 |
|
20 |
| -throw error; |
| 26 | + helper.validate(reports[0], [ |
| 27 | + ['header.event', 'Exception'], |
| 28 | + ['header.trigger', 'Exception'], |
| 29 | + ['javascriptStack.message', 'Error: test error'], |
| 30 | + ]); |
| 31 | +})); |
0 commit comments