Skip to content

Commit

Permalink
test: consolidate triggerReport() tests
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cjihrig authored and addaleax committed Mar 1, 2019
1 parent 8e2cc5e commit a382b52
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 93 deletions.
58 changes: 54 additions & 4 deletions test/node-report/test-api-nohooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
const common = require('../common');
common.skipIfReportDisabled();
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const helper = require('../common/report');
const tmpdir = require('../common/tmpdir');

Expand All @@ -13,7 +15,55 @@ common.expectWarning('ExperimentalWarning',
'change at any time');
tmpdir.refresh();
process.report.setOptions({ path: tmpdir.path });
process.report.triggerReport();
const reports = helper.findReports(process.pid, tmpdir.path);
assert.strictEqual(reports.length, 1);
helper.validate(reports[0]);

function validate() {
const reports = helper.findReports(process.pid, tmpdir.path);
assert.strictEqual(reports.length, 1);
helper.validate(reports[0]);
fs.unlinkSync(reports[0]);
return reports[0];
}

{
// Test with no arguments.
process.report.triggerReport();
validate();
}

{
// Test with an error argument.
process.report.triggerReport(new Error('test error'));
validate();
}

{
// Test with a file argument.
const file = process.report.triggerReport('custom-name-1.json');
const absolutePath = path.join(tmpdir.path, file);
assert.strictEqual(helper.findReports(process.pid, tmpdir.path).length, 0);
assert.strictEqual(file, 'custom-name-1.json');
helper.validate(absolutePath);
fs.unlinkSync(absolutePath);
}

{
// Test with file and error arguments.
const file = process.report.triggerReport('custom-name-2.json',
new Error('test error'));
const absolutePath = path.join(tmpdir.path, file);
assert.strictEqual(helper.findReports(process.pid, tmpdir.path).length, 0);
assert.strictEqual(file, 'custom-name-2.json');
helper.validate(absolutePath);
fs.unlinkSync(absolutePath);
}

{
// Test with a filename option.
const filename = path.join(tmpdir.path, 'custom-name-3.json');
process.report.setOptions({ filename });
const file = process.report.triggerReport();
assert.strictEqual(helper.findReports(process.pid, tmpdir.path).length, 0);
assert.strictEqual(file, filename);
helper.validate(filename);
fs.unlinkSync(filename);
}
30 changes: 0 additions & 30 deletions test/node-report/test-api-pass-error.js

This file was deleted.

29 changes: 0 additions & 29 deletions test/node-report/test-api-trigger-with-filename.js

This file was deleted.

30 changes: 0 additions & 30 deletions test/node-report/test-api-trigger-with-options.js

This file was deleted.

0 comments on commit a382b52

Please sign in to comment.