react-native-tvos 0.72.4-0rc1 → 0.72.6-0

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.
Files changed (70) hide show
  1. package/Libraries/Core/ReactNativeVersion.js +2 -2
  2. package/Libraries/vendor/emitter/EventEmitter.js +3 -1
  3. package/README-core.md +147 -0
  4. package/README.md +4 -3
  5. package/React/Base/RCTBundleURLProvider.h +33 -2
  6. package/React/Base/RCTBundleURLProvider.mm +78 -15
  7. package/React/Base/RCTVersion.m +2 -2
  8. package/React/CoreModules/RCTTiming.mm +5 -0
  9. package/ReactAndroid/gradle.properties +1 -1
  10. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +2 -2
  11. package/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java +5 -0
  12. package/ReactAndroid/src/main/java/com/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper.java +4 -0
  13. package/ReactAndroid/src/main/jni/CMakeLists.txt +5 -0
  14. package/ReactCommon/React-Fabric.podspec +1 -1
  15. package/ReactCommon/ReactCommon.podspec +1 -1
  16. package/ReactCommon/cxxreact/ReactNativeVersion.h +2 -2
  17. package/ReactCommon/jsc/JSCRuntime.cpp +10 -0
  18. package/ReactCommon/react/debug/React-debug.podspec +1 -1
  19. package/ReactCommon/react/nativemodule/core/platform/ios/React-NativeModulesApple.podspec +1 -1
  20. package/ReactCommon/react/nativemodule/samples/ReactCommon-Samples.podspec +1 -1
  21. package/ReactCommon/react/renderer/core/RawPropsKeyMap.cpp +2 -0
  22. package/ReactCommon/react/renderer/core/RawPropsParser.cpp +1 -0
  23. package/ReactCommon/react/renderer/core/RawPropsPrimitives.h +4 -4
  24. package/ReactCommon/react/renderer/graphics/React-graphics.podspec +1 -1
  25. package/ReactCommon/react/renderer/imagemanager/platform/ios/React-ImageManager.podspec +1 -1
  26. package/ReactCommon/react/renderer/runtimescheduler/React-runtimescheduler.podspec +1 -1
  27. package/ReactCommon/react/utils/React-utils.podspec +1 -1
  28. package/package.json +8 -7
  29. package/scripts/cocoapods/helpers.rb +16 -0
  30. package/scripts/cocoapods/utils.rb +104 -8
  31. package/scripts/react_native_pods.rb +6 -2
  32. package/sdks/hermes-engine/utils/build-apple-framework.sh +8 -1
  33. package/sdks/hermes-engine/utils/build-hermes-xcode.sh +8 -0
  34. package/sdks/hermesc/linux64-bin/hermesc +0 -0
  35. package/sdks/hermesc/osx-bin/hermesc +0 -0
  36. package/sdks/hermesc/win64-bin/hermesc.exe +0 -0
  37. package/template/Gemfile +2 -1
  38. package/template/ios/HelloWorld.xcodeproj/project.pbxproj +95 -13
  39. package/template/package.json +2 -2
  40. package/types/index.d.ts +1 -0
  41. package/types/public/ReactNativeTVTypes.d.ts +192 -0
  42. package/ReactAndroid/src/main/java/com/facebook/react/ReactAndroidHWInputDeviceHelper.java +0 -98
  43. package/scripts/cocoapods/__tests__/codegen-test.rb +0 -242
  44. package/scripts/cocoapods/__tests__/codegen_utils-test.rb +0 -602
  45. package/scripts/cocoapods/__tests__/fabric-test.rb +0 -68
  46. package/scripts/cocoapods/__tests__/flipper-test.rb +0 -161
  47. package/scripts/cocoapods/__tests__/jsengine-test.rb +0 -130
  48. package/scripts/cocoapods/__tests__/local_podspec_patch-test.rb +0 -167
  49. package/scripts/cocoapods/__tests__/new_architecture-test.rb +0 -303
  50. package/scripts/cocoapods/__tests__/test_utils/CodegenScriptPhaseExtractorMock.rb +0 -21
  51. package/scripts/cocoapods/__tests__/test_utils/CodegenUtilsMock.rb +0 -108
  52. package/scripts/cocoapods/__tests__/test_utils/DirMock.rb +0 -72
  53. package/scripts/cocoapods/__tests__/test_utils/EnvironmentMock.rb +0 -21
  54. package/scripts/cocoapods/__tests__/test_utils/FileMock.rb +0 -113
  55. package/scripts/cocoapods/__tests__/test_utils/FileUtilsMock.rb +0 -40
  56. package/scripts/cocoapods/__tests__/test_utils/FinderMock.rb +0 -28
  57. package/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb +0 -222
  58. package/scripts/cocoapods/__tests__/test_utils/LocalPodspecPatchMock.rb +0 -14
  59. package/scripts/cocoapods/__tests__/test_utils/Open3Mock.rb +0 -43
  60. package/scripts/cocoapods/__tests__/test_utils/PathnameMock.rb +0 -42
  61. package/scripts/cocoapods/__tests__/test_utils/PodMock.rb +0 -144
  62. package/scripts/cocoapods/__tests__/test_utils/SpecMock.rb +0 -30
  63. package/scripts/cocoapods/__tests__/test_utils/SysctlCheckerMock.rb +0 -21
  64. package/scripts/cocoapods/__tests__/test_utils/TargetDefinitionMock.rb +0 -12
  65. package/scripts/cocoapods/__tests__/test_utils/podSpy.rb +0 -39
  66. package/scripts/cocoapods/__tests__/test_utils/systemUtils.rb +0 -14
  67. package/scripts/cocoapods/__tests__/utils-test.rb +0 -766
  68. package/scripts/codegen/__test_fixtures__/fixtures.js +0 -132
  69. package/scripts/codegen/__tests__/generate-artifacts-executor-test.js +0 -500
  70. package/scripts/codegen/__tests__/generate-specs-cli-executor-test.js +0 -88
