Skip to content

Commit 38a87d5

Browse files
richardlaurvagg
authored andcommitted
test: increase coverage of node_report_module.cc
PR-URL: #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>
1 parent 82df851 commit 38a87d5

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
// Tests when a report is triggered with a given filename.
4+
const common = require('../common');
5+
common.skipIfReportDisabled();
6+
const filename = 'myreport.json';
7+
if (process.argv[2] === 'child') {
8+
process.report.triggerReport(filename);
9+
} else {
10+
const helper = require('../common/report.js');
11+
const spawn = require('child_process').spawn;
12+
const assert = require('assert');
13+
const { join } = require('path');
14+
const tmpdir = require('../common/tmpdir');
15+
tmpdir.refresh();
16+
17+
const child = spawn(process.execPath,
18+
['--experimental-report', __filename, 'child'],
19+
{ cwd: tmpdir.path });
20+
child.on('exit', common.mustCall((code) => {
21+
const process_msg = 'Process exited unexpectedly';
22+
assert.strictEqual(code, 0, process_msg + ':' + code);
23+
const reports = helper.findReports(child.pid, tmpdir.path);
24+
assert.strictEqual(reports.length, 0,
25+
`Found unexpected report ${reports[0]}`);
26+
const report = join(tmpdir.path, filename);
27+
helper.validate(report);
28+
}));
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
// Tests when a report is triggered with options set.
4+
const common = require('../common');
5+
common.skipIfReportDisabled();
6+
const filename = 'myreport.json';
7+
if (process.argv[2] === 'child') {
8+
process.report.setOptions({ filename: filename });
9+
process.report.triggerReport();
10+
} else {
11+
const helper = require('../common/report.js');
12+
const spawn = require('child_process').spawn;
13+
const assert = require('assert');
14+
const { join } = require('path');
15+
const tmpdir = require('../common/tmpdir');
16+
tmpdir.refresh();
17+
18+
const child = spawn(process.execPath,
19+
['--experimental-report', __filename, 'child'],
20+
{ cwd: tmpdir.path });
21+
child.on('exit', common.mustCall((code) => {
22+
const process_msg = 'Process exited unexpectedly';
23+
assert.strictEqual(code, 0, process_msg + ':' + code);
24+
const reports = helper.findReports(child.pid, tmpdir.path);
25+
assert.strictEqual(reports.length, 0,
26+
`Found unexpected report ${reports[0]}`);
27+
const report = join(tmpdir.path, filename);
28+
helper.validate(report);
29+
}));
30+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
// Tests --diagnostic-report-verbose option.
4+
const common = require('../common');
5+
common.skipIfReportDisabled();
6+
if (process.argv[2] === 'child') {
7+
// no-op
8+
} else {
9+
const helper = require('../common/report.js');
10+
const spawn = require('child_process').spawn;
11+
const assert = require('assert');
12+
const tmpdir = require('../common/tmpdir');
13+
tmpdir.refresh();
14+
15+
const expected = [ 'report: initialization complete, event flags:',
16+
'report_uncaught_exception: 0',
17+
'report_on_signal: 0',
18+
'report_on_fatalerror: 0',
19+
'report_signal:',
20+
'report_filename:',
21+
'report_directory:',
22+
'report_verbose: 1' ];
23+
24+
const child = spawn(process.execPath,
25+
['--experimental-report',
26+
'--diagnostic-report-verbose',
27+
__filename,
28+
'child',
29+
],
30+
{ cwd: tmpdir.path });
31+
let stderr;
32+
child.stderr.on('data', (data) => stderr += data);
33+
child.on('exit', common.mustCall((code) => {
34+
const process_msg = 'Process exited unexpectedly';
35+
assert.strictEqual(code, 0, process_msg + ':' + code);
36+
const reports = helper.findReports(child.pid, tmpdir.path);
37+
assert.strictEqual(reports.length, 0,
38+
`Found unexpected report ${reports[0]}`);
39+
for (const line of expected) {
40+
assert.ok(stderr.includes(line), `'${line}' not found in '${stderr}'`);
41+
}
42+
}));
43+
}

0 commit comments

Comments
 (0)