From 878a5f22b6bf2520631aa5d77b17f56e998a9a3d Mon Sep 17 00:00:00 2001 From: Ryan Cartwright Date: Fri, 30 Jun 2023 14:50:43 +1000 Subject: [PATCH] update tests --- src/resources/http.test.ts | 19 ++++++++++++++++--- src/resources/http.ts | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/resources/http.test.ts b/src/resources/http.test.ts index 5e73aa3a..31ec549c 100644 --- a/src/resources/http.test.ts +++ b/src/resources/http.test.ts @@ -13,6 +13,19 @@ // limitations under the License. import * as faas from '../faas/index'; import { HttpWorkerOptions, http } from '.'; + +jest.mock('portfinder', () => { + const originalModule = jest.requireActual('portfinder'); + + return { + __esmodule: true, + ...originalModule, + getPort: (callback: (err, port) => void) => { + callback('', 1234); + }, + }; +}); + jest.mock('../faas/index'); describe('HTTP Proxy', () => { @@ -36,7 +49,7 @@ describe('HTTP Proxy', () => { beforeAll(() => { try { - http(mockApp, 1234); + http(mockApp); } catch (err) { error = err; } @@ -55,7 +68,7 @@ describe('HTTP Proxy', () => { }); beforeAll(async () => { - http(mockApp, 1234, fakeCallback); + http(mockApp, fakeCallback); }); it('should create a new FaasClient', () => { @@ -81,7 +94,7 @@ describe('HTTP Proxy', () => { }); beforeAll(async () => { - http(fakeFunc, 1234, fakeCallback); + http(fakeFunc, fakeCallback); }); it('should create a new FaasClient', () => { diff --git a/src/resources/http.ts b/src/resources/http.ts index c6a9c2bd..3bd90e9c 100644 --- a/src/resources/http.ts +++ b/src/resources/http.ts @@ -69,6 +69,7 @@ export const http = ( 'Unable to find open port. Try setting the env var `NITRIC_HTTP_PROXY_PORT`' ); } + new HttpWorker(nodeApp, port, callback); });