From c2b180fcbbd570b98efd8f939390f15ae61f9d0c Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 23 Feb 2019 11:00:09 -0500 Subject: [PATCH] test: simplify node-report/test-exception.js PR-URL: https://github.com/nodejs/node/pull/26277 Reviewed-By: James M Snell Reviewed-By: Richard Lau --- test/node-report/test-exception.js | 54 ++++++++++-------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/test/node-report/test-exception.js b/test/node-report/test-exception.js index e2c801afb9216e..b3da7c4244ae09 100644 --- a/test/node-report/test-exception.js +++ b/test/node-report/test-exception.js @@ -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'); - const reports = helper.findReports(child.pid, tmpdir.path); - assert.strictEqual(reports.length, 1, report_msg); - const report = reports[0]; - helper.validate(report); - })); -} +throw error;