From 7f768ac7ac605a0c6ffd334dccf42487c2c86470 Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Mon, 8 Nov 2021 11:10:25 -0800 Subject: [PATCH] eevert "remove two serve tests" This reverts commit afe80d0160d38039225202f6b34e1b8f51fec294. --- .../cli/src/commands/__tests__/serve.test.js | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) 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)