From 7f5cae5b53146ca25aa94951550f9965b1cbe83a Mon Sep 17 00:00:00 2001 From: Le Vivilet Date: Fri, 27 Dec 2024 11:18:34 +0100 Subject: [PATCH] feature: add port conflict test --- .../test/PreviewProcessPortConflict.test.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 packages/test-integration/test/PreviewProcessPortConflict.test.ts diff --git a/packages/test-integration/test/PreviewProcessPortConflict.test.ts b/packages/test-integration/test/PreviewProcessPortConflict.test.ts new file mode 100644 index 00000000..b73d10bf --- /dev/null +++ b/packages/test-integration/test/PreviewProcessPortConflict.test.ts @@ -0,0 +1,21 @@ +import { expect, test } from '@jest/globals' +import getPort from 'get-port' +import { createPreviewProcess } from '../src/parts/CreatePreviewProcess/CreatePreviewProcess.js' + +test('preview process - handles port already in use', async () => { + const previewProcess1 = createPreviewProcess() + const previewProcess2 = createPreviewProcess() + const id = 1 + const port = await getPort() + + await previewProcess1.invoke('WebViewServer.create', id) + await previewProcess1.invoke('WebViewServer.start', id, port) + + // TODO improve error message + await expect(previewProcess2.invoke('WebViewServer.start', id, port)).rejects.toThrow( + "Failed to start webview server: TypeError: Cannot read properties of undefined (reading 'server')", + ) + + previewProcess1[Symbol.dispose]() + previewProcess2[Symbol.dispose]() +})