Skip to content

Commit 88256d7

Browse files
cjihrigaddaleax
authored andcommitted
test: simplify node-report/test-exception.js
PR-URL: #26277 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent e8995d1 commit 88256d7

File tree

1 file changed

+18
-36
lines changed

1 file changed

+18
-36
lines changed

test/node-report/test-exception.js

+18-36
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,24 @@
1+
// Flags: --experimental-report --diagnostic-report-uncaught-exception
12
'use strict';
2-
3-
// Testcase to produce report on uncaught exception
3+
// Test producing a report on uncaught exception.
44
const common = require('../common');
55
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');
1110

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 });
1316

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+
}));
2023

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

Comments
 (0)