expo-modules-core 0.6.5 → 0.9.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 (219) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +1 -1
  3. package/android/ExpoModulesCorePlugin.gradle +15 -0
  4. package/android/build.gradle +31 -15
  5. package/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java +5 -5
  6. package/android/src/main/java/expo/modules/adapters/react/services/UIManagerModuleWrapper.java +13 -0
  7. package/android/src/main/java/expo/modules/core/ViewManager.java +9 -0
  8. package/android/src/main/java/expo/modules/core/interfaces/JavaScriptContextProvider.java +4 -0
  9. package/android/src/main/java/expo/modules/core/interfaces/ReactActivityHandler.java +37 -1
  10. package/android/src/main/java/expo/modules/core/interfaces/ReactNativeHostHandler.java +30 -0
  11. package/android/src/main/java/expo/modules/core/interfaces/services/UIManager.java +2 -0
  12. package/android/src/main/java/expo/modules/kotlin/AppContext.kt +23 -5
  13. package/android/src/main/java/expo/modules/kotlin/DynamicExtenstions.kt +5 -3
  14. package/android/src/main/java/expo/modules/kotlin/KPromiseWrapper.kt +3 -8
  15. package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +24 -9
  16. package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +12 -7
  17. package/android/src/main/java/expo/modules/kotlin/ModuleRegistry.kt +23 -1
  18. package/android/src/main/java/expo/modules/kotlin/Promise.kt +1 -1
  19. package/android/src/main/java/expo/modules/kotlin/callbacks/Callback.kt +5 -0
  20. package/android/src/main/java/expo/modules/kotlin/callbacks/ViewCallback.kt +39 -0
  21. package/android/src/main/java/expo/modules/kotlin/callbacks/ViewCallbackDelegate.kt +27 -0
  22. package/android/src/main/java/expo/modules/kotlin/defaultmodules/ErrorManagerModule.kt +25 -0
  23. package/android/src/main/java/expo/modules/kotlin/events/EventEmitter.kt +13 -0
  24. package/android/src/main/java/expo/modules/kotlin/events/KModuleEventEmitterWrapper.kt +102 -0
  25. package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +93 -9
  26. package/android/src/main/java/expo/modules/kotlin/exception/ExceptionDecorator.kt +11 -0
  27. package/android/src/main/java/expo/modules/kotlin/{methods/AnyMethod.kt → functions/AnyFunction.kt} +18 -18
  28. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunction.kt +15 -0
  29. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +170 -0
  30. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromise.kt +15 -0
  31. package/android/src/main/java/expo/modules/kotlin/functions/AsyncSuspendFunction.kt +36 -0
  32. package/android/src/main/java/expo/modules/kotlin/modules/DefinitionMarker.kt +4 -0
  33. package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +17 -2
  34. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +416 -43
  35. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionData.kt +2 -2
  36. package/android/src/main/java/expo/modules/kotlin/records/FieldValidator.kt +139 -0
  37. package/android/src/main/java/expo/modules/kotlin/records/RecordTypeConverter.kt +71 -15
  38. package/android/src/main/java/expo/modules/kotlin/records/Required.kt +5 -0
  39. package/android/src/main/java/expo/modules/kotlin/records/ValidationBinder.kt +110 -0
  40. package/android/src/main/java/expo/modules/kotlin/records/Validators.kt +61 -0
  41. package/android/src/main/java/expo/modules/kotlin/types/ArrayTypeConverter.kt +11 -5
  42. package/android/src/main/java/expo/modules/kotlin/types/JSTypeConverter.kt +35 -0
  43. package/android/src/main/java/expo/modules/kotlin/types/JSTypeConverterHelper.kt +148 -0
  44. package/android/src/main/java/expo/modules/kotlin/types/ListTypeConverter.kt +10 -4
  45. package/android/src/main/java/expo/modules/kotlin/types/MapTypeConverter.kt +12 -6
  46. package/android/src/main/java/expo/modules/kotlin/types/PairTypeConverter.kt +29 -13
  47. package/android/src/main/java/expo/modules/kotlin/types/TypeConverter.kt +2 -1
  48. package/android/src/main/java/expo/modules/kotlin/types/TypeConverterProvider.kt +9 -1
  49. package/android/src/main/java/expo/modules/kotlin/views/CallbacksDefinition.kt +3 -0
  50. package/android/src/main/java/expo/modules/kotlin/views/GroupViewManagerWrapper.kt +71 -0
  51. package/android/src/main/java/expo/modules/kotlin/views/SimpleViewManagerWrapper.kt +22 -0
  52. package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinition.kt +18 -0
  53. package/android/src/main/java/expo/modules/kotlin/views/ViewGroupDefinitionBuilder.kt +114 -0
  54. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinition.kt +30 -2
  55. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinitionBuilder.kt +81 -2
  56. package/android/src/main/java/expo/modules/kotlin/views/ViewManagerWrapperDelegate.kt +62 -2
  57. package/build/EventEmitter.d.ts +1 -0
  58. package/build/EventEmitter.d.ts.map +1 -0
  59. package/build/NativeModulesProxy.d.ts +1 -0
  60. package/build/NativeModulesProxy.d.ts.map +1 -0
  61. package/build/NativeModulesProxy.native.d.ts +1 -4
  62. package/build/NativeModulesProxy.native.d.ts.map +1 -0
  63. package/build/NativeModulesProxy.native.js +1 -14
  64. package/build/NativeModulesProxy.native.js.map +1 -1
  65. package/build/NativeModulesProxy.types.d.ts +1 -3
  66. package/build/NativeModulesProxy.types.d.ts.map +1 -0
  67. package/build/NativeModulesProxy.types.js.map +1 -1
  68. package/build/NativeViewManagerAdapter.d.ts +1 -0
  69. package/build/NativeViewManagerAdapter.d.ts.map +1 -0
  70. package/build/NativeViewManagerAdapter.native.d.ts +1 -0
  71. package/build/NativeViewManagerAdapter.native.d.ts.map +1 -0
  72. package/build/NativeViewManagerAdapter.native.js +9 -33
  73. package/build/NativeViewManagerAdapter.native.js.map +1 -1
  74. package/build/PermissionsHook.d.ts +1 -0
  75. package/build/PermissionsHook.d.ts.map +1 -0
  76. package/build/PermissionsInterface.d.ts +1 -0
  77. package/build/PermissionsInterface.d.ts.map +1 -0
  78. package/build/Platform.d.ts +1 -0
  79. package/build/Platform.d.ts.map +1 -0
  80. package/build/SyntheticPlatformEmitter.d.ts +1 -0
  81. package/build/SyntheticPlatformEmitter.d.ts.map +1 -0
  82. package/build/SyntheticPlatformEmitter.web.d.ts +1 -0
  83. package/build/SyntheticPlatformEmitter.web.d.ts.map +1 -0
  84. package/build/deprecate.d.ts +1 -0
  85. package/build/deprecate.d.ts.map +1 -0
  86. package/build/environment/browser.d.ts +1 -0
  87. package/build/environment/browser.d.ts.map +1 -0
  88. package/build/environment/browser.web.d.ts +1 -0
  89. package/build/environment/browser.web.d.ts.map +1 -0
  90. package/build/errors/CodedError.d.ts +1 -0
  91. package/build/errors/CodedError.d.ts.map +1 -0
  92. package/build/errors/UnavailabilityError.d.ts +1 -0
  93. package/build/errors/UnavailabilityError.d.ts.map +1 -0
  94. package/build/index.d.ts +3 -0
  95. package/build/index.d.ts.map +1 -0
  96. package/build/index.js +2 -0
  97. package/build/index.js.map +1 -1
  98. package/build/requireNativeModule.d.ts +16 -0
  99. package/build/requireNativeModule.d.ts.map +1 -0
  100. package/build/requireNativeModule.js +18 -0
  101. package/build/requireNativeModule.js.map +1 -0
  102. package/build/sweet/NativeErrorManager.d.ts +3 -0
  103. package/build/sweet/NativeErrorManager.d.ts.map +1 -0
  104. package/build/sweet/NativeErrorManager.js +3 -0
  105. package/build/sweet/NativeErrorManager.js.map +1 -0
  106. package/build/sweet/setUpErrorManager.fx.d.ts +2 -0
  107. package/build/sweet/setUpErrorManager.fx.d.ts.map +1 -0
  108. package/build/sweet/setUpErrorManager.fx.js +11 -0
  109. package/build/sweet/setUpErrorManager.fx.js.map +1 -0
  110. package/ios/AppDelegates/EXAppDelegatesLoader.m +4 -8
  111. package/ios/AppDelegates/ExpoAppDelegate.swift +22 -20
  112. package/ios/EXAppDefines.h +1 -0
  113. package/ios/EXAppDefines.m +6 -0
  114. package/ios/EXUtilities.h +2 -0
  115. package/ios/EXUtilities.m +12 -0
  116. package/ios/ExpoModulesCore.h +4 -0
  117. package/ios/ExpoModulesCore.podspec +4 -2
  118. package/ios/Interfaces/FileSystem/EXFileSystemInterface.h +1 -1
  119. package/ios/Interfaces/TaskManager/EXTaskServiceInterface.h +1 -0
  120. package/ios/JSI/{JSIConversions.h → EXJSIConversions.h} +5 -0
  121. package/ios/JSI/{JSIConversions.mm → EXJSIConversions.mm} +21 -1
  122. package/ios/JSI/{JSIInstaller.h → EXJSIInstaller.h} +10 -0
  123. package/ios/JSI/EXJSIInstaller.mm +17 -0
  124. package/ios/JSI/EXJSIUtils.h +19 -0
  125. package/ios/JSI/EXJSIUtils.mm +89 -0
  126. package/ios/JSI/EXJavaScriptObject.h +97 -0
  127. package/ios/JSI/EXJavaScriptObject.mm +121 -0
  128. package/ios/JSI/EXJavaScriptRuntime.h +73 -0
  129. package/ios/JSI/EXJavaScriptRuntime.mm +153 -0
  130. package/ios/JSI/EXJavaScriptValue.h +57 -0
  131. package/ios/JSI/EXJavaScriptValue.mm +166 -0
  132. package/ios/JSI/ExpoModulesHostObject.h +33 -0
  133. package/ios/JSI/ExpoModulesHostObject.mm +41 -0
  134. package/ios/JSI/JavaScriptRuntime.swift +32 -0
  135. package/ios/JSI/JavaScriptValue.swift +94 -0
  136. package/ios/ModuleRegistryAdapter/EXModuleRegistryAdapter.m +3 -23
  137. package/ios/NativeModulesProxy/EXNativeModulesProxy.h +2 -2
  138. package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +101 -75
  139. package/ios/RCTComponentData+Privates.h +12 -0
  140. package/ios/ReactDelegates/EXReactCompatibleHelpers.h +18 -0
  141. package/ios/ReactDelegates/EXReactCompatibleHelpers.m +19 -0
  142. package/ios/ReactDelegates/ExpoReactDelegate.swift +3 -3
  143. package/ios/ReactDelegates/ExpoReactDelegateHandler.swift +4 -4
  144. package/ios/ReactDelegates/ModulePriorities.swift +1 -1
  145. package/ios/Swift/AppContext.swift +57 -4
  146. package/ios/Swift/Arguments/AnyArgumentType.swift +1 -1
  147. package/ios/Swift/Arguments/ArgumentType.swift +4 -0
  148. package/ios/Swift/Arguments/Convertibles.swift +13 -13
  149. package/ios/Swift/Arguments/Types/EnumArgumentType.swift +11 -17
  150. package/ios/Swift/Arguments/Types/PromiseArgumentType.swift +1 -1
  151. package/ios/Swift/Arguments/Types/RawArgumentType.swift +2 -2
  152. package/ios/Swift/Conversions.swift +51 -56
  153. package/ios/Swift/EventListener.swift +8 -10
  154. package/ios/Swift/Events/Callback.swift +66 -0
  155. package/ios/Swift/Events/Event.swift +43 -0
  156. package/ios/Swift/Exceptions/ChainableException.swift +51 -0
  157. package/ios/Swift/{CodedError.swift → Exceptions/CodedError.swift} +1 -12
  158. package/ios/Swift/Exceptions/Exception.swift +62 -0
  159. package/ios/Swift/Exceptions/ExceptionOrigin.swift +28 -0
  160. package/ios/Swift/Exceptions/GenericException.swift +20 -0
  161. package/ios/Swift/Exceptions/UnexpectedException.swift +16 -0
  162. package/ios/Swift/Functions/AnyFunction.swift +16 -1
  163. package/ios/Swift/Functions/AsyncFunctionComponent.swift +182 -0
  164. package/ios/Swift/Functions/ConcreteFunction.swift +52 -59
  165. package/ios/Swift/Functions/SyncFunctionComponent.swift +181 -0
  166. package/ios/Swift/JavaScriptUtils.swift +99 -0
  167. package/ios/Swift/ModuleHolder.swift +69 -18
  168. package/ios/Swift/ModuleRegistry.swift +4 -1
  169. package/ios/Swift/Modules/AnyModule.swift +0 -1
  170. package/ios/Swift/Modules/ModuleDefinition.swift +4 -13
  171. package/ios/Swift/Modules/ModuleDefinitionBuilder.swift +0 -1
  172. package/ios/Swift/Modules/ModuleDefinitionComponents.swift +54 -220
  173. package/ios/Swift/ModulesProvider.swift +3 -11
  174. package/ios/Swift/Objects/ObjectDefinition.swift +30 -0
  175. package/ios/Swift/Objects/ObjectDefinitionComponents.swift +257 -0
  176. package/ios/Swift/Promise.swift +8 -3
  177. package/ios/Swift/Records/AnyField.swift +7 -0
  178. package/ios/Swift/Records/Field.swift +24 -19
  179. package/ios/Swift/Records/FieldOption.swift +1 -1
  180. package/ios/Swift/Records/Record.swift +12 -4
  181. package/ios/Swift/SwiftInteropBridge.swift +53 -15
  182. package/ios/Swift/Views/AnyViewProp.swift +1 -1
  183. package/ios/Swift/Views/ComponentData.swift +96 -0
  184. package/ios/Swift/Views/ConcreteViewProp.swift +6 -8
  185. package/ios/Swift/Views/ExpoView.swift +8 -0
  186. package/ios/Swift/Views/ViewFactory.swift +1 -1
  187. package/ios/Swift/Views/ViewManagerDefinition.swift +23 -2
  188. package/ios/Swift/Views/ViewManagerDefinitionBuilder.swift +0 -1
  189. package/ios/Swift/Views/ViewManagerDefinitionComponents.swift +49 -0
  190. package/ios/Swift/Views/ViewModuleWrapper.swift +5 -2
  191. package/ios/Swift.h +5 -0
  192. package/ios/Tests/ArgumentTypeSpec.swift +5 -7
  193. package/ios/Tests/ConstantsSpec.swift +6 -7
  194. package/ios/Tests/ConvertiblesSpec.swift +35 -36
  195. package/ios/Tests/ExceptionsSpec.swift +111 -0
  196. package/ios/Tests/ExpoModulesSpec.swift +75 -0
  197. package/ios/Tests/FunctionSpec.swift +21 -25
  198. package/ios/Tests/FunctionWithConvertiblesSpec.swift +4 -5
  199. package/ios/Tests/JavaScriptObjectSpec.swift +97 -0
  200. package/ios/Tests/JavaScriptRuntimeSpec.swift +94 -0
  201. package/ios/Tests/Mocks/ModuleMocks.swift +1 -1
  202. package/ios/Tests/Mocks/ModulesProviderMock.swift +0 -1
  203. package/ios/Tests/ModuleEventListenersSpec.swift +16 -17
  204. package/ios/Tests/ModuleRegistrySpec.swift +2 -3
  205. package/ios/Tests/RecordSpec.swift +9 -20
  206. package/package.json +3 -3
  207. package/src/NativeModulesProxy.native.ts +2 -22
  208. package/src/NativeModulesProxy.types.ts +0 -8
  209. package/src/NativeViewManagerAdapter.native.tsx +12 -28
  210. package/src/index.ts +4 -0
  211. package/src/requireNativeModule.ts +29 -0
  212. package/src/sweet/NativeErrorManager.ts +2 -0
  213. package/src/sweet/setUpErrorManager.fx.ts +12 -0
  214. package/android/src/main/java/expo/modules/kotlin/events/KEventEmitterWrapper.kt +0 -26
  215. package/android/src/main/java/expo/modules/kotlin/methods/Method.kt +0 -14
  216. package/android/src/main/java/expo/modules/kotlin/methods/PromiseMethod.kt +0 -15
  217. package/ios/JSI/ExpoModulesProxySpec.h +0 -24
  218. package/ios/JSI/ExpoModulesProxySpec.mm +0 -135
  219. package/ios/JSI/JSIInstaller.mm +0 -22
