@react-native-harness/runtime 1.1.0-rc.3 → 1.1.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@react-native-harness/runtime",
3
3
  "description": "The core test runtime that executes on React Native devices, providing Jest-compatible APIs (describe, it, expect) and managing test collection, execution, and result reporting in native environments.",
4
- "version": "1.1.0-rc.3",
4
+ "version": "1.1.0-rc.4",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -44,9 +44,10 @@
44
44
  "@vitest/spy": "4.0.16",
45
45
  "chai": "^6.2.2",
46
46
  "event-target-shim": "^6.0.2",
47
+ "react-native-url-polyfill": "^3.0.0",
47
48
  "use-sync-external-store": "^1.6.0",
48
49
  "zustand": "^5.0.5",
49
- "@react-native-harness/bridge": "1.1.0-rc.3"
50
+ "@react-native-harness/bridge": "1.1.0-rc.4"
50
51
  },
51
52
  "devDependencies": {
52
53
  "@types/chai": "^5.2.2"
@@ -0,0 +1,65 @@
1
+ import { HARNESS_BRIDGE_PATH } from '@react-native-harness/bridge';
2
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
3
+ import { getWSServer } from './getWSServer.js';
4
+
5
+ const mocks = vi.hoisted(() => ({
6
+ getDevServerUrl: vi.fn(),
7
+ }));
8
+
9
+ vi.mock('../utils/dev-server.js', () => ({
10
+ getDevServerUrl: mocks.getDevServerUrl,
11
+ }));
12
+
13
+ vi.mock('react-native-url-polyfill', () => ({
14
+ URL,
15
+ }));
16
+
17
+ describe('getWSServer', () => {
18
+ beforeEach(() => {
19
+ mocks.getDevServerUrl.mockReset();
20
+ });
21
+
22
+ it('builds a websocket bridge URL from an http dev server URL', () => {
23
+ mocks.getDevServerUrl.mockReturnValue(
24
+ 'http://localhost:8081/index.bundle?platform=ios&dev=true#main',
25
+ );
26
+
27
+ expect(getWSServer()).toBe(`ws://localhost:8081${HARNESS_BRIDGE_PATH}`);
28
+ });
29
+
30
+ it('builds a secure websocket bridge URL from an https dev server URL', () => {
31
+ mocks.getDevServerUrl.mockReturnValue('HTTPS://Example.COM:19000/');
32
+
33
+ expect(getWSServer()).toBe(`wss://example.com:19000${HARNESS_BRIDGE_PATH}`);
34
+ });
35
+
36
+ it('preserves the explicit port for hostnames', () => {
37
+ mocks.getDevServerUrl.mockReturnValue('http://example.com:31337/status');
38
+
39
+ expect(getWSServer()).toBe(`ws://example.com:31337${HARNESS_BRIDGE_PATH}`);
40
+ });
41
+
42
+ it('drops user info while preserving the host for ipv6 URLs', () => {
43
+ mocks.getDevServerUrl.mockReturnValue(
44
+ 'http://user:secret@[::1]:8081/status',
45
+ );
46
+
47
+ expect(getWSServer()).toBe(`ws://[::1]:8081${HARNESS_BRIDGE_PATH}`);
48
+ });
49
+
50
+ it('preserves the port for ipv6 URLs without user info', () => {
51
+ mocks.getDevServerUrl.mockReturnValue('http://[2001:db8::1]:19001/status');
52
+
53
+ expect(getWSServer()).toBe(
54
+ `ws://[2001:db8::1]:19001${HARNESS_BRIDGE_PATH}`,
55
+ );
56
+ });
57
+
58
+ it('throws for non-absolute dev server URLs', () => {
59
+ mocks.getDevServerUrl.mockReturnValue('localhost:8081');
60
+
61
+ expect(() => getWSServer()).toThrow(
62
+ new TypeError('Invalid URL: localhost:8081'),
63
+ );
64
+ });
65
+ });
@@ -1,8 +1,15 @@
1
1
  import { HARNESS_BRIDGE_PATH } from '@react-native-harness/bridge';
2
+ import { URL } from 'react-native-url-polyfill';
2
3
  import { getDevServerUrl } from '../utils/dev-server.js';
3
4
 
4
5
  export const getWSServer = (): string => {
5
- const devServerUrl = new URL(getDevServerUrl());
6
+ const devServerUrlString = getDevServerUrl();
7
+ const devServerUrl = new URL(devServerUrlString);
8
+
9
+ if (!devServerUrl.host) {
10
+ throw new TypeError(`Invalid URL: ${devServerUrlString}`);
11
+ }
12
+
6
13
  const protocol = devServerUrl.protocol === 'https:' ? 'wss:' : 'ws:';
7
14
 
8
15
  return `${protocol}//${devServerUrl.host}${HARNESS_BRIDGE_PATH}`;