File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ const msgs = {
47
47
invalid_reporter : "Unable to find '%s' reporter" ,
48
48
invalid_setup : "Invalid setup for reporter '%s' (%s)" ,
49
49
invalid_outfile : "Invalid stdout filename for reporter '%s' (%s)" ,
50
+ bad_file : "Missing or malformed options file '%s' -- %s" ,
50
51
} ;
51
52
function bombOut ( id , ...args ) {
52
53
const newArgs = [ `ERROR: ${ msgs [ id ] } ` , ...args ] ;
@@ -67,7 +68,11 @@ function convertSetup(reporters) {
67
68
Object . keys ( reporters ) . forEach ( ( reporter ) => {
68
69
if ( reporter === 'mocha-multi' ) {
69
70
debug ( 'loading reporters from file %j' , reporters [ reporter ] ) ;
70
- setup = setup . concat ( convertSetup ( JSON . parse ( fs . readFileSync ( reporters [ reporter ] ) ) ) ) ;
71
+ try {
72
+ setup = setup . concat ( convertSetup ( JSON . parse ( fs . readFileSync ( reporters [ reporter ] ) ) ) ) ;
73
+ } catch ( e ) {
74
+ bombOut ( 'bad_file' , reporters [ reporter ] , e ) ;
75
+ }
71
76
} else {
72
77
const r = reporters [ reporter ] ;
73
78
debug ( 'adding reporter %j %j' , reporter , r ) ;
Original file line number Diff line number Diff line change @@ -104,6 +104,16 @@ function compare {
104
104
fi
105
105
}
106
106
107
+ badfilecheck=" ERROR: Missing or malformed options file 'missing.json' -- Error: ENOENT: no such file or directory, open 'missing.json'"
108
+ badfile=` mocha --reporter " $mocha_multi " --reporter-options mocha-multi=missing.json --recursive test 2>&1 `
109
+ log " $badfile "
110
+ if [ " $badfile " != " $badfilecheck " ]; then
111
+ log " Wrong error message trying to load missing options file" fail
112
+ exit 1
113
+ else
114
+ log " Correct error message trying to load missing options file" pass
115
+ fi
116
+
107
117
if [ " $1 " = " " ]; then
108
118
log " No reporter chosen"
109
119
exit 1
You can’t perform that action at this time.
0 commit comments