@@ -0,0 +1,75 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesTestCore
4
+
5
+ @testable import ExpoModulesCore
6
+
7
+ class ExpoModulesSpec: ExpoSpec {
8
+ override func spec() {
9
+ let appContext = AppContext.create()
10
+ let interopBridge = SwiftInteropBridge(appContext: appContext)
11
+ let runtime = appContext.runtime
12
+ let testModuleName = "TestModule"
13
+ let testFunctionName = "testFunction"
14
+ let constantsDict: [String: Any] = [
15
+ "expo": "is cool",
16
+ "sdk": 45,
17
+ ]
18
+
19
+ beforeSuite {
20
+ try! appContext.installExpoModulesHostObject(interopBridge)
21
+
22
+ appContext.moduleRegistry.register(holder: mockModuleHolder(appContext) {
23
+ Name(testModuleName)
24
+
25
+ Constants(constantsDict)
26
+
27
+ Function(testFunctionName) { Double.pi }
28
+ })
29
+ }
30
+
31
+ describe("host object") {
32
+ it("is defined") {
33
+ expect(try! runtime?.eval("'ExpoModules' in this").asBool()) === true
34
+ }
35
+
36
+ it("has native module defined") {
37
+ expect(try! runtime?.eval("'\(testModuleName)' in ExpoModules").asBool()) === true
38
+ }
39
+
40
+ it("can access native module") {
41
+ let nativeModule = try! runtime?.eval("ExpoModules.\(testModuleName)")
42
+ expect(nativeModule?.isUndefined()) == false
43
+ expect(nativeModule?.isObject()) == true
44
+ expect(nativeModule?.getRaw()).notTo(beNil())
45
+ }
46
+
47
+ it("has keys for registered modules") {
48
+ let registeredModuleNames = appContext.moduleRegistry.getModuleNames()
49
+ let keys = try! runtime?.eval("Object.keys(ExpoModules)").asArray().compactMap {
50
+ return try! $0?.asString()
51
+ }
52
+ expect(keys).to(contain(registeredModuleNames))
53
+ }
54
+ }
55
+
56
+ describe("module") {
57
+ it("exposes constants") {
58
+ let dict = try! runtime!.eval("ExpoModules.TestModule").asDict()
59
+
60
+ dict.forEach { (key: String, value: Any) in
61
+ expect(value) === dict[key]!
62
+ }
63
+ }
64
+
65
+ it("has function") {
66
+ expect(try! runtime?.eval("typeof ExpoModules.TestModule.\(testFunctionName)").asString()) == "function"
67
+ expect(try! runtime?.eval("ExpoModules.TestModule.\(testFunctionName)").isFunction()) == true
68
+ }
69
+
70
+ it("calls function") {
71
+ expect(try! runtime?.eval("ExpoModules.TestModule.\(testFunctionName)()").asDouble()) == Double.pi
72
+ }
73
+ }
74
+ }
75
+ }
@@ -1,9 +1,8 @@
1
- import Quick
2
- import Nimble
1
+ import ExpoModulesTestCore
3
2
 
