Skip to content

Commit a382b52

Browse files
cjihrigaddaleax
authored andcommitted
test: consolidate triggerReport() tests
PR-URL: #26268 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 8e2cc5e commit a382b52

File tree

4 files changed

+54
-93
lines changed

4 files changed

+54
-93
lines changed

test/node-report/test-api-nohooks.js

+54-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
const common = require('../common');
66
common.skipIfReportDisabled();
77
const assert = require('assert');
8+
const fs = require('fs');
9+
const path = require('path');
810
const helper = require('../common/report');
911
const tmpdir = require('../common/tmpdir');
1012

@@ -13,7 +15,55 @@ common.expectWarning('ExperimentalWarning',
1315
'change at any time');
1416
tmpdir.refresh();
1517
process.report.setOptions({ path: tmpdir.path });
16-
process.report.triggerReport();
17-
const reports = helper.findReports(process.pid, tmpdir.path);
18-
assert.strictEqual(reports.length, 1);
19-
helper.validate(reports[0]);
18+
19+
function validate() {
20+
const reports = helper.findReports(process.pid, tmpdir.path);
21+
assert.strictEqual(reports.length, 1);
22+
helper.validate(reports[0]);
23+
fs.unlinkSync(reports[0]);
24+
return reports[0];
25+
}
26+
27+
{
28+
// Test with no arguments.
29+
process.report.triggerReport();
30+
validate();
31+
}
32+
33+
{
34+
// Test with an error argument.
35+
process.report.triggerReport(new Error('test error'));
36+
validate();
37+
}
38+
39+
{
40+
// Test with a file argument.
41+
const file = process.report.triggerReport('custom-name-1.json');
42+
const absolutePath = path.join(tmpdir.path, file);
43+
assert.strictEqual(helper.findReports(process.pid, tmpdir.path).length, 0);
44+
assert.strictEqual(file, 'custom-name-1.json');
45+
helper.validate(absolutePath);
46+
fs.unlinkSync(absolutePath);
47+
}
48+
49+
{
50+
// Test with file and error arguments.
51+
const file = process.report.triggerReport('custom-name-2.json',
52+
new Error('test error'));
53+
const absolutePath = path.join(tmpdir.path, file);
54+
assert.strictEqual(helper.findReports(process.pid, tmpdir.path).length, 0);
55+
assert.strictEqual(file, 'custom-name-2.json');
56+
helper.validate(absolutePath);
57+
fs.unlinkSync(absolutePath);
58+
}
59+
60+
{
61+
// Test with a filename option.
62+
const filename = path.join(tmpdir.path, 'custom-name-3.json');
63+
process.report.setOptions({ filename });
64+
const file = process.report.triggerReport();
65+
assert.strictEqual(helper.findReports(process.pid, tmpdir.path).length, 0);
66+
assert.strictEqual(file, filename);
67+
helper.validate(filename);
68+
fs.unlinkSync(filename);
69+
}

test/node-report/test-api-pass-error.js

-30
This file was deleted.

test/node-report/test-api-trigger-with-filename.js

-29
This file was deleted.

test/node-report/test-api-trigger-with-options.js

-30
This file was deleted.

0 commit comments

Comments
 (0)