@@ -157,6 +157,31 @@ export default {
157157};
158158` ;
159159
160+ const USER_CONFIG_COMMAND_ARG_REQUIRED = `;
161+ module.exports = {
162+ commands: [
163+ {
164+ name: 'test-command-arg-required',
165+ description: 'test command',
166+ func: () => {
167+ console.log('ok');
168+ },
169+ options: [
170+ {
171+ name: '--required-arg <string>',
172+ description: 'test command arg',
173+ required: true,
174+ },
175+ {
176+ name: '--optional-arg <string>',
177+ description: 'test command arg',
178+ },
179+ ],
180+ },
181+ ],
182+ };
183+ ` ;
184+
160185test ( 'should read user config from react-native.config.js' , ( ) => {
161186 writeFiles ( path . join ( DIR , 'TestProject' ) , {
162187 'react-native.config.js' : USER_CONFIG ,
@@ -275,3 +300,27 @@ test('should read config if using import/export in react-native.config.mjs with
275300 const { stdout} = runCLI ( path . join ( DIR , 'TestProject' ) , [ 'test-command-esm' ] ) ;
276301 expect ( stdout ) . toMatch ( 'test-command-esm' ) ;
277302} ) ;
303+
304+ test ( 'should fail if a required arg is missing, pass if optional missing' , ( ) => {
305+ writeFiles ( path . join ( DIR , 'TestProject' ) , {
306+ 'react-native.config.cjs' : USER_CONFIG_COMMAND_ARG_REQUIRED ,
307+ } ) ;
308+
309+ const { stderr} = runCLI (
310+ path . join ( DIR , 'TestProject' ) ,
311+ [ 'test-command-arg-required' , '--optional-arg' , 'foo' ] ,
312+ {
313+ expectedFailure : true ,
314+ } ,
315+ ) ;
316+ expect ( stderr ) . toMatch (
317+ "required option '--required-arg <string>' not specified" ,
318+ ) ;
319+
320+ const { stdout} = runCLI ( path . join ( DIR , 'TestProject' ) , [
321+ 'test-command-arg-required' ,
322+ '--required-arg' ,
323+ 'bar' ,
324+ ] ) ;
325+ expect ( stdout ) . toMatch ( 'ok' ) ;
326+ } ) ;
0 commit comments