55const common = require ( '../common' ) ;
66common . skipIfReportDisabled ( ) ;
77const assert = require ( 'assert' ) ;
8+ const fs = require ( 'fs' ) ;
9+ const path = require ( 'path' ) ;
810const helper = require ( '../common/report' ) ;
911const tmpdir = require ( '../common/tmpdir' ) ;
1012
@@ -13,7 +15,55 @@ common.expectWarning('ExperimentalWarning',
1315 'change at any time' ) ;
1416tmpdir . refresh ( ) ;
1517process . 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+ }
0 commit comments