File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,9 @@ exports.get = () => {
16
16
try {
17
17
customConfig = JSON . parse ( fs . readFileSync ( CUSTOM ) ) ;
18
18
} catch ( ex ) {
19
- /*eslint-disable */
20
- /*eslint-enable */
19
+ if ( ex instanceof SyntaxError ) {
20
+ throw new Error ( 'The content of .tldrrc is not a valid JSON object:\n' + ex ) ;
21
+ }
21
22
}
22
23
23
24
let merged = defaults ( customConfig , defaultConfig ) ;
Original file line number Diff line number Diff line change @@ -18,7 +18,11 @@ describe('Config', () => {
18
18
"repository": "http://myrepo/assets/tldr.zip"
19
19
}` ;
20
20
21
- const CUSTOM_INVALID =
21
+ const CUSTOM_INVALID_JSON =
22
+ `# comments are not allowed in json
23
+ {}` ;
24
+
25
+ const CUSTOM_INVALID_SCHEMA =
22
26
`
23
27
{
24
28
"themes": {
@@ -53,9 +57,15 @@ describe('Config', () => {
53
57
config . get ( ) . repository . should . eql ( 'http://myrepo/assets/tldr.zip' ) ;
54
58
} ) ;
55
59
56
- it ( 'should validate the custom config format' , ( ) => {
60
+ it ( 'should validate the custom config JSON' , ( ) => {
61
+ fs . readFileSync . onCall ( 0 ) . returns ( DEFAULT ) ;
62
+ fs . readFileSync . onCall ( 1 ) . returns ( CUSTOM_INVALID_JSON ) ;
63
+ config . get . should . throw ( / n o t a v a l i d J S O N o b j e c t / ) ;
64
+ } ) ;
65
+
66
+ it ( 'should validate the custom config schema' , ( ) => {
57
67
fs . readFileSync . onCall ( 0 ) . returns ( DEFAULT ) ;
58
- fs . readFileSync . onCall ( 1 ) . returns ( CUSTOM_INVALID ) ;
68
+ fs . readFileSync . onCall ( 1 ) . returns ( CUSTOM_INVALID_SCHEMA ) ;
59
69
config . get . should . throw ( / I n v a l i d t h e m e v a l u e / ) ;
60
70
} ) ;
61
71
You can’t perform that action at this time.
0 commit comments