Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: simplify node-report/test-exception.js #26277

Merged
merged 1 commit into from
Feb 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 18 additions & 36 deletions test/node-report/test-exception.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,24 @@
// Flags: --experimental-report --diagnostic-report-uncaught-exception
'use strict';

// Testcase to produce report on uncaught exception
// Test producing a 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);
}
const assert = require('assert');
const helper = require('../common/report');
const tmpdir = require('../common/tmpdir');
const error = new Error('test error');

myException();
common.expectWarning('ExperimentalWarning',
'report is an experimental feature. This feature could ' +
'change at any time');
tmpdir.refresh();
process.report.setOptions({ path: tmpdir.path });

} else {
const helper = require('../common/report.js');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const spawn = require('child_process').spawn;
const assert = require('assert');
process.on('uncaughtException', common.mustCall((err) => {
assert.strictEqual(err, error);
const reports = helper.findReports(process.pid, tmpdir.path);
assert.strictEqual(reports.length, 1);
helper.validate(reports[0]);
}));

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');
richardlau marked this conversation as resolved.
Show resolved Hide resolved
const reports = helper.findReports(child.pid, tmpdir.path);
assert.strictEqual(reports.length, 1, report_msg);
const report = reports[0];
helper.validate(report);
}));
}
throw error;