Skip to content

Commit a9c3e67

Browse files
committed
feat: make Harness WS port configurable
1 parent 2124133 commit a9c3e67

File tree

8 files changed

+17
-6
lines changed

8 files changed

+17
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
__default__: prerelease
3+
---
4+
5+
Added `webSocketPort` option to `rn-harness.config` (default 3001). This allows configuring the Bridge Server port, enabling usage of custom ports without rebuilding the application.

packages/config/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const ConfigSchema = z
88
.min(1, 'App registry component name is required'),
99
runners: z.array(z.any()).min(1, 'At least one runner is required'),
1010
defaultRunner: z.string().optional(),
11+
webSocketPort: z.number().optional().default(3001),
1112
bridgeTimeout: z
1213
.number()
1314
.min(1000, 'Bridge timeout must be at least 1 second')

packages/jest/src/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const getHarnessInternal = async (
2424
getMetroInstance({ projectRoot, harnessConfig: config }, signal),
2525
import(platform.runner).then((module) => module.default(platform.config)),
2626
getBridgeServer({
27-
port: 3001,
27+
port: config.webSocketPort,
2828
timeout: config.bridgeTimeout,
2929
}),
3030
]);

packages/metro/src/manifest.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import fs from 'node:fs';
33
import { Config as HarnessConfig } from '@react-native-harness/config';
44

55
const getManifestContent = (harnessConfig: HarnessConfig): string => {
6-
return `global.RN_HARNESS = { appRegistryComponentName: '${harnessConfig.appRegistryComponentName}' };`;
6+
return `global.RN_HARNESS = {
7+
appRegistryComponentName: '${harnessConfig.appRegistryComponentName}',
8+
webSocketPort: ${harnessConfig.webSocketPort}
9+
};`;
710
};
811

912
export const getHarnessManifest = (harnessConfig: HarnessConfig): string => {

packages/platform-android/src/adb.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ export const isAppInstalled = async (
1818

1919
export const reversePort = async (
2020
adbId: string,
21-
port: number
21+
port: number,
22+
hostPort: number = port
2223
): Promise<void> => {
23-
await spawn('adb', ['-s', adbId, 'reverse', `tcp:${port}`, `tcp:${port}`]);
24+
await spawn('adb', ['-s', adbId, 'reverse', `tcp:${port}`, `tcp:${hostPort}`]);
2425
};
2526

2627
export const stopApp = async (

packages/platform-android/src/runner.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const getAndroidRunner = async (
3333
await Promise.all([
3434
adb.reversePort(adbId, 8081),
3535
adb.reversePort(adbId, 8080),
36-
adb.reversePort(adbId, 3001),
3736
]);
3837

3938
return {

packages/runtime/src/client/getWSServer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { WS_SERVER_PORT } from '../constants.js';
44
export const getWSServer = (): string => {
55
const devServerUrl = getDevServerUrl();
66
const hostname = devServerUrl.split('://')[1].split(':')[0];
7+
const port = global.RN_HARNESS?.webSocketPort || WS_SERVER_PORT;
78

8-
return `ws://${hostname}:${WS_SERVER_PORT}`;
9+
return `ws://${hostname}:${port}`;
910
};

packages/runtime/src/globals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export type HarnessGlobal = {
22
appRegistryComponentName: string;
3+
webSocketPort?: number;
34
};
45

56
declare global {

0 commit comments

Comments
 (0)