diff --git a/src/commands/launch/functions.test.ts b/src/commands/launch/functions.test.ts index 9d27cff..846c348 100755 --- a/src/commands/launch/functions.test.ts +++ b/src/commands/launch/functions.test.ts @@ -40,6 +40,21 @@ describe('Functions Command', () => { }); }); + it('should fall back to process.cwd() when data-dir flag is not provided', async () => { + Functions.prototype['parse'] = jest + .fn() + .mockResolvedValueOnce({ flags: { 'data-dir': undefined, port: '3000' } }); + const functionsCommand = new Functions([], {} as any); + + await functionsCommand.init(); + + expect(Functions.prototype['parse']).toHaveBeenCalledWith(Functions); + expect(functionsCommand['sharedConfig']).toEqual({ + projectBasePath: process.cwd(), + port: 3000, + }); + }); + it.each([{ portFlagInput: 'invalidPortInput' }, { portFlagInput: '999999' }, { portFlagInput: '-200' }])( 'should log an error and exit if the "port" flag input is invalid -> $portFlagInput', async ({ portFlagInput }) => { diff --git a/src/commands/launch/functions.ts b/src/commands/launch/functions.ts index 6f9fbf5..1251491 100755 --- a/src/commands/launch/functions.ts +++ b/src/commands/launch/functions.ts @@ -22,7 +22,6 @@ export default class Functions extends Command { }), 'data-dir': Flags.string({ char: 'd', - default: process.cwd(), description: 'Current working directory', }), }; @@ -34,7 +33,8 @@ export default class Functions extends Command { async init(): Promise { const { flags } = await this.parse(Functions); - const projectBasePath = flags['data-dir']; + const currentWorkingDirectory = process.cwd(); + const projectBasePath = flags['data-dir'] || currentWorkingDirectory; const logger = new Logger({ projectBasePath }); this.log = logger.log.bind(logger);