Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 88256d7

Browse filesBrowse files
cjihrigaddaleax
authored andcommitted
test: simplify node-report/test-exception.js
PR-URL: #26277 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent e8995d1 commit 88256d7
Copy full SHA for 88256d7

File tree

Expand file treeCollapse file tree

1 file changed

+18
-36
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-36
lines changed
Open diff view settings
Collapse file

‎test/node-report/test-exception.js‎

Copy file name to clipboard
+18-36Lines changed: 18 additions & 36 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.