Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/commands/launch/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/launch/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default class Functions extends Command {
}),
'data-dir': Flags.string({
char: 'd',
default: process.cwd(),
description: 'Current working directory',
}),
};
Expand All @@ -34,7 +33,8 @@ export default class Functions extends Command {

async init(): Promise<void> {
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);
Expand Down
Loading