Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a382b52

Browse filesBrowse 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
Copy full SHA for a382b52

File tree

Expand file treeCollapse file tree

4 files changed

+54
-93
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+54
-93
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/node-report/test-api-nohooks.js
+54-4Lines changed: 54 additions & 4 deletions
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+
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/node-report/test-api-pass-error.js
-30Lines changed: 0 additions & 30 deletions
This file was deleted.
Collapse file

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

Copy file name to clipboardExpand all lines: test/node-report/test-api-trigger-with-filename.js
-29Lines changed: 0 additions & 29 deletions
This file was deleted.
Collapse file

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

Copy file name to clipboardExpand all lines: test/node-report/test-api-trigger-with-options.js
-30Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.