forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-exception.js
More file actions
44 lines (40 loc) · 1.48 KB
/
test-exception.js
File metadata and controls
44 lines (40 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
// Testcase to produce report on uncaught exception
const common = require('../common');
common.skipIfReportDisabled();
if (process.argv[2] === 'child') {
function myException(request, response) {
const m = '*** test-exception.js: throwing uncaught Error';
throw new Error(m);
}
myException();
} else {
const helper = require('../common/report.js');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const spawn = require('child_process').spawn;
const assert = require('assert');
const child = spawn(process.execPath,
['--experimental-report',
'--diagnostic-report-uncaught-exception',
__filename, 'child'],
{ cwd: tmpdir.path });
// Capture stderr output from the child process
let stderr = '';
child.stderr.on('data', (chunk) => {
stderr += chunk;
});
child.on('exit', common.mustCall((code) => {
const report_msg = 'No reports found';
const process_msg = 'Process exited unexpectedly';
assert.strictEqual(code, 1, process_msg + ':' + code);
assert.ok(new RegExp('myException').test(stderr),
'Check for expected stack trace frame in stderr');
const reports = helper.findReports(child.pid, tmpdir.path);
assert.strictEqual(reports.length, 1, report_msg);
const report = reports[0];
helper.validate(report, { pid: child.pid,
commandline: child.spawnargs.join(' ')
});
}));
}