Skip to content

Commit 4f71f26

Browse files
rubennortemeta-codesync[bot]
authored andcommitted
Migrate Blob, Network, and WebSocket Jest tests to Fantom (#57266)
Summary: Pull Request resolved: #57266 Migrates `BlobRegistry`, `URL`, `FormData`, and `WebSocket` unit tests from regular Jest (`-test.js`) to Fantom (`-itest.js`), running them on Hermes in the real runtime. One `URL` assertion (`URLSearchParams.sort()`) was dropped because it depends on an ICU collator that is not available in Fantom's Hermes build; the rest of the `URL` coverage is preserved. These tests remain on Jest because they depend on capabilities Fantom does not provide (a registered native Blob module, or mocking of the native networking module): `Blob`, `BlobManager`, `File`, `FileReader`, and `XMLHttpRequest`. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D108759077 fbshipit-source-id: 7ec55a02354cfbb4449a5391a4de6b6df0082bbd
1 parent 4dfbc04 commit 4f71f26

4 files changed

Lines changed: 16 additions & 28 deletions

File tree

packages/react-native/Libraries/Blob/__tests__/BlobRegistry-test.js renamed to packages/react-native/Libraries/Blob/__tests__/BlobRegistry-itest.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
* @format
99
*/
1010

11-
'use strict';
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1212

1313
const BlobRegistry = require('../BlobRegistry');
1414

1515
describe('BlobRegistry', () => {
1616
describe('register', () => {
1717
it('does not throw error', () => {
18-
expect(() => BlobRegistry.register('id1')).not.toThrowError();
18+
expect(() => BlobRegistry.register('id1')).not.toThrow();
1919
});
2020

2121
it('registers new id', () => {
@@ -26,7 +26,7 @@ describe('BlobRegistry', () => {
2626

2727
describe('unregister', () => {
2828
it('does not throw error', () => {
29-
expect(() => BlobRegistry.unregister('id3')).not.toThrowError();
29+
expect(() => BlobRegistry.unregister('id3')).not.toThrow();
3030
});
3131

3232
it('remove registered id', () => {

packages/react-native/Libraries/Blob/__tests__/URL-test.js renamed to packages/react-native/Libraries/Blob/__tests__/URL-itest.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @format
99
*/
1010

11-
'use strict';
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1212

1313
const URL = require('../URL').URL;
1414
const URLSearchParams = require('../URL').URLSearchParams;
@@ -133,12 +133,9 @@ describe('URL', function () {
133133
expect(urlParams.has('query')).toBe(true);
134134
expect(urlParams.has('key')).toBe(false);
135135

136-
// Sorting URLSearchParams
137-
const unsortedParams = new URLSearchParams(
138-
'?z=last&b=second&c=third&a=first',
139-
);
140-
unsortedParams.sort();
141-
expect(unsortedParams.toString()).toBe('a=first&b=second&c=third&z=last');
136+
// Sorting URLSearchParams is not exercised here: URLSearchParams.sort()
137+
// relies on String.prototype.localeCompare, which requires ICU collation
138+
// support that is unavailable in Fantom's Hermes build.
142139

143140
// searchParams.set() should replace values not duplicate them
144141
const urlWithSearchParams = new URL(

packages/react-native/Libraries/Network/__tests__/FormData-test.js renamed to packages/react-native/Libraries/Network/__tests__/FormData-itest.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @format
99
*/
1010

11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
12+
1113
import FormData from '../FormData';
1214

1315
describe('FormData', function () {
@@ -28,7 +30,7 @@ describe('FormData', function () {
2830
},
2931
fieldName: 'null',
3032
};
31-
expect(formData.getParts()[0]).toMatchObject(expectedPart);
33+
expect(formData.getParts()[0]).toEqual(expectedPart);
3234
});
3335

3436
it('should return blob', function () {
@@ -48,7 +50,7 @@ describe('FormData', function () {
4850
},
4951
fieldName: 'photo',
5052
};
51-
expect(formData.getParts()[0]).toMatchObject(expectedPart);
53+
expect(formData.getParts()[0]).toEqual(expectedPart);
5254
});
5355

5456
it('should return blob with the correct utf-8 handling', function () {
@@ -69,7 +71,7 @@ describe('FormData', function () {
6971
},
7072
fieldName: 'photo',
7173
};
72-
expect(formData.getParts()[0]).toMatchObject(expectedPart);
74+
expect(formData.getParts()[0]).toEqual(expectedPart);
7375
});
7476

7577
it('should return non blob array', function () {
@@ -92,7 +94,7 @@ describe('FormData', function () {
9294
},
9395
fieldName: 'array',
9496
};
95-
expect(formData.getParts()[0]).toMatchObject(expectedPart);
97+
expect(formData.getParts()[0]).toEqual(expectedPart);
9698
});
9799

98100
it('should return values based on the given key', function () {
@@ -101,7 +103,7 @@ describe('FormData', function () {
101103

102104
expect(formData.getAll('username').length).toBe(2);
103105

104-
expect(formData.getAll('username')).toMatchObject(['Chris', 'Bob']);
106+
expect(formData.getAll('username')).toEqual(['Chris', 'Bob']);
105107

106108
formData.append('photo', {
107109
uri: 'arbitrary/path',
@@ -121,7 +123,7 @@ describe('FormData', function () {
121123
name: 'photo2.jpg',
122124
};
123125

124-
expect(formData.getAll('photo')[1]).toMatchObject(expectedPart);
126+
expect(formData.getAll('photo')[1]).toEqual(expectedPart);
125127

126128
expect(formData.getAll('file').length).toBe(0);
127129
});

packages/react-native/Libraries/WebSocket/__tests__/WebSocket-test.js renamed to packages/react-native/Libraries/WebSocket/__tests__/WebSocket-itest.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,7 @@
88
* @format
99
*/
1010

11-
'use strict';
12-
13-
jest.mock('../../EventEmitter/NativeEventEmitter');
14-
jest.setMock('../../BatchedBridge/NativeModules', {
15-
__esModule: true,
16-
default: {
17-
WebSocketModule: {
18-
connect: () => {},
19-
},
20-
PlatformConstants: {},
21-
},
22-
});
11+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
2312

2413
const WebSocket = require('../WebSocket').default;
2514

0 commit comments

Comments
 (0)