@@ -1,132 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @oncall react_native
9
- */
10
-
11
- 'use-strict';
12
-
13
- const SINGLE_LIBRARY_CODEGEN_CONFIG = {
14
- codegenConfig: {
15
- libraries: [
16
- {
17
- name: 'react-native',
18
- type: 'all',
19
- jsSrcsDir: '.',
20
- },
21
- ],
22
- },
23
- };
24
-
25
- const MULTIPLE_LIBRARIES_CODEGEN_CONFIG = {
26
- codegenConfig: {
27
- libraries: [
28
- {
29
- name: 'react-native',
30
- type: 'all',
31
- jsSrcsDir: '.',
32
- },
33
- {
34
- name: 'my-component',
35
- type: 'components',
36
- jsSrcsDir: 'component/js',
37
- },
38
- {
39
- name: 'my-module',
40
- type: 'module',
41
- jsSrcsDir: 'module/js',
42
- },
43
- ],
44
- },
45
- };
46
-
47
- const NO_LIBRARIES_CONFIG_FILE = {
48
- codegenConfig: {
49
- name: 'AppModules',
50
- type: 'all',
51
- jsSrcsDir: '.',
52
- },
53
- };
54
-
55
- const SCHEMA_TEXT = `
56
- {
57
- "modules": {
58
- "ColoredView": {
59
- "type": "Component",
60
- "components": {
61
- "ColoredView": {
62
- "extendsProps": [
63
- {
64
- "type": "ReactNativeBuiltInType",
65
- "knownTypeName": "ReactNativeCoreViewProps"
66
- }
67
- ],
68
- "events": [],
69
- "props": [
70
- {
71
- "name": "color",
72
- "optional": false,
73
- "typeAnnotation": {
74
- "type": "StringTypeAnnotation",
75
- "default": null
76
- }
77
- }
78
- ],
79
- "commands": []
80
- }
81
- }
82
- },
83
- "NativeCalculator": {
84
- "type": "NativeModule",
85
- "aliases": {},
86
- "spec": {
87
- "properties": [
88
- {
89
- "name": "add",
90
- "optional": false,
91
- "typeAnnotation": {
92
- "type": "FunctionTypeAnnotation",
93
- "returnTypeAnnotation": {
94
- "type": "PromiseTypeAnnotation"
95
- },
96
- "params": [
97
- {
98
- "name": "a",
99
- "optional": false,
100
- "typeAnnotation": {
101
- "type": "NumberTypeAnnotation"
102
- }
103
- },
104
- {
105
- "name": "b",
106
- "optional": false,
107
- "typeAnnotation": {
108
- "type": "NumberTypeAnnotation"
109
- }
110
- }
111
- ]
112
- }
113
- }
114
- ]
115
- },
116
- "moduleNames": [
117
- "Calculator"
118
- ]
119
- }
120
- }
121
- }
122
- `;
123
-
124
- const SCHEMA = JSON.parse(SCHEMA_TEXT);
125
-
126
- module.exports = {
127
- schemaText: SCHEMA_TEXT,
128
- schema: SCHEMA,
129
- noLibrariesConfigFile: NO_LIBRARIES_CONFIG_FILE,
130
- singleLibraryCodegenConfig: SINGLE_LIBRARY_CODEGEN_CONFIG,
131
- multipleLibrariesCodegenConfig: MULTIPLE_LIBRARIES_CODEGEN_CONFIG,
132
- };
@@ -1,500 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @oncall react_native
9
- */
10
-
11
- 'use strict';
12
-
13
- const underTest = require('../generate-artifacts-executor');
14
- const fixtures = require('../__test_fixtures__/fixtures');
15
- const path = require('path');
16
- const fs = require('fs');
17
- const child_process = require('child_process');
18
-
19
- const codegenConfigKey = 'codegenConfig';
20
- const reactNativeDependencyName = 'react-native';
21
- const rootPath = path.join(__dirname, '../../..');
22
-
23
- describe('generateCode', () => {
24
- afterEach(() => {
25
- jest.resetModules();
26
- jest.resetAllMocks();
27
- });
28
-
29
- it('executeNodes with the right arguments', () => {
30
- // Define variables and expected values
31
- const iosOutputDir = 'app/ios/build/generated/ios';
32
- const library = {config: {name: 'library', type: 'all'}};
33
- const tmpDir = 'tmp';
34
- const node = 'usr/bin/node';
35
- const pathToSchema = 'app/build/schema.json';
36
- const rnRoot = path.join(__dirname, '../..');
37
- const libraryType = 'all';
38
-
39
- const tmpOutDir = path.join(tmpDir, 'out');
40
-
41
- // mock used functions
42
- jest.spyOn(fs, 'mkdirSync').mockImplementation();
43
- jest.spyOn(child_process, 'execSync').mockImplementation();
44
-
45
- underTest._generateCode(iosOutputDir, library, tmpDir, node, pathToSchema);
46
-
47
- const expectedCommand = `${node} ${path.join(
48
- rnRoot,
49
- 'generate-specs-cli.js',
50
- )} --platform ios --schemaPath ${pathToSchema} --outputDir ${tmpOutDir} --libraryName ${
51
- library.config.name
52
- } --libraryType ${libraryType}`;
53
-
54
- expect(child_process.execSync).toHaveBeenCalledTimes(2);
55
- expect(child_process.execSync).toHaveBeenNthCalledWith(1, expectedCommand);
56
- expect(child_process.execSync).toHaveBeenNthCalledWith(
57
- 2,
58
- `cp -R ${tmpOutDir}/* ${iosOutputDir}`,
59
- );
60
-
61
- expect(fs.mkdirSync).toHaveBeenCalledTimes(2);
62
- expect(fs.mkdirSync).toHaveBeenNthCalledWith(1, tmpOutDir, {
63
- recursive: true,
64
- });
65
- expect(fs.mkdirSync).toHaveBeenNthCalledWith(2, iosOutputDir, {
66
- recursive: true,
67
- });
68
- });
69
- });
70
-
71
- describe('extractLibrariesFromJSON', () => {
72
- it('throws if in react-native and no dependencies found', () => {
73
- let libraries = [];
74
- let configFile = {};
75
- expect(() => {
76
- underTest._extractLibrariesFromJSON(
77
- configFile,
78
- libraries,
79
- codegenConfigKey,
80
- );
81
- }).toThrow();
82
- });
83
-
84
- it('it skips if not into react-native and no dependencies found', () => {
85
- let libraries = [];
86
- let configFile = {};
87
-
88
- underTest._extractLibrariesFromJSON(
89
- configFile,
90
- libraries,
91
- codegenConfigKey,
92
- 'some-node-module',
93
- 'node_modules/some',
94
- );
95
- expect(libraries.length).toBe(0);
96
- });
97
-
98
- it('extracts a single dependency when config has no libraries', () => {
99
- let libraries = [];
100
- let configFile = fixtures.noLibrariesConfigFile;
101
- underTest._extractLibrariesFromJSON(
102
- configFile,
103
- libraries,
104
- codegenConfigKey,
105
- 'my-app',
106
- '.',
107
- );
108
- expect(libraries.length).toBe(1);
109
- expect(libraries[0]).toEqual({
110
- library: 'my-app',
111
- config: {
112
- name: 'AppModules',
113
- type: 'all',
114
- jsSrcsDir: '.',
115
- },
116
- libraryPath: '.',
117
- });
118
- });
119
-
120
- it("extract codegenConfig when it's empty", () => {
121
- const configFile = {codegenConfig: {libraries: []}};
122
- let libraries = [];
123
- underTest._extractLibrariesFromJSON(
124
- configFile,
125
- codegenConfigKey,
126
- libraries,
127
- reactNativeDependencyName,
128
- rootPath,
129
- );
130
- expect(libraries.length).toBe(0);
131
- });
132
-
133
- it('extract codegenConfig when dependency is one', () => {
134
- const configFile = fixtures.singleLibraryCodegenConfig;
135
- let libraries = [];
136
- underTest._extractLibrariesFromJSON(
137
- configFile,
138
- libraries,
139
- codegenConfigKey,
140
- reactNativeDependencyName,
141
- rootPath,
142
- );
143
- expect(libraries.length).toBe(1);
144
- expect(libraries[0]).toEqual({
145
- library: reactNativeDependencyName,
146
- config: {
147
- name: 'react-native',
148
- type: 'all',
149
- jsSrcsDir: '.',
150
- },
151
- libraryPath: rootPath,
152
- });
153
- });
154
-
155
- it('extract codegenConfig with multiple dependencies', () => {
156
- const configFile = fixtures.multipleLibrariesCodegenConfig;
157
- const myDependency = 'my-dependency';
158
- const myDependencyPath = path.join(__dirname, myDependency);
159
- let libraries = [];
160
- underTest._extractLibrariesFromJSON(
161
- configFile,
162
- libraries,
163
- codegenConfigKey,
164
- myDependency,
165
- myDependencyPath,
166
- );
167
- expect(libraries.length).toBe(3);
168
- expect(libraries[0]).toEqual({
169
- library: myDependency,
170
- config: {
171
- name: 'react-native',
172
- type: 'all',
173
- jsSrcsDir: '.',
174
- },
175
- libraryPath: myDependencyPath,
176
- });
177
- expect(libraries[1]).toEqual({
178
- library: myDependency,
179
- config: {
180
- name: 'my-component',
181
- type: 'components',
182
- jsSrcsDir: 'component/js',
183
- },
184
- libraryPath: myDependencyPath,
185
- });
186
- expect(libraries[2]).toEqual({
187
- library: myDependency,
188
- config: {
189
- name: 'my-module',
190
- type: 'module',
191
- jsSrcsDir: 'module/js',
192
- },
193
- libraryPath: myDependencyPath,
194
- });
195
- });
196
- });
197
-
198
- describe('findCodegenEnabledLibraries', () => {
199
- const mock = require('mock-fs');
200
- const {
201
- _findCodegenEnabledLibraries: findCodegenEnabledLibraries,
202
- } = require('../generate-artifacts-executor');
203
-
204
- afterEach(() => {
205
- mock.restore();
206
- });
207
-
208
- it('returns libraries defined in react-native.config.js', () => {
209
- const projectDir = path.join(__dirname, '../../../../test-project');
210
- const baseCodegenConfigFileDir = path.join(__dirname, '../../..');
211
- const baseCodegenConfigFilePath = path.join(
212
- baseCodegenConfigFileDir,
213
- 'package.json',
214
- );
215
-
216
- mock({
217
- [baseCodegenConfigFilePath]: `
218
- {
219
- "codegenConfig": {}
220
- }
221
- `,
222
- [projectDir]: {
223
- app: {
224
- 'package.json': `{
225
- "name": "my-app"
226
- }`,
227
- 'react-native.config.js': '',
228
- },
229
- 'library-foo': {
230
- 'package.json': `{
231
- "name": "react-native-foo",
232
- "codegenConfig": {
233
- "name": "RNFooSpec",
234
- "type": "modules",
235
- "jsSrcsDir": "src"
236
- }
237
- }`,
238
- },
239
- },
240
- });
241
-
242
- jest.mock(path.join(projectDir, 'app', 'react-native.config.js'), () => ({
243
- dependencies: {
244
- 'react-native-foo': {
245
- root: path.join(projectDir, 'library-foo'),
246
- },
247
- 'react-native-bar': {
248
- root: path.join(projectDir, 'library-bar'),
249
- },
250
- },
251
- }));
252
-
253
- const libraries = findCodegenEnabledLibraries(
254
- `${projectDir}/app`,
255
- baseCodegenConfigFileDir,
256
- `package.json`,
257
- 'codegenConfig',
258
- );
259
-
260
- expect(libraries).toEqual([
261
- {
262
- library: 'react-native',
263
- config: {},
264
- libraryPath: baseCodegenConfigFileDir,
265
- },
266
- {
267
- library: 'react-native-foo',
268
- config: {name: 'RNFooSpec', type: 'modules', jsSrcsDir: 'src'},
269
- libraryPath: path.join(projectDir, 'library-foo'),
270
- },
271
- ]);
272
- });
273
- });
274
-
275
- describe('delete empty files and folders', () => {
276
- beforeEach(() => {
277
- jest.resetModules();
278
- });
279
-
280
- it('when path is empty file, deletes it', () => {
281
- const targetFilepath = 'my-file.txt';
282
- let statSyncInvocationCount = 0;
283
- let rmSyncInvocationCount = 0;
284
- let rmdirSyncInvocationCount = 0;
285
- jest.mock('fs', () => ({
286
- statSync: filepath => {
287
- statSyncInvocationCount += 1;
288
- expect(filepath).toBe(targetFilepath);
289
- return {
290
- isFile: () => {
291
- return true;
292
- },
293
- size: 0,
294
- };
295
- },
296
- rmSync: filepath => {
297
- rmSyncInvocationCount += 1;
298
- expect(filepath).toBe(targetFilepath);
299
- },
300
- rmdirSync: filepath => {
301
- rmdirSyncInvocationCount += 1;
302
- },
303
- }));
304
-
305
- underTest._cleanupEmptyFilesAndFolders(targetFilepath);
306
- expect(statSyncInvocationCount).toBe(1);
307
- expect(rmSyncInvocationCount).toBe(1);
308
- expect(rmdirSyncInvocationCount).toBe(0);
309
- });
310
-
311
- it('when path is not an empty file, does nothing', () => {
312
- const targetFilepath = 'my-file.txt';
313
- const size = 128;
314
-
315
- let statSyncInvocationCount = 0;
316
- let rmSyncInvocationCount = 0;
317
- let rmdirSyncInvocationCount = 0;
318
-
319
- jest.mock('fs', () => ({
320
- statSync: filepath => {
321
- statSyncInvocationCount += 1;
322
- expect(filepath).toBe(targetFilepath);
323
- return {
324
- isFile: () => {
325
- return true;
326
- },
327
- size: size,
328
- };
329
- },
330
- rmSync: filepath => {
331
- rmSyncInvocationCount += 1;
332
- },
333
- rmdirSync: filepath => {
334
- rmdirSyncInvocationCount += 1;
335
- },
336
- }));
337
-
338
- underTest._cleanupEmptyFilesAndFolders(targetFilepath);
339
- expect(statSyncInvocationCount).toBe(1);
340
- expect(rmSyncInvocationCount).toBe(0);
341
- expect(rmdirSyncInvocationCount).toBe(0);
342
- });
343
-
344
- it("when path is folder and it's empty, removes it", () => {
345
- const targetFolder = 'build';
346
- const content = [];
347
-
348
- let statSyncInvocationCount = 0;
349
- let readdirInvocationCount = 0;
350
- let rmSyncInvocationCount = 0;
351
- let rmdirSyncInvocationCount = 0;
352
-
353
- jest.mock('fs', () => ({
354
- statSync: filepath => {
355
- statSyncInvocationCount += 1;
356
- expect(filepath).toBe(targetFolder);
357
- return {
358
- isFile: () => {
359
- return false;
360
- },
361
- };
362
- },
363
- rmSync: filepath => {
364
- rmSyncInvocationCount += 1;
365
- },
366
- rmdirSync: filepath => {
367
- rmdirSyncInvocationCount += 1;
368
- expect(filepath).toBe(targetFolder);
369
- },
370
- readdirSync: filepath => {
371
- readdirInvocationCount += 1;
372
- return content;
373
- },
374
- }));
375
-
376
- underTest._cleanupEmptyFilesAndFolders(targetFolder);
377
- expect(statSyncInvocationCount).toBe(1);
378
- expect(readdirInvocationCount).toBe(2);
379
- expect(rmSyncInvocationCount).toBe(0);
380
- expect(rmdirSyncInvocationCount).toBe(1);
381
- });
382
-
383
- it("when path is folder and it's not empty, removes only empty folders and files", () => {
384
- const targetFolder = 'build';
385
- const content = ['emptyFolder', 'emptyFile', 'notEmptyFile'];
386
-
387
- const files = [
388
- path.normalize('build/emptyFile'),
389
- path.normalize('build/notEmptyFile'),
390
- ];
391
-
392
- const emptyContent = [];
393
- let fileSizes = {};
394
- fileSizes[path.normalize('build/emptyFile')] = 0;
395
- fileSizes[path.normalize('build/notEmptyFile')] = 32;
396
-
397
- let statSyncInvocation = [];
398
- let rmSyncInvocation = [];
399
- let rmdirSyncInvocation = [];
400
- let readdirInvocation = [];
401
-
402
- jest.mock('fs', () => ({
403
- statSync: filepath => {
404
- statSyncInvocation.push(filepath);
405
-
406
- return {
407
- isFile: () => {
408
- return files.includes(filepath);
409
- },
410
- size: fileSizes[filepath],
411
- };
412
- },
413
- rmSync: filepath => {
414
- rmSyncInvocation.push(filepath);
415
- },
416
- rmdirSync: filepath => {
417
- rmdirSyncInvocation.push(filepath);
418
- },
419
- readdirSync: filepath => {
420
- readdirInvocation.push(filepath);
421
- return filepath === targetFolder ? content : emptyContent;
422
- },
423
- }));
424
-
425
- underTest._cleanupEmptyFilesAndFolders(targetFolder);
426
- expect(statSyncInvocation).toEqual([
427
- path.normalize('build'),
428
- path.normalize('build/emptyFolder'),
429
- path.normalize('build/emptyFile'),
430
- path.normalize('build/notEmptyFile'),
431
- ]);
432
- expect(readdirInvocation).toEqual([
433
- path.normalize('build'),
434
- path.normalize('build/emptyFolder'),
435
- path.normalize('build/emptyFolder'),
436
- path.normalize('build'),
437
- ]);
438
- expect(rmSyncInvocation).toEqual([path.normalize('build/emptyFile')]);
439
- expect(rmdirSyncInvocation).toEqual([path.normalize('build/emptyFolder')]);
440
- });
441
-
442
- it('when path is folder and it contains only empty folders, removes everything', () => {
443
- const targetFolder = 'build';
444
- const content = ['emptyFolder1', 'emptyFolder2'];
445
- const emptyContent = [];
446
-
447
- let statSyncInvocation = [];
448
- let rmSyncInvocation = [];
449
- let rmdirSyncInvocation = [];
450
- let readdirInvocation = [];
451
-
452
- jest.mock('fs', () => ({
453
- statSync: filepath => {
454
- statSyncInvocation.push(filepath);
455
-
456
- return {
457
- isFile: () => {
458
- return false;
459
- },
460
- };
461
- },
462
- rmSync: filepath => {
463
- rmSyncInvocation.push(filepath);
464
- },
465
- rmdirSync: filepath => {
466
- rmdirSyncInvocation.push(filepath);
467
- },
468
- readdirSync: filepath => {
469
- readdirInvocation.push(filepath);
470
- return filepath === targetFolder
471
- ? content.filter(
472
- element =>
473
- !rmdirSyncInvocation.includes(path.join(targetFolder, element)),
474
- )
475
- : emptyContent;
476
- },
477
- }));
478
-
479
- underTest._cleanupEmptyFilesAndFolders(targetFolder);
480
- expect(statSyncInvocation).toEqual([
481
- path.normalize('build'),
482
- path.normalize('build/emptyFolder1'),
483
- path.normalize('build/emptyFolder2'),
484
- ]);
485
- expect(readdirInvocation).toEqual([
486
- path.normalize('build'),
487
- path.normalize('build/emptyFolder1'),
488
- path.normalize('build/emptyFolder1'),
489
- path.normalize('build/emptyFolder2'),
490
- path.normalize('build/emptyFolder2'),
491
- path.normalize('build'),
492
- ]);
493
- expect(rmSyncInvocation).toEqual([]);
494
- expect(rmdirSyncInvocation).toEqual([
495
- path.normalize('build/emptyFolder1'),
496
- path.normalize('build/emptyFolder2'),
497
- path.normalize('build'),
498
- ]);
499
- });
500
- });
@@ -1,88 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @oncall react_native
9
- */
10
-
11
- 'use strict';
12
-
13
- const sut = require('../generate-specs-cli-executor');
14
- const fixtures = require('../__test_fixtures__/fixtures');
15
- const {normalize} = require('path');
16
-
17
- describe('generateSpec', () => {
18
- it('invokes RNCodegen with the right params', () => {
19
- const platform = 'ios';
20
- const libraryType = 'all';
21
- const schemaPath = './';
22
- const componentsOutputDir = normalize(
23
- 'app/ios/build/generated/ios/react/renderer/components/library',
24
- );
25
- const modulesOutputDir = normalize('app/ios/build/generated/ios/library');
26
- const outputDirectory = normalize('app/ios/build/generated/ios');
27
- const libraryName = 'library';
28
- const packageName = 'com.library';
29
- const generators = ['componentsIOS', 'modulesIOS', 'modulesCxx'];
30
-
31
- jest.mock('fs', () => ({
32
- readFileSync: (path, encoding) => {
33
- expect(path).toBe(schemaPath);
34
- expect(encoding).toBe('utf-8');
35
- return fixtures.schemaText;
36
- },
37
- }));
38
-
39
- let mkdirpSyncInvoked = 0;
40
- jest.mock('mkdirp', () => ({
41
- sync: folder => {
42
- if (mkdirpSyncInvoked === 0) {
43
- expect(folder).toBe(outputDirectory);
44
- }
45
-
46
- if (mkdirpSyncInvoked === 1) {
47
- expect(folder).toBe(componentsOutputDir);
48
- }
49
-
50
- if (mkdirpSyncInvoked === 2) {
51
- expect(folder).toBe(modulesOutputDir);
52
- }
53
-
54
- mkdirpSyncInvoked += 1;
55
- },
56
- }));
57
-
58
- // We cannot mock directly the `RNCodegen` object because the
59
- // code access the `lib` folder directly and request a file explicitly.
60
- // This makes testing harder than usually. To overcome this, we created a utility
61
- // to retrieve the `Codegen`. By doing that, we can mock the wrapper so that it returns
62
- // an object with the same interface of the `RNCodegen` object.
63
- jest.mock('../codegen-utils', () => ({
64
- getCodegen: () => ({
65
- generate: (libraryConfig, generatorConfigs) => {
66
- expect(libraryConfig.libraryName).toBe(libraryName);
67
- expect(libraryConfig.schema).toStrictEqual(fixtures.schema);
68
- expect(libraryConfig.outputDirectory).toBe(outputDirectory);
69
- expect(libraryConfig.packageName).toBe(packageName);
70
-
71
- expect(generatorConfigs.generators).toStrictEqual(generators);
72
- expect(generatorConfigs.test).toBeUndefined();
73
- },
74
- }),
75
- }));
76
-
77
- sut.execute(
78
- platform,
79
- schemaPath,
80
- outputDirectory,
81
- libraryName,
82
- packageName,
83
- libraryType,
84
- );
85
-
86
- expect(mkdirpSyncInvoked).toBe(3);
87
- });
88
- });