@@ -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,29 @@ 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' , ( ) => {
305+ writeFiles ( path . join ( DIR , 'TestProject' ) , {
306+ 'react-native.config.ts' : USER_CONFIG_COMMAND_ARG_REQUIRED ,
307+ } ) ;
308+
309+ const { stdout} = runCLI ( path . join ( DIR , 'TestProject' ) , [
310+ 'test-command-arg-required' ,
311+ '--optional-arg' ,
312+ 'foo' ,
313+ ] ) ;
314+ expect ( stdout ) . toBe ( 'test-command-ts' ) ;
315+ } ) ;
316+
317+ test ( 'should not fail if an optional arg is missing' , ( ) => {
318+ writeFiles ( path . join ( DIR , 'TestProject' ) , {
319+ 'react-native.config.ts' : USER_CONFIG_COMMAND_ARG_REQUIRED ,
320+ } ) ;
321+
322+ const { stdout} = runCLI ( path . join ( DIR , 'TestProject' ) , [
323+ 'test-command-arg-required' ,
324+ '--required-arg' ,
325+ 'bar' ,
326+ ] ) ;
327+ expect ( stdout ) . toBe ( 'ok' ) ;
328+ } ) ;
0 commit comments