|
| 1 | +// Flags: --experimental-report --diagnostic-report-uncaught-exception |
1 | 2 | 'use strict';
|
2 |
| - |
3 |
| -// Testcase to produce report on uncaught exception |
| 3 | +// Test producing a report on uncaught exception. |
4 | 4 | const common = require('../common');
|
5 | 5 | common.skipIfReportDisabled();
|
6 |
| -if (process.argv[2] === 'child') { |
7 |
| - function myException(request, response) { |
8 |
| - const m = '*** test-exception.js: throwing uncaught Error'; |
9 |
| - throw new Error(m); |
10 |
| - } |
| 6 | +const assert = require('assert'); |
| 7 | +const helper = require('../common/report'); |
| 8 | +const tmpdir = require('../common/tmpdir'); |
| 9 | +const error = new Error('test error'); |
11 | 10 |
|
12 |
| - myException(); |
| 11 | +common.expectWarning('ExperimentalWarning', |
| 12 | + 'report is an experimental feature. This feature could ' + |
| 13 | + 'change at any time'); |
| 14 | +tmpdir.refresh(); |
| 15 | +process.report.setOptions({ path: tmpdir.path }); |
13 | 16 |
|
14 |
| -} else { |
15 |
| - const helper = require('../common/report.js'); |
16 |
| - const tmpdir = require('../common/tmpdir'); |
17 |
| - tmpdir.refresh(); |
18 |
| - const spawn = require('child_process').spawn; |
19 |
| - const assert = require('assert'); |
| 17 | +process.on('uncaughtException', common.mustCall((err) => { |
| 18 | + assert.strictEqual(err, error); |
| 19 | + const reports = helper.findReports(process.pid, tmpdir.path); |
| 20 | + assert.strictEqual(reports.length, 1); |
| 21 | + helper.validate(reports[0]); |
| 22 | +})); |
20 | 23 |
|
21 |
| - const child = spawn(process.execPath, |
22 |
| - ['--experimental-report', |
23 |
| - '--diagnostic-report-uncaught-exception', |
24 |
| - __filename, 'child'], |
25 |
| - { cwd: tmpdir.path }); |
26 |
| - // Capture stderr output from the child process |
27 |
| - let stderr = ''; |
28 |
| - child.stderr.on('data', (chunk) => { |
29 |
| - stderr += chunk; |
30 |
| - }); |
31 |
| - child.on('exit', common.mustCall((code) => { |
32 |
| - const report_msg = 'No reports found'; |
33 |
| - const process_msg = 'Process exited unexpectedly'; |
34 |
| - assert.strictEqual(code, 1, process_msg + ':' + code); |
35 |
| - assert.ok(new RegExp('myException').test(stderr), |
36 |
| - 'Check for expected stack trace frame in stderr'); |
37 |
| - const reports = helper.findReports(child.pid, tmpdir.path); |
38 |
| - assert.strictEqual(reports.length, 1, report_msg); |
39 |
| - const report = reports[0]; |
40 |
| - helper.validate(report); |
41 |
| - })); |
42 |
| -} |
| 24 | +throw error; |
0 commit comments