4
3
  @testable import ExpoModulesCore
5
4
 
6
- class FunctionSpec: QuickSpec {
5
+ class FunctionSpec: ExpoSpec {
7
6
  override func spec() {
8
7
  let appContext = AppContext()
9
8
  let functionName = "test function name"
@@ -11,11 +10,11 @@ class FunctionSpec: QuickSpec {
11
10
  func testFunctionReturning<T: Equatable>(value returnValue: T) {
12
11
  waitUntil { done in
13
12
  mockModuleHolder(appContext) {
14
- $0.function(functionName) {
13
+ AsyncFunction(functionName) {
15
14
  return returnValue
16
15
  }
17
16
  }
18
- .call(function: functionName, args: []) { value, error in
17
+ .call(function: functionName, args: []) { value, _ in
19
18
  expect(value).notTo(beNil())
20
19
  expect(value).to(beAKindOf(T.self))
21
20
  expect(value as? T).to(equal(returnValue))
@@ -27,7 +26,7 @@ class FunctionSpec: QuickSpec {
27
26
  it("is called") {
28
27
  waitUntil { done in
29
28
  mockModuleHolder(appContext) {
30
- $0.function(functionName) {
29
+ AsyncFunction(functionName) {
31
30
  done()
32
31
  }
33
32
  }
@@ -42,7 +41,7 @@ class FunctionSpec: QuickSpec {
42
41
  }
43
42
 
44
43
  it("returns int values") {
45
- testFunctionReturning(value: 1234)
44
+ testFunctionReturning(value: 1_234)
46
45
  testFunctionReturning(value: [2, 1, 3, 7])
47
46
  }
48
47
 
@@ -60,7 +59,7 @@ class FunctionSpec: QuickSpec {
60
59
  let str: String? = nil
61
60
 
62
61
  mockModuleHolder(appContext) {
63
- $0.function(functionName) { (a: String?) in
62
+ AsyncFunction(functionName) { (a: String?) in
64
63
  expect(a == nil) == true
65
64
  }
66
65
  }
@@ -71,7 +70,7 @@ class FunctionSpec: QuickSpec {
71
70
  let array: [[String]] = [["expo"]]
72
71
 
73
72
  mockModuleHolder(appContext) {
74
- $0.function(functionName) { (a: [[String]]) in
73
+ AsyncFunction(functionName) { (a: [[String]]) in
75
74
  expect(a.first!.first) == array.first!.first
76
75
  }
77
76
  }
@@ -81,7 +80,7 @@ class FunctionSpec: QuickSpec {
81
80
  describe("converting dicts to records") {
82
81
  struct TestRecord: Record {
83
82
  @Field var property: String = "expo"
84
- @Field var optionalProperty: Int? = nil
83
+ @Field var optionalProperty: Int?
85
84
  @Field("propertyWithCustomKey") var customKeyProperty: String = "expo"
86
85
  }
87
86
  let dict = [
@@ -92,11 +91,11 @@ class FunctionSpec: QuickSpec {
92
91
  it("converts to simple record when passed as an argument") {
93
92
  waitUntil { done in
94
93
  mockModuleHolder(appContext) {
95
- $0.function(functionName) { (a: TestRecord) in
94
+ AsyncFunction(functionName) { (a: TestRecord) in
96
95
  return a.property
97
96
  }
98
97
  }
99
- .call(function: functionName, args: [dict]) { value, error in
98
+ .call(function: functionName, args: [dict]) { value, _ in
100
99
  expect(value).notTo(beNil())
101
100
  expect(value).to(beAKindOf(String.self))
102
101
  expect(value).to(be(dict["property"]))
@@ -108,11 +107,11 @@ class FunctionSpec: QuickSpec {
108
107
  it("converts to record with custom key") {
109
108
  waitUntil { done in
110
109
  mockModuleHolder(appContext) {
111
- $0.function(functionName) { (a: TestRecord) in
110
+ AsyncFunction(functionName) { (a: TestRecord) in
112
111
  return a.customKeyProperty
113
112
  }
114
113
  }
115
- .call(function: functionName, args: [dict]) { value, error in
114
+ .call(function: functionName, args: [dict]) { value, _ in
116
115
  expect(value).notTo(beNil())
117
116
  expect(value).to(beAKindOf(String.self))
118
117
  expect(value).to(be(dict["propertyWithCustomKey"]))
@@ -124,11 +123,11 @@ class FunctionSpec: QuickSpec {
124
123
  it("returns the record back") {
125
124
  waitUntil { done in
126
125
  mockModuleHolder(appContext) {
127
- $0.function(functionName) { (a: TestRecord) in
126
+ AsyncFunction(functionName) { (a: TestRecord) in
128
127
  return a.toDictionary()
129
128
  }
130
129
  }
131
- .call(function: functionName, args: [dict]) { value, error in
130
+ .call(function: functionName, args: [dict]) { value, _ in
132
131
  expect(value).notTo(beNil())
133
132
  expect(value).to(beAKindOf(Record.Dict.self))
134
133
 
@@ -145,16 +144,14 @@ class FunctionSpec: QuickSpec {
145
144
  it("throws when called with more arguments than expected") {
146
145
  waitUntil { done in
147
146
  mockModuleHolder(appContext) {
148
- $0.function(functionName) { (a: Int) in
147
+ AsyncFunction(functionName) { (_: Int) in
149
148
  return "something"
150
149
  }
151
150
  }
152
151
  // Function expects one argument, let's give it more.
153
- .call(function: functionName, args: [1, 2]) { value, error in
152
+ .call(function: functionName, args: [1, 2]) { _, error in
154
153
  expect(error).notTo(beNil())
155
- expect(error).to(beAKindOf(InvalidArgsNumberError.self))
156
- expect(error?.code).to(equal("ERR_INVALID_ARGS_NUMBER"))
157
- expect(error?.description).to(equal(InvalidArgsNumberError(received: 2, expected: 1).description))
154
+ expect(error).to(beAKindOf(InvalidArgsNumberException.self))
158
155
  done()
159
156
  }
160
157
  }
@@ -163,16 +160,15 @@ class FunctionSpec: QuickSpec {
163
160
  it("throws when called with arguments of incompatible types") {
164
161
  waitUntil { done in
165
162
  mockModuleHolder(appContext) {
166
- $0.function(functionName) { (a: String) in
163
+ AsyncFunction(functionName) { (_: String) in
167
164
  return "something"
168
165
  }
169
166
  }
170
167
  // Function expects a string, let's give it a number.
171
168
  .call(function: functionName, args: [1]) { value, error in
172
169
  expect(error).notTo(beNil())
173
- expect(error).to(beAKindOf(Conversions.CastingError<String>.self))
174
- expect(error?.code).to(equal("ERR_CASTING_FAILED"))
175
- expect(error?.description).to(equal(Conversions.CastingError<String>(value: 1).description))
170
+ expect(error).to(beAKindOf(ArgumentCastException.self))
171
+ expect((error as! Exception).isCausedBy(Conversions.CastingException<String>.self)) == true
176
172
  done()
177
173
  }
178
174
  }
@@ -1,12 +1,11 @@
1
1
  // Copyright 2018-present 650 Industries. All rights reserved.
2
2
 
3
3
  import CoreGraphics
4
- import Quick
5
- import Nimble
4
+ import ExpoModulesTestCore
6
5
 
7
6
  @testable import ExpoModulesCore
8
7
 
9
- class FunctionWithConvertiblesSpec: QuickSpec {
8
+ class FunctionWithConvertiblesSpec: ExpoSpec {
10
9
  override func spec() {
11
10
  let appContext = AppContext()
12
11
  let functionName = "function"
@@ -18,7 +17,7 @@ class FunctionWithConvertiblesSpec: QuickSpec {
18
17
  let height = 592.1
19
18
 
20
19
  mockModuleHolder(appContext) {
21
- $0.function(functionName) { (point: CGPoint, size: CGSize, vector: CGVector, rect: CGRect) in
20
+ AsyncFunction(functionName) { (point: CGPoint, size: CGSize, vector: CGVector, rect: CGRect) in
22
21
  expect(point.x) == x
23
22
  expect(point.y) == y
24
23
  expect(size.width) == width
@@ -48,7 +47,7 @@ class FunctionWithConvertiblesSpec: QuickSpec {
48
47
  }
49
48
 
50
49
  mockModuleHolder(appContext) {
51
- $0.function(functionName) { (color1: CGColor, color2: CGColor, color3: CGColor, color4: CGColor) in
50
+ AsyncFunction(functionName) { (color1: CGColor, color2: CGColor, color3: CGColor, color4: CGColor) in
52
51
  testColorComponents(color1, 0x2A, 0x4B, 0x5D, 0xFF)
53
52
  testColorComponents(color2, 0x11, 0xFF, 0x00, 0xDD)
54
53
  testColorComponents(color3, 0x66, 0x00, 0xCC, 0xAA)
@@ -0,0 +1,97 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesTestCore
4
+
5
+ @testable import ExpoModulesCore
6
+
7
+ final class JavaScriptObjectSpec: ExpoSpec {
8
+ override func spec() {
9
+ let runtime = JavaScriptRuntime()
10
+ var object: JavaScriptObject?
11
+
12
+ let key = "expo"
13
+ let value1 = "💙"
14
+ let value2 = "💛"
15
+
16
+ beforeEach {
17
+ object = runtime.createObject()
18
+ }
19
+
20
+ describe("hasProperty") {
21
+ it("returns false when the property is missing") {
22
+ expect(object?.hasProperty(key)) == false
23
+ }
24
+
25
+ it("returns true when the property exists") {
26
+ object?.setProperty(key, value: value1)
27
+ expect(object?.hasProperty(key)) == true
28
+ }
29
+
30
+ it("returns true when the property is explicitly set to undefined") {
31
+ object?.setProperty(key, value: nil)
32
+ expect(object?.hasProperty(key)) == true
33
+ expect(object?.getProperty(key).isUndefined()) == true
34
+ }
35
+ }
36
+
37
+ describe("getProperty") {
38
+ it("returns correct value") {
39
+ object?.setProperty(key, value: value1)
40
+ expect(try! object?.getProperty(key).asString()) == value1
41
+ }
42
+
43
+ it("returns undefined") {
44
+ expect(object?.getProperty("bar").isUndefined()) == true
45
+ }
46
+ }
47
+
48
+ describe("setProperty") {
49
+ it("sets") {
50
+ object?.setProperty(key, value: value1)
51
+ expect(try! object?.getProperty(key).asString()) == value1
52
+ }
53
+
54
+ it("overrides") {
55
+ object?.setProperty(key, value: value1)
56
+ object?.setProperty(key, value: value2)
57
+ expect(try! object?.getProperty(key).asString()) == value2
58
+ }
59
+
60
+ it("unsets") {
61
+ object?.setProperty(key, value: nil)
62
+ expect(object?.getProperty(key).isUndefined()) == true
63
+ }
64
+ }
65
+
66
+ describe("defineProperty") {
67
+ it("defines non-enumerable property") {
68
+ object?.defineProperty(key, value: value1, options: [])
69
+ expect(try! object?.getProperty(key).asString()) == value1
70
+ expect(object?.getPropertyNames()).notTo(contain(key))
71
+ }
72
+
73
+ it("defines enumerable property") {
74
+ // When the property is enumerable, it is listed in the property names
75
+ object?.defineProperty(key, value: value1, options: .enumerable)
76
+ expect(try! object?.getProperty(key).asString()) == value1
77
+ expect(object?.getPropertyNames()).to(contain(key))
78
+ }
79
+
80
+ it("defines configurable property") {
81
+ // Configurable allows to redefine the property
82
+ object?.defineProperty(key, value: value1, options: .configurable)
83
+ expect(try! object?.getProperty(key).asString()) == value1
84
+ object?.defineProperty(key, value: value2, options: [])
85
+ expect(try! object?.getProperty(key).asString()) == value2
86
+ }
87
+
88
+ it("defines writable property") {
89
+ // Writable allows changing the property
90
+ object?.defineProperty(key, value: value1, options: .writable)
91
+ expect(try! object?.getProperty(key).asString()) == value1
92
+ object?.setProperty(key, value: value2)
93
+ expect(try! object?.getProperty(key).asString()) == value2
94
+ }
95
+ }
96
+ }
97
+ }
@@ -0,0 +1,94 @@
1
+ import ExpoModulesTestCore
2
+
3
+ @testable import ExpoModulesCore
4
+
5
+ class JavaScriptRuntimeSpec: ExpoSpec {
6
+ override func spec() {
7
+ let runtime = JavaScriptRuntime()
8
+
9
+ it("has global object accessible") {
10
+ expect(runtime.global) !== nil
11
+ }
12
+
13
+ describe("eval") {
14
+ it("returns undefined") {
15
+ let undefined = try! runtime.eval("undefined")
16
+ expect(undefined.isUndefined()) == true
17
+ expect(undefined.kind) == .undefined
18
+ expect(undefined.isNull()) == false
19
+ expect(undefined.getRaw()).to(beNil())
20
+ }
21
+
22
+ it("returns null") {
23
+ let null = try! runtime.eval("null")
24
+ expect(null.isNull()) == true
25
+ expect(null.kind) == .null
26
+ expect(null.getRaw()).to(beNil())
27
+ }
28
+
29
+ it("returns bool") {
30
+ let boolTrue = try! runtime.eval("true")
31
+ let boolFalse = try! runtime.eval("false")
32
+ expect(boolTrue.isBool()) == true
33
+ expect(boolFalse.isBool()) == true
34
+ expect(boolTrue.kind) == .bool
35
+ expect(boolFalse.kind) == .bool
36
+ expect(try! boolTrue.asBool()) == true
37
+ expect(try! boolFalse.asBool()) == false
38
+ }
39
+
40
+ it("returns number") {
41
+ let number = try! runtime.eval("1.23")
42
+ expect(number.isNumber()) == true
43
+ expect(number.kind) == .number
44
+ expect(try! number.asInt()) == 1
45
+ expect(try! number.asDouble()) == 1.23
46
+ }
47
+
48
+ it("returns string") {
49
+ let string = try! runtime.eval("'foobar'")
50
+ expect(string.isString()) == true
51
+ expect(string.kind) == .string
52
+ expect(try! string.asString()) == "foobar"
53
+ }
54
+
55
+ it("returns array") {
56
+ let array = try! runtime.eval("(['foo', 'bar'])")
57
+ expect(array.isObject()) == true
58
+ expect(array.kind) == .object
59
+ expect(try! array.asArray().map { try $0?.asString() }) == ["foo", "bar"]
60
+ }
61
+
62
+ it("returns dict") {
63
+ let dict1 = try! runtime.eval("({ 'foo': 123 })")
64
+ let dict2 = try! runtime.eval("({ 'foo': 'bar' })")
65
+ expect(dict1.isObject()) == true
66
+ expect(dict2.isObject()) == true
67
+ expect(dict1.kind) == .object
68
+ expect(dict2.kind) == .object
69
+ expect(try! dict1.asDict() as? [String: Int]) == ["foo": 123]
70
+ expect(try! dict2.asDict() as? [String: String]) == ["foo": "bar"]
71
+ }
72
+
73
+ it("returns function") {
74
+ let function = try! runtime.eval("(function() {})")
75
+ expect(function.isObject()) == true
76
+ expect(function.isFunction()) == true
77
+ expect(function.kind) == .function
78
+ }
79
+
80
+ it("returns symbol") {
81
+ let symbol = try! runtime.eval("Symbol('foo')")
82
+ expect(symbol.isSymbol()) == true
83
+ expect(symbol.kind) == .symbol
84
+ }
85
+
86
+ it("throws evaluation exception") {
87
+ expect({ try runtime.eval("foo") }).to(throwError { error in
88
+ expect(error).to(beAKindOf(JavaScriptEvalException.self))
89
+ expect((error as! JavaScriptEvalException).reason).to(contain("Can't find variable: foo"))
90
+ })
91
+ }
92
+ }
93
+ }
94
+ }
@@ -32,7 +32,7 @@ class CustomModule: Module {
32
32
  typealias MockedDefinitionFunc = (CustomModule) -> ModuleDefinition
33
33
 
34
34
  func mockModuleHolder(_ appContext: AppContext, @ModuleDefinitionBuilder _ definitionBody: @escaping () -> ModuleDefinition) -> ModuleHolder {
35
- return ModuleHolder(appContext: appContext, module: CustomModule(appContext: appContext, { module in definitionBody() }))
35
+ return ModuleHolder(appContext: appContext, module: CustomModule(appContext: appContext, { _ in definitionBody() }))
36
36
  }
37
37
 
38
38
  func mockModuleHolder(_ appContext: AppContext, @ModuleDefinitionBuilder _ definitionBody: @escaping (CustomModule) -> ModuleDefinition) -> ModuleHolder {
@@ -3,7 +3,6 @@ import ExpoModulesCore
3
3
  public class ModulesProviderMock: ModulesProvider {
4
4
  public override func getModuleClasses() -> [AnyModule.Type] {
5
5
  return [
6
-
7
6
  ]
8
7
  }
9
8
  }
@@ -1,5 +1,4 @@
1
- import Quick
2
- import Nimble
1
+ import ExpoModulesTestCore
3
2
 
4
3
  @testable import ExpoModulesCore
5
4
 
@@ -11,7 +10,7 @@ import Nimble
11
10
 
12
11
  NOTE: Each test registers the module because only registered modules can capture events.
13
12
  */
14
- class ModuleEventListenersSpec: QuickSpec {
13
+ class ModuleEventListenersSpec: ExpoSpec {
15
14
  override func spec() {
16
15
  var appContext: AppContext!
17
16
 
@@ -19,22 +18,22 @@ class ModuleEventListenersSpec: QuickSpec {
19
18
  appContext = AppContext()
20
19
  }
21
20
 
22
- it("calls onCreate once the module instance is created") {
21
+ it("calls OnCreate once the module instance is created") {
23
22
  waitUntil { done in
24
- let _ = mockModuleHolder(appContext) {
25
- $0.onCreate {
23
+ _ = mockModuleHolder(appContext) {
24
+ OnCreate {
26
25
  done()
27
26
  }
28
27
  }
29
28
  }
30
29
  }
31
30
 
32
- it("calls onDestroy once the module is about to be deallocated") {
31
+ it("calls OnDestroy once the module is about to be deallocated") {
33
32
  waitUntil { done in
34
33
  let moduleName = "mockedModule"
35
34
  let holder = mockModuleHolder(appContext) {
36
- $0.name(moduleName)
37
- $0.onDestroy {
35
+ Name(moduleName)
36
+ OnDestroy {
38
37
  done()
39
38
  }
40
39
  }
@@ -45,10 +44,10 @@ class ModuleEventListenersSpec: QuickSpec {
45
44
  }
46
45
  }
47
46
 
48
- it("calls onAppContextDestroys once the context destroys") {
47
+ it("calls OnAppContextDestroys once the context destroys") {
49
48
  waitUntil { done in
50
49
  let holder = mockModuleHolder(appContext) {
51
- $0.onAppContextDestroys {
50
+ OnAppContextDestroys {
52
51
  done()
53
52
  }
54
53
  }
@@ -70,10 +69,10 @@ class ModuleEventListenersSpec: QuickSpec {
70
69
  }
71
70
  }
72
71
 
73
- it("calls onAppEntersForeground when system's willEnterForegroundNotification is sent") {
72
+ it("calls OnAppEntersForeground when system's willEnterForegroundNotification is sent") {
74
73
  waitUntil { done in
75
74
  let holder = mockModuleHolder(appContext) {
76
- $0.onAppEntersForeground {
75
+ OnAppEntersForeground {
77
76
  done()
78
77
  }
79
78
  }
@@ -82,10 +81,10 @@ class ModuleEventListenersSpec: QuickSpec {
82
81
  }
83
82
  }
84
83
 
85
- it("calls onAppBecomesActive when system's didBecomeActiveNotification is sent") {
84
+ it("calls OnAppBecomesActive when system's didBecomeActiveNotification is sent") {
86
85
  waitUntil { done in
87
86
  let holder = mockModuleHolder(appContext) {
88
- $0.onAppBecomesActive {
87
+ OnAppBecomesActive {
89
88
  done()
90
89
  }
91
90
  }
@@ -94,10 +93,10 @@ class ModuleEventListenersSpec: QuickSpec {
94
93
  }
95
94
  }
96
95
 
97
- it("calls onAppEntersBackground when system's didEnterBackgroundNotification is sent") {
96
+ it("calls OnAppEntersBackground when system's didEnterBackgroundNotification is sent") {
98
97
  waitUntil { done in
99
98
  let holder = mockModuleHolder(appContext) {
100
- $0.onAppEntersBackground {
99
+ OnAppEntersBackground {
101
100
  done()
102
101
  }
103
102
  }
@@ -1,9 +1,8 @@
1
- import Quick
2
- import Nimble
1
+ import ExpoModulesTestCore
3
2
 
4
3
  @testable import ExpoModulesCore
5
4
 
6
- class ModuleRegistrySpec: QuickSpec {
5
+ class ModuleRegistrySpec: ExpoSpec {
7
6
  override func spec() {
8
7
  let appContext = AppContext()
9
8
 
@@ -1,13 +1,12 @@
1
- import Quick
2
- import Nimble
1
+ import ExpoModulesTestCore
3
2
 
4
3
  @testable import ExpoModulesCore
5
4
 
6
- class RecordSpec: QuickSpec {
5
+ class RecordSpec: ExpoSpec {
7
6
  override func spec() {
8
7
  it("initializes with empty dictionary") {
9
8
  struct TestRecord: Record { }
10
- let _ = try TestRecord(from: [:])
9
+ _ = try TestRecord(from: [:])
11
10
  }
12
11
 
13
12
  it("works back and forth with a field") {
@@ -37,14 +36,9 @@ class RecordSpec: QuickSpec {
37
36
  @Field(.required) var a: Int
38
37
  }
39
38
 
40
- do {
41
- let _ = try TestRecord(from: [:])
42
- fail()
43
- } catch let error as CodedError {
44
- expect(error).to(beAKindOf(FieldRequiredError.self))
45
- expect(error.code).to(equal("ERR_FIELD_REQUIRED"))
46
- expect(error.description).to(equal(FieldRequiredError(fieldKey: "a").description))
47
- }
39
+ expect { try TestRecord(from: [:]) }.to(throwError { error in
40
+ expect(error).to(beAKindOf(FieldRequiredException.self))
41
+ })
48
42
  }
49
43
 
50
44
  it("throws when casting is not possible") {
@@ -53,14 +47,9 @@ class RecordSpec: QuickSpec {
53
47
  }
54
48
  let dict = ["a": "try with String instead of Int"]
55
49
 
56
- do {
57
- let _ = try TestRecord(from: dict)
58
- fail()
59
- } catch let error as CodedError {
60
- expect(error).to(beAKindOf(FieldInvalidTypeError.self))
61
- expect(error.code).to(equal("ERR_FIELD_INVALID_TYPE"))
62
- expect(error.description).to(equal(FieldInvalidTypeError(fieldKey: "a", value: dict["a"], desiredType: Int.self).description))
63
- }
50
+ expect { try TestRecord(from: dict) }.to(throwError { error in
51
+ expect(error).to(beAKindOf(FieldInvalidTypeException.self))
52
+ })
64
53
  }
65
54
  }
66
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-modules-core",
3
- "version": "0.6.5",
3
+ "version": "0.9.0",
4
4
  "description": "The core of Expo Modules architecture",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "author": "650 Industries, Inc.",
32
32
  "license": "MIT",
33
- "homepage": "https://github.com/expo/expo/tree/master/packages/expo-modules-core",
33
+ "homepage": "https://github.com/expo/expo/tree/main/packages/expo-modules-core",
34
34
  "jest": {
35
35
  "preset": "expo-module-scripts"
36
36
  },
@@ -42,5 +42,5 @@
42
42
  "@testing-library/react-hooks": "^7.0.1",
43
43
  "expo-module-scripts": "^2.0.0"
44
44
  },
45
- "gitHead": "ba24eba18bf4f4d4b0d54828992d81a2bb18246a"
45
+ "gitHead": "0f796e10a2b2f258c40f9d56aa141c372cd63fc1"
46
46
  }