| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,8 @@ | |||
| 5 | 5 | const common = require('../common'); | |
| 6 | 6 | common.skipIfReportDisabled(); | |
| 7 | 7 | const assert = require('assert'); | |
| 8 | + const fs = require('fs'); | ||
| 9 | + const path = require('path'); | ||
| 8 | 10 | const helper = require('../common/report'); | |
| 9 | 11 | const tmpdir = require('../common/tmpdir'); | |
| 10 | 12 | ||
@@ -13,7 +15,55 @@ common.expectWarning('ExperimentalWarning', | |||
| 13 | 15 | 'change at any time'); | |
| 14 | 16 | tmpdir.refresh(); | |
| 15 | 17 | 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments