diff --git a/packages/cli/src/commands/__tests__/serve.test.js b/packages/cli/src/commands/__tests__/serve.test.js index ed54c6fd02a1..54a40651701d 100644 --- a/packages/cli/src/commands/__tests__/serve.test.js +++ b/packages/cli/src/commands/__tests__/serve.test.js @@ -40,7 +40,11 @@ jest.mock('@redwoodjs/api-server', () => { import yargs from 'yargs' -import { bothServerHandler } from '@redwoodjs/api-server' +import { + apiServerHandler, + bothServerHandler, + webServerHandler, +} from '@redwoodjs/api-server' import { builder } from '../serve' @@ -49,6 +53,48 @@ describe('yarn rw serve', () => { jest.clearAllMocks() }) + it('Should proxy serve api with params to api-server handler', async () => { + const parser = yargs.command('serve [side]', false, builder) + + parser.parse('serve api --port 5555 --apiRootPath funkyFunctions') + + expect(apiServerHandler).toHaveBeenCalledWith( + expect.objectContaining({ + port: 5555, + apiRootPath: expect.stringMatching(/^\/?funkyFunctions\/?$/), + }) + ) + }) + + it('Should proxy serve api with params to api-server handler (alias and slashes in path)', async () => { + const parser = yargs.command('serve [side]', false, builder) + + parser.parse('serve api --port 5555 --rootPath funkyFunctions/nested/') + + expect(apiServerHandler).toHaveBeenCalledWith( + expect.objectContaining({ + port: 5555, + rootPath: expect.stringMatching(/^\/?funkyFunctions\/nested\/$/), + }) + ) + }) + + it('Should proxy serve web with params to web server handler', async () => { + const parser = yargs.command('serve [side]', false, builder) + + parser.parse( + 'serve web --port 9898 --socket abc --apiHost https://myapi.redwood/api' + ) + + expect(webServerHandler).toHaveBeenCalledWith( + expect.objectContaining({ + port: 9898, + socket: 'abc', + apiHost: 'https://myapi.redwood/api', + }) + ) + }) + it('Should proxy rw serve with params to appropriate handler', async () => { const parser = yargs.command('serve [side]', false, builder)