|
| 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 | + * @flow strict-local |
| 8 | + * @format |
| 9 | + * @oncall react_native |
| 10 | + */ |
| 11 | + |
| 12 | +'use-strict'; |
| 13 | + |
| 14 | +const {parseArgs, filterJSFile} = require('../combine-utils.js'); |
| 15 | + |
| 16 | +describe('parseArgs', () => { |
| 17 | + const nodeBin = 'node'; |
| 18 | + const combineApp = 'app'; |
| 19 | + const schemaJson = 'schema.json'; |
| 20 | + const specFile1 = 'NativeSpec.js'; |
| 21 | + const specFile2 = 'SpecNativeComponent.js'; |
| 22 | + |
| 23 | + describe('when no platform provided', () => { |
| 24 | + it('returns null platform, schema and fileList', () => { |
| 25 | + const {platform, outfile, fileList} = parseArgs([ |
| 26 | + nodeBin, |
| 27 | + combineApp, |
| 28 | + schemaJson, |
| 29 | + specFile1, |
| 30 | + specFile2, |
| 31 | + ]); |
| 32 | + |
| 33 | + expect(platform).toBeNull(); |
| 34 | + expect(outfile).toBe(schemaJson); |
| 35 | + expect(fileList).toStrictEqual([specFile1, specFile2]); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + describe('when platform passed with --platform', () => { |
| 40 | + it('returns the platform, the schema and the fileList', () => { |
| 41 | + const {platform, outfile, fileList} = parseArgs([ |
| 42 | + nodeBin, |
| 43 | + combineApp, |
| 44 | + '--platform', |
| 45 | + 'ios', |
| 46 | + schemaJson, |
| 47 | + specFile1, |
| 48 | + specFile2, |
| 49 | + ]); |
| 50 | + |
| 51 | + expect(platform).toBe('ios'); |
| 52 | + expect(outfile).toBe(schemaJson); |
| 53 | + expect(fileList).toStrictEqual([specFile1, specFile2]); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('when platform passed with -p', () => { |
| 58 | + it('returns the platform, the schema and the fileList', () => { |
| 59 | + const {platform, outfile, fileList} = parseArgs([ |
| 60 | + nodeBin, |
| 61 | + combineApp, |
| 62 | + '-p', |
| 63 | + 'android', |
| 64 | + schemaJson, |
| 65 | + specFile1, |
| 66 | + specFile2, |
| 67 | + ]); |
| 68 | + |
| 69 | + expect(platform).toBe('android'); |
| 70 | + expect(outfile).toBe(schemaJson); |
| 71 | + expect(fileList).toStrictEqual([specFile1, specFile2]); |
| 72 | + }); |
| 73 | + }); |
| 74 | +}); |
| 75 | + |
| 76 | +describe('filterJSFile', () => { |
| 77 | + describe('When the file is not a Spec file', () => { |
| 78 | + it('when no platform is passed, return false', () => { |
| 79 | + const file = 'anyJSFile.js'; |
| 80 | + const result = filterJSFile(file); |
| 81 | + expect(result).toBeFalsy(); |
| 82 | + }); |
| 83 | + |
| 84 | + it('when ios is passed and the file is iOS specific, return false', () => { |
| 85 | + const file = 'anyJSFile.ios.js'; |
| 86 | + const result = filterJSFile(file); |
| 87 | + expect(result).toBeFalsy(); |
| 88 | + }); |
| 89 | + |
| 90 | + it('when android is passed and the file is android specific, return false', () => { |
| 91 | + const file = 'anyJSFile.android.js'; |
| 92 | + const result = filterJSFile(file); |
| 93 | + expect(result).toBeFalsy(); |
| 94 | + }); |
| 95 | + }); |
| 96 | + |
| 97 | + describe('When the file is NativeUIManager', () => { |
| 98 | + it('returns false', () => { |
| 99 | + const file = 'NativeUIManager.js'; |
| 100 | + const result = filterJSFile(file); |
| 101 | + expect(result).toBeFalsy(); |
| 102 | + }); |
| 103 | + }); |
| 104 | + |
| 105 | + describe('When the file is NativeSampleTurboModule', () => { |
| 106 | + it('returns false', () => { |
| 107 | + const file = 'NativeSampleTurboModule.js'; |
| 108 | + const result = filterJSFile(file); |
| 109 | + expect(result).toBeFalsy(); |
| 110 | + }); |
| 111 | + }); |
| 112 | + |
| 113 | + describe('When the file is a test file', () => { |
| 114 | + it('returns false', () => { |
| 115 | + const file = '__tests__/NativeModule-test.js'; |
| 116 | + const result = filterJSFile(file); |
| 117 | + expect(result).toBeFalsy(); |
| 118 | + }); |
| 119 | + }); |
| 120 | + |
| 121 | + describe('When the file is a TS type def', () => { |
| 122 | + it('returns false', () => { |
| 123 | + const file = 'NativeModule.d.ts'; |
| 124 | + const result = filterJSFile(file); |
| 125 | + expect(result).toBeFalsy(); |
| 126 | + }); |
| 127 | + }); |
| 128 | + |
| 129 | + describe('When the file is valid and it is platform agnostic', () => { |
| 130 | + const file = 'NativeModule.js'; |
| 131 | + it('if the platform is null, returns true', () => { |
| 132 | + const result = filterJSFile(file); |
| 133 | + expect(result).toBeTruthy(); |
| 134 | + }); |
| 135 | + it('if the platform is ios, returns true', () => { |
| 136 | + const result = filterJSFile(file, 'ios'); |
| 137 | + expect(result).toBeTruthy(); |
| 138 | + }); |
| 139 | + it('if the platform is android, returns true', () => { |
| 140 | + const result = filterJSFile(file, 'android'); |
| 141 | + expect(result).toBeTruthy(); |
| 142 | + }); |
| 143 | + it('if the platform is windows, returns false', () => { |
| 144 | + const result = filterJSFile(file, 'windows'); |
| 145 | + expect(result).toBeTruthy(); |
| 146 | + }); |
| 147 | + }); |
| 148 | + |
| 149 | + describe('When the file is valid and it is iOS specific', () => { |
| 150 | + const file = 'MySampleNativeComponent.ios.js'; |
| 151 | + it('if the platform is null, returns false', () => { |
| 152 | + const result = filterJSFile(file); |
| 153 | + expect(result).toBeFalsy(); |
| 154 | + }); |
| 155 | + it('if the platform is ios, returns true', () => { |
| 156 | + const result = filterJSFile(file, 'ios'); |
| 157 | + expect(result).toBeTruthy(); |
| 158 | + }); |
| 159 | + it('if the platform is android, returns false', () => { |
| 160 | + const result = filterJSFile(file, 'android'); |
| 161 | + expect(result).toBeFalsy(); |
| 162 | + }); |
| 163 | + it('if the platform is windows, returns false', () => { |
| 164 | + const result = filterJSFile(file, 'windows'); |
| 165 | + expect(result).toBeFalsy(); |
| 166 | + }); |
| 167 | + }); |
| 168 | + |
| 169 | + describe('When the file is valid and it is Android specific', () => { |
| 170 | + const file = 'MySampleNativeComponent.android.js'; |
| 171 | + it('if the platform is null, returns false', () => { |
| 172 | + const result = filterJSFile(file); |
| 173 | + expect(result).toBeFalsy(); |
| 174 | + }); |
| 175 | + it('if the platform is ios, returns false', () => { |
| 176 | + const result = filterJSFile(file, 'ios'); |
| 177 | + expect(result).toBeFalsy(); |
| 178 | + }); |
| 179 | + it('if the platform is android, returns true', () => { |
| 180 | + const result = filterJSFile(file, 'android'); |
| 181 | + expect(result).toBeTruthy(); |
| 182 | + }); |
| 183 | + it('if the platform is windows, returns false', () => { |
| 184 | + const result = filterJSFile(file, 'windows'); |
| 185 | + expect(result).toBeFalsy(); |
| 186 | + }); |
| 187 | + }); |
| 188 | + |
| 189 | + describe('When the file is valid and it is Windows specific', () => { |
| 190 | + const file = 'MySampleNativeComponent.windows.js'; |
| 191 | + it('if the platform is null, returns false', () => { |
| 192 | + const result = filterJSFile(file); |
| 193 | + expect(result).toBeFalsy(); |
| 194 | + }); |
| 195 | + it('if the platform is ios, returns false', () => { |
| 196 | + const result = filterJSFile(file, 'ios'); |
| 197 | + expect(result).toBeFalsy(); |
| 198 | + }); |
| 199 | + it('if the platform is android, returns false', () => { |
| 200 | + const result = filterJSFile(file, 'android'); |
| 201 | + expect(result).toBeFalsy(); |
| 202 | + }); |
| 203 | + it('if the platform is windows, returns true', () => { |
| 204 | + const result = filterJSFile(file, 'windows'); |
| 205 | + expect(result).toBeTruthy(); |
| 206 | + }); |
| 207 | + }); |
| 208 | +}); |
0 commit comments