@@ -4,6 +4,8 @@ const _ = require('lodash');
4
4
const Config = require ( '../../../lib/config' ) ;
5
5
const defaults = require ( '../../../lib/config/defaults' ) ;
6
6
7
+ const parser = require ( '../../../lib/config/options' ) ;
8
+
7
9
describe ( 'config options' , ( ) => {
8
10
const sandbox = sinon . sandbox . create ( ) ;
9
11
@@ -108,4 +110,64 @@ describe('config options', () => {
108
110
assert . deepEqual ( config . prepareEnvironment , newFunc ) ;
109
111
} ) ;
110
112
} ) ;
113
+
114
+ describe ( 'plugins' , ( ) => {
115
+ const parse_ = ( opts ) => parser ( _ . defaults ( opts , { env : { } , argv : [ ] } ) ) ;
116
+
117
+ it ( 'should parse boolean value from environment' , ( ) => {
118
+ const result = parse_ ( {
119
+ options : { plugins : { foo : { } } } ,
120
+ env : { 'hermione_plugins_foo' : 'true' }
121
+ } ) ;
122
+
123
+ assert . strictEqual ( result . plugins . foo , true ) ;
124
+ } ) ;
125
+
126
+ it ( 'should parse object value from environment' , ( ) => {
127
+ const result = parse_ ( {
128
+ options : { plugins : { foo : { } } } ,
129
+ env : { 'hermione_plugins_foo' : '{"opt": 1}' }
130
+ } ) ;
131
+
132
+ assert . deepEqual ( result . plugins . foo , { opt : 1 } ) ;
133
+ } ) ;
134
+
135
+ it ( 'should throw error on invalid values from environment' , ( ) => {
136
+ assert . throws (
137
+ ( ) => parse_ ( {
138
+ options : { plugins : { foo : { } } } ,
139
+ env : { 'hermione_plugins_foo' : '{key: 1}' }
140
+ } ) ,
141
+ 'a value must be a primitive type'
142
+ ) ;
143
+ } ) ;
144
+
145
+ it ( 'should parse boolean value from cli' , ( ) => {
146
+ const result = parse_ ( {
147
+ options : { plugins : { foo : { } } } ,
148
+ argv : [ '--plugins-foo' , 'true' ]
149
+ } ) ;
150
+
151
+ assert . strictEqual ( result . plugins . foo , true ) ;
152
+ } ) ;
153
+
154
+ it ( 'should parse object value from cli' , ( ) => {
155
+ const result = parse_ ( {
156
+ options : { plugins : { foo : { } } } ,
157
+ argv : [ '--plugins-foo' , '{"opt": 1}' ]
158
+ } ) ;
159
+
160
+ assert . deepEqual ( result . plugins . foo , { opt : 1 } ) ;
161
+ } ) ;
162
+
163
+ it ( 'should throw error on invalid values from cli' , ( ) => {
164
+ assert . throws (
165
+ ( ) => parse_ ( {
166
+ options : { plugins : { foo : { } } } ,
167
+ argv : [ '--plugins-foo' , '{key: 1}' ]
168
+ } ) ,
169
+ 'a value must be a primitive type'
170
+ ) ;
171
+ } ) ;
172
+ } ) ;
111
173
} ) ;
0 commit comments