test: increase coverage of node_report_module.cc
PR-URL: https://github.com/nodejs/node/pull/26116 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
This commit is contained in:
parent
fd0a861cdb
commit
146868c75e
29
test/node-report/test-api-trigger-with-filename.js
Normal file
29
test/node-report/test-api-trigger-with-filename.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Tests when a report is triggered with a given filename.
|
||||||
|
const common = require('../common');
|
||||||
|
common.skipIfReportDisabled();
|
||||||
|
const filename = 'myreport.json';
|
||||||
|
if (process.argv[2] === 'child') {
|
||||||
|
process.report.triggerReport(filename);
|
||||||
|
} else {
|
||||||
|
const helper = require('../common/report.js');
|
||||||
|
const spawn = require('child_process').spawn;
|
||||||
|
const assert = require('assert');
|
||||||
|
const { join } = require('path');
|
||||||
|
const tmpdir = require('../common/tmpdir');
|
||||||
|
tmpdir.refresh();
|
||||||
|
|
||||||
|
const child = spawn(process.execPath,
|
||||||
|
['--experimental-report', __filename, 'child'],
|
||||||
|
{ cwd: tmpdir.path });
|
||||||
|
child.on('exit', common.mustCall((code) => {
|
||||||
|
const process_msg = 'Process exited unexpectedly';
|
||||||
|
assert.strictEqual(code, 0, process_msg + ':' + code);
|
||||||
|
const reports = helper.findReports(child.pid, tmpdir.path);
|
||||||
|
assert.strictEqual(reports.length, 0,
|
||||||
|
`Found unexpected report ${reports[0]}`);
|
||||||
|
const report = join(tmpdir.path, filename);
|
||||||
|
helper.validate(report);
|
||||||
|
}));
|
||||||
|
}
|
30
test/node-report/test-api-trigger-with-options.js
Normal file
30
test/node-report/test-api-trigger-with-options.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Tests when a report is triggered with options set.
|
||||||
|
const common = require('../common');
|
||||||
|
common.skipIfReportDisabled();
|
||||||
|
const filename = 'myreport.json';
|
||||||
|
if (process.argv[2] === 'child') {
|
||||||
|
process.report.setOptions({ filename: filename });
|
||||||
|
process.report.triggerReport();
|
||||||
|
} else {
|
||||||
|
const helper = require('../common/report.js');
|
||||||
|
const spawn = require('child_process').spawn;
|
||||||
|
const assert = require('assert');
|
||||||
|
const { join } = require('path');
|
||||||
|
const tmpdir = require('../common/tmpdir');
|
||||||
|
tmpdir.refresh();
|
||||||
|
|
||||||
|
const child = spawn(process.execPath,
|
||||||
|
['--experimental-report', __filename, 'child'],
|
||||||
|
{ cwd: tmpdir.path });
|
||||||
|
child.on('exit', common.mustCall((code) => {
|
||||||
|
const process_msg = 'Process exited unexpectedly';
|
||||||
|
assert.strictEqual(code, 0, process_msg + ':' + code);
|
||||||
|
const reports = helper.findReports(child.pid, tmpdir.path);
|
||||||
|
assert.strictEqual(reports.length, 0,
|
||||||
|
`Found unexpected report ${reports[0]}`);
|
||||||
|
const report = join(tmpdir.path, filename);
|
||||||
|
helper.validate(report);
|
||||||
|
}));
|
||||||
|
}
|
43
test/node-report/test-diagnostic-report-verbose.js
Normal file
43
test/node-report/test-diagnostic-report-verbose.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Tests --diagnostic-report-verbose option.
|
||||||
|
const common = require('../common');
|
||||||
|
common.skipIfReportDisabled();
|
||||||
|
if (process.argv[2] === 'child') {
|
||||||
|
// no-op
|
||||||
|
} else {
|
||||||
|
const helper = require('../common/report.js');
|
||||||
|
const spawn = require('child_process').spawn;
|
||||||
|
const assert = require('assert');
|
||||||
|
const tmpdir = require('../common/tmpdir');
|
||||||
|
tmpdir.refresh();
|
||||||
|
|
||||||
|
const expected = [ 'report: initialization complete, event flags:',
|
||||||
|
'report_uncaught_exception: 0',
|
||||||
|
'report_on_signal: 0',
|
||||||
|
'report_on_fatalerror: 0',
|
||||||
|
'report_signal:',
|
||||||
|
'report_filename:',
|
||||||
|
'report_directory:',
|
||||||
|
'report_verbose: 1' ];
|
||||||
|
|
||||||
|
const child = spawn(process.execPath,
|
||||||
|
['--experimental-report',
|
||||||
|
'--diagnostic-report-verbose',
|
||||||
|
__filename,
|
||||||
|
'child',
|
||||||
|
],
|
||||||
|
{ cwd: tmpdir.path });
|
||||||
|
let stderr;
|
||||||
|
child.stderr.on('data', (data) => stderr += data);
|
||||||
|
child.on('exit', common.mustCall((code) => {
|
||||||
|
const process_msg = 'Process exited unexpectedly';
|
||||||
|
assert.strictEqual(code, 0, process_msg + ':' + code);
|
||||||
|
const reports = helper.findReports(child.pid, tmpdir.path);
|
||||||
|
assert.strictEqual(reports.length, 0,
|
||||||
|
`Found unexpected report ${reports[0]}`);
|
||||||
|
for (const line of expected) {
|
||||||
|
assert.ok(stderr.includes(line), `'${line}' not found in '${stderr}'`);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user