@hot-updater/react-native 1.0.0-rc.17 → 1.0.0-rc.21

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 (240) hide show
  1. package/lib/commonjs/checkForUpdate.js +7 -9
  2. package/lib/commonjs/checkForUpdate.js.map +1 -1
  3. package/lib/commonjs/clientPlugin.js +7 -43
  4. package/lib/commonjs/clientPlugin.js.map +1 -1
  5. package/lib/commonjs/httpClient.js +7 -9
  6. package/lib/commonjs/httpClient.js.map +1 -1
  7. package/lib/commonjs/index.js +10 -0
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/native.js +4 -4
  10. package/lib/commonjs/native.js.map +1 -1
  11. package/lib/commonjs/pluginHost.js +26 -190
  12. package/lib/commonjs/pluginHost.js.map +1 -1
  13. package/lib/commonjs/releaseCatalogCache.js +7 -59
  14. package/lib/commonjs/releaseCatalogCache.js.map +1 -1
  15. package/lib/commonjs/sdkVersion.js +1 -1
  16. package/lib/module/checkForUpdate.js +1 -3
  17. package/lib/module/checkForUpdate.js.map +1 -1
  18. package/lib/module/clientPlugin.js +1 -41
  19. package/lib/module/clientPlugin.js.map +1 -1
  20. package/lib/module/httpClient.js +1 -3
  21. package/lib/module/httpClient.js.map +1 -1
  22. package/lib/module/index.js +2 -0
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/native.js +1 -1
  25. package/lib/module/native.js.map +1 -1
  26. package/lib/module/pluginHost.js +22 -187
  27. package/lib/module/pluginHost.js.map +1 -1
  28. package/lib/module/releaseCatalogCache.js +3 -54
  29. package/lib/module/releaseCatalogCache.js.map +1 -1
  30. package/lib/module/sdkVersion.js +1 -1
  31. package/lib/typescript/commonjs/checkForUpdate.d.ts.map +1 -1
  32. package/lib/typescript/commonjs/clientPlugin.d.ts +1 -184
  33. package/lib/typescript/commonjs/clientPlugin.d.ts.map +1 -1
  34. package/lib/typescript/commonjs/httpClient.d.ts +1 -2
  35. package/lib/typescript/commonjs/httpClient.d.ts.map +1 -1
  36. package/lib/typescript/commonjs/index.d.ts +1 -0
  37. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  38. package/lib/typescript/commonjs/native.d.ts +1 -1
  39. package/lib/typescript/commonjs/native.d.ts.map +1 -1
  40. package/lib/typescript/commonjs/pluginHost.d.ts +3 -28
  41. package/lib/typescript/commonjs/pluginHost.d.ts.map +1 -1
  42. package/lib/typescript/commonjs/releaseCatalogCache.d.ts +1 -13
  43. package/lib/typescript/commonjs/releaseCatalogCache.d.ts.map +1 -1
  44. package/lib/typescript/commonjs/sdkVersion.d.ts +1 -1
  45. package/lib/typescript/commonjs/types.d.ts +1 -1
  46. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  47. package/lib/typescript/commonjs/wrap.types.d.ts +2 -2
  48. package/lib/typescript/module/checkForUpdate.d.ts.map +1 -1
  49. package/lib/typescript/module/clientPlugin.d.ts +1 -184
  50. package/lib/typescript/module/clientPlugin.d.ts.map +1 -1
  51. package/lib/typescript/module/httpClient.d.ts +1 -2
  52. package/lib/typescript/module/httpClient.d.ts.map +1 -1
  53. package/lib/typescript/module/index.d.ts +1 -0
  54. package/lib/typescript/module/index.d.ts.map +1 -1
  55. package/lib/typescript/module/native.d.ts +1 -1
  56. package/lib/typescript/module/native.d.ts.map +1 -1
  57. package/lib/typescript/module/pluginHost.d.ts +3 -28
  58. package/lib/typescript/module/pluginHost.d.ts.map +1 -1
  59. package/lib/typescript/module/releaseCatalogCache.d.ts +1 -13
  60. package/lib/typescript/module/releaseCatalogCache.d.ts.map +1 -1
  61. package/lib/typescript/module/sdkVersion.d.ts +1 -1
  62. package/lib/typescript/module/types.d.ts +1 -1
  63. package/lib/typescript/module/types.d.ts.map +1 -1
  64. package/lib/typescript/module/wrap.types.d.ts +2 -2
  65. package/package.json +7 -16
  66. package/src/checkForUpdate.ts +4 -6
  67. package/src/clientPlugin.ts +17 -231
  68. package/src/httpClient.ts +4 -4
  69. package/src/index.ts +7 -0
  70. package/src/native.ts +1 -1
  71. package/src/pluginHost.ts +24 -241
  72. package/src/releaseCatalogCache.ts +7 -136
  73. package/src/sdkVersion.ts +1 -1
  74. package/src/types.ts +1 -1
  75. package/src/wrap.types.ts +2 -2
  76. package/android/src/test/java/com/hotupdater/BsdiffPatchTest.kt +0 -46
  77. package/android/src/test/java/com/hotupdater/BundleFileStorageServiceTest.kt +0 -2236
  78. package/android/src/test/java/com/hotupdater/HotUpdaterExceptionTest.kt +0 -220
  79. package/android/src/test/java/com/hotupdater/HotUpdaterImplTest.kt +0 -264
  80. package/android/src/test/java/com/hotupdater/HotUpdaterRecoveryStateTest.kt +0 -97
  81. package/android/src/test/java/com/hotupdater/InstallIdentityServiceTest.kt +0 -71
  82. package/android/src/test/java/com/hotupdater/KeyValueStorageServiceTest.kt +0 -106
  83. package/android/src/test/java/com/hotupdater/NativeConfigUtilsTest.kt +0 -20
  84. package/android/src/test/java/com/hotupdater/NoBackupContext.kt +0 -11
  85. package/android/src/test/java/com/hotupdater/OkHttpDownloadServiceTest.kt +0 -397
  86. package/android/src/test/java/com/hotupdater/PendingCrashRecoveryTest.kt +0 -44
  87. package/android/src/test/java/com/hotupdater/PreviousProcessExitTest.kt +0 -57
  88. package/android/src/test/java/com/hotupdater/RelativePathResolverTest.kt +0 -41
  89. package/android/src/test/java/com/hotupdater/ReleaseCatalogCacheServiceTest.kt +0 -118
  90. package/android/src/test/java/com/hotupdater/TarBrArchiveExtractorTest.kt +0 -206
  91. package/lib/commonjs/appReady.spec.js +0 -360
  92. package/lib/commonjs/appReady.spec.js.map +0 -1
  93. package/lib/commonjs/appReady.test-utils.js +0 -25
  94. package/lib/commonjs/appReady.test-utils.js.map +0 -1
  95. package/lib/commonjs/baseURL.js +0 -16
  96. package/lib/commonjs/baseURL.js.map +0 -1
  97. package/lib/commonjs/catalogCacheNative.spec.js +0 -31
  98. package/lib/commonjs/catalogCacheNative.spec.js.map +0 -1
  99. package/lib/commonjs/checkForUpdate.releaseCatalog.spec.js +0 -936
  100. package/lib/commonjs/checkForUpdate.releaseCatalog.spec.js.map +0 -1
  101. package/lib/commonjs/entryImportGraph.spec.js +0 -50
  102. package/lib/commonjs/entryImportGraph.spec.js.map +0 -1
  103. package/lib/commonjs/httpClient.spec.js +0 -171
  104. package/lib/commonjs/httpClient.spec.js.map +0 -1
  105. package/lib/commonjs/index.spec.js +0 -395
  106. package/lib/commonjs/index.spec.js.map +0 -1
  107. package/lib/commonjs/iosInterop.spec.js +0 -18
  108. package/lib/commonjs/iosInterop.spec.js.map +0 -1
  109. package/lib/commonjs/native.spec.js +0 -910
  110. package/lib/commonjs/native.spec.js.map +0 -1
  111. package/lib/commonjs/pluginHost.spec.js +0 -292
  112. package/lib/commonjs/pluginHost.spec.js.map +0 -1
  113. package/lib/commonjs/plugins/insights/eventId.js +0 -129
  114. package/lib/commonjs/plugins/insights/eventId.js.map +0 -1
  115. package/lib/commonjs/plugins/insights/eventId.spec.js +0 -47
  116. package/lib/commonjs/plugins/insights/eventId.spec.js.map +0 -1
  117. package/lib/commonjs/plugins/insights/index.js +0 -272
  118. package/lib/commonjs/plugins/insights/index.js.map +0 -1
  119. package/lib/commonjs/plugins/insights/insights.spec.js +0 -640
  120. package/lib/commonjs/plugins/insights/insights.spec.js.map +0 -1
  121. package/lib/commonjs/plugins/insights/sender.js +0 -128
  122. package/lib/commonjs/plugins/insights/sender.js.map +0 -1
  123. package/lib/commonjs/plugins/insights/sender.spec.js +0 -265
  124. package/lib/commonjs/plugins/insights/sender.spec.js.map +0 -1
  125. package/lib/commonjs/plugins/insights/state.js +0 -145
  126. package/lib/commonjs/plugins/insights/state.js.map +0 -1
  127. package/lib/commonjs/releaseCatalogCache.spec.js +0 -213
  128. package/lib/commonjs/releaseCatalogCache.spec.js.map +0 -1
  129. package/lib/commonjs/releaseCatalogCacheNativeContract.spec.js +0 -64
  130. package/lib/commonjs/releaseCatalogCacheNativeContract.spec.js.map +0 -1
  131. package/lib/commonjs/store.notification.spec.js +0 -84
  132. package/lib/commonjs/store.notification.spec.js.map +0 -1
  133. package/lib/commonjs/store.spec.js +0 -182
  134. package/lib/commonjs/store.spec.js.map +0 -1
  135. package/lib/commonjs/updateError.spec.js +0 -149
  136. package/lib/commonjs/updateError.spec.js.map +0 -1
  137. package/lib/commonjs/wrap.progress.spec.js +0 -195
  138. package/lib/commonjs/wrap.progress.spec.js.map +0 -1
  139. package/lib/commonjs/wrap.spec.js +0 -232
  140. package/lib/commonjs/wrap.spec.js.map +0 -1
  141. package/lib/module/appReady.spec.js +0 -359
  142. package/lib/module/appReady.spec.js.map +0 -1
  143. package/lib/module/appReady.test-utils.js +0 -19
  144. package/lib/module/appReady.test-utils.js.map +0 -1
  145. package/lib/module/baseURL.js +0 -11
  146. package/lib/module/baseURL.js.map +0 -1
  147. package/lib/module/catalogCacheNative.spec.js +0 -31
  148. package/lib/module/catalogCacheNative.spec.js.map +0 -1
  149. package/lib/module/checkForUpdate.releaseCatalog.spec.js +0 -935
  150. package/lib/module/checkForUpdate.releaseCatalog.spec.js.map +0 -1
  151. package/lib/module/entryImportGraph.spec.js +0 -50
  152. package/lib/module/entryImportGraph.spec.js.map +0 -1
  153. package/lib/module/httpClient.spec.js +0 -171
  154. package/lib/module/httpClient.spec.js.map +0 -1
  155. package/lib/module/index.spec.js +0 -394
  156. package/lib/module/index.spec.js.map +0 -1
  157. package/lib/module/iosInterop.spec.js +0 -18
  158. package/lib/module/iosInterop.spec.js.map +0 -1
  159. package/lib/module/native.spec.js +0 -909
  160. package/lib/module/native.spec.js.map +0 -1
  161. package/lib/module/pluginHost.spec.js +0 -291
  162. package/lib/module/pluginHost.spec.js.map +0 -1
  163. package/lib/module/plugins/insights/eventId.js +0 -122
  164. package/lib/module/plugins/insights/eventId.js.map +0 -1
  165. package/lib/module/plugins/insights/eventId.spec.js +0 -47
  166. package/lib/module/plugins/insights/eventId.spec.js.map +0 -1
  167. package/lib/module/plugins/insights/index.js +0 -268
  168. package/lib/module/plugins/insights/index.js.map +0 -1
  169. package/lib/module/plugins/insights/insights.spec.js +0 -639
  170. package/lib/module/plugins/insights/insights.spec.js.map +0 -1
  171. package/lib/module/plugins/insights/sender.js +0 -123
  172. package/lib/module/plugins/insights/sender.js.map +0 -1
  173. package/lib/module/plugins/insights/sender.spec.js +0 -265
  174. package/lib/module/plugins/insights/sender.spec.js.map +0 -1
  175. package/lib/module/plugins/insights/state.js +0 -139
  176. package/lib/module/plugins/insights/state.js.map +0 -1
  177. package/lib/module/releaseCatalogCache.spec.js +0 -213
  178. package/lib/module/releaseCatalogCache.spec.js.map +0 -1
  179. package/lib/module/releaseCatalogCacheNativeContract.spec.js +0 -64
  180. package/lib/module/releaseCatalogCacheNativeContract.spec.js.map +0 -1
  181. package/lib/module/store.notification.spec.js +0 -85
  182. package/lib/module/store.notification.spec.js.map +0 -1
  183. package/lib/module/store.spec.js +0 -181
  184. package/lib/module/store.spec.js.map +0 -1
  185. package/lib/module/updateError.spec.js +0 -149
  186. package/lib/module/updateError.spec.js.map +0 -1
  187. package/lib/module/wrap.progress.spec.js +0 -196
  188. package/lib/module/wrap.progress.spec.js.map +0 -1
  189. package/lib/module/wrap.spec.js +0 -233
  190. package/lib/module/wrap.spec.js.map +0 -1
  191. package/lib/typescript/commonjs/appReady.test-utils.d.ts +0 -9
  192. package/lib/typescript/commonjs/appReady.test-utils.d.ts.map +0 -1
  193. package/lib/typescript/commonjs/baseURL.d.ts +0 -4
  194. package/lib/typescript/commonjs/baseURL.d.ts.map +0 -1
  195. package/lib/typescript/commonjs/plugins/insights/eventId.d.ts +0 -18
  196. package/lib/typescript/commonjs/plugins/insights/eventId.d.ts.map +0 -1
  197. package/lib/typescript/commonjs/plugins/insights/index.d.ts +0 -40
  198. package/lib/typescript/commonjs/plugins/insights/index.d.ts.map +0 -1
  199. package/lib/typescript/commonjs/plugins/insights/sender.d.ts +0 -74
  200. package/lib/typescript/commonjs/plugins/insights/sender.d.ts.map +0 -1
  201. package/lib/typescript/commonjs/plugins/insights/state.d.ts +0 -46
  202. package/lib/typescript/commonjs/plugins/insights/state.d.ts.map +0 -1
  203. package/lib/typescript/module/appReady.test-utils.d.ts +0 -9
  204. package/lib/typescript/module/appReady.test-utils.d.ts.map +0 -1
  205. package/lib/typescript/module/baseURL.d.ts +0 -4
  206. package/lib/typescript/module/baseURL.d.ts.map +0 -1
  207. package/lib/typescript/module/plugins/insights/eventId.d.ts +0 -18
  208. package/lib/typescript/module/plugins/insights/eventId.d.ts.map +0 -1
  209. package/lib/typescript/module/plugins/insights/index.d.ts +0 -40
  210. package/lib/typescript/module/plugins/insights/index.d.ts.map +0 -1
  211. package/lib/typescript/module/plugins/insights/sender.d.ts +0 -74
  212. package/lib/typescript/module/plugins/insights/sender.d.ts.map +0 -1
  213. package/lib/typescript/module/plugins/insights/state.d.ts +0 -46
  214. package/lib/typescript/module/plugins/insights/state.d.ts.map +0 -1
  215. package/plugins/insights/package.json +0 -8
  216. package/src/appReady.spec.ts +0 -393
  217. package/src/appReady.test-utils.ts +0 -31
  218. package/src/baseURL.ts +0 -15
  219. package/src/catalogCacheNative.spec.ts +0 -63
  220. package/src/checkForUpdate.releaseCatalog.spec.ts +0 -966
  221. package/src/entryImportGraph.spec.ts +0 -65
  222. package/src/httpClient.spec.ts +0 -216
  223. package/src/index.spec.ts +0 -434
  224. package/src/iosInterop.spec.ts +0 -30
  225. package/src/native.spec.ts +0 -978
  226. package/src/pluginHost.spec.ts +0 -297
  227. package/src/plugins/insights/eventId.spec.ts +0 -60
  228. package/src/plugins/insights/eventId.ts +0 -171
  229. package/src/plugins/insights/index.ts +0 -367
  230. package/src/plugins/insights/insights.spec.ts +0 -732
  231. package/src/plugins/insights/sender.spec.ts +0 -287
  232. package/src/plugins/insights/sender.ts +0 -221
  233. package/src/plugins/insights/state.ts +0 -184
  234. package/src/releaseCatalogCache.spec.ts +0 -304
  235. package/src/releaseCatalogCacheNativeContract.spec.ts +0 -80
  236. package/src/store.notification.spec.ts +0 -102
  237. package/src/store.spec.ts +0 -215
  238. package/src/updateError.spec.ts +0 -144
  239. package/src/wrap.progress.spec.ts +0 -232
  240. package/src/wrap.spec.ts +0 -262
@@ -1,910 +0,0 @@
1
- "use strict";
2
-
3
- var _core = require("@hot-updater/core");
4
- var _vitest = require("vitest");
5
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
6
- const nativeModuleMock = _vitest.vi.hoisted(() => {
7
- const getManifest = _vitest.vi.fn();
8
- const getCrashHistory = _vitest.vi.fn(() => []);
9
- return {
10
- getActiveUpdateState: _vitest.vi.fn(),
11
- clearCrashHistory: _vitest.vi.fn(() => true),
12
- getBaseURL: _vitest.vi.fn(() => null),
13
- getBundleId: _vitest.vi.fn(() => "bundle-id"),
14
- getCohort: _vitest.vi.fn(() => "123"),
15
- getInstallId: _vitest.vi.fn(() => "install-id"),
16
- getStorageItem: _vitest.vi.fn(() => null),
17
- getManifest,
18
- getCrashHistory,
19
- getConstants: _vitest.vi.fn(() => ({
20
- APP_VERSION: null,
21
- CHANNEL: "production",
22
- DEFAULT_CHANNEL: "production",
23
- FINGERPRINT_HASH: null,
24
- MIN_BUNDLE_ID: "min-bundle-id"
25
- })),
26
- notifyAppReady: _vitest.vi.fn(),
27
- reload: _vitest.vi.fn(),
28
- resetChannel: _vitest.vi.fn(),
29
- setCohort: _vitest.vi.fn(),
30
- setStorageItem: _vitest.vi.fn(),
31
- setBundleURL: _vitest.vi.fn(),
32
- switchChannel: _vitest.vi.fn(),
33
- updateBundle: _vitest.vi.fn()
34
- };
35
- });
36
- _vitest.vi.mock("react-native", () => ({
37
- NativeEventEmitter: class {
38
- addListener() {
39
- return {
40
- remove: () => {}
41
- };
42
- }
43
- },
44
- Platform: {
45
- OS: "ios"
46
- }
47
- }));
48
- _vitest.vi.mock("./specs/NativeHotUpdater", () => ({
49
- default: nativeModuleMock
50
- }));
51
- (0, _vitest.describe)("notifyAppReady", () => {
52
- (0, _vitest.beforeEach)(() => {
53
- _vitest.vi.resetModules();
54
- nativeModuleMock.getActiveUpdateState.mockReset();
55
- nativeModuleMock.getActiveUpdateState.mockReturnValue({
56
- activeSelection: null,
57
- stableSelection: null,
58
- verificationPending: false,
59
- highestSeenCatalogs: {}
60
- });
61
- nativeModuleMock.notifyAppReady.mockReset();
62
- nativeModuleMock.getBaseURL.mockReset();
63
- nativeModuleMock.getBundleId.mockReset();
64
- nativeModuleMock.getCrashHistory.mockReset();
65
- nativeModuleMock.getConstants.mockReturnValue({
66
- APP_VERSION: null,
67
- CHANNEL: "production",
68
- DEFAULT_CHANNEL: "production",
69
- FINGERPRINT_HASH: null,
70
- MIN_BUNDLE_ID: "min-bundle-id"
71
- });
72
- nativeModuleMock.getBundleId.mockReturnValue("bundle-id");
73
- nativeModuleMock.getBaseURL.mockReturnValue(null);
74
- nativeModuleMock.getCrashHistory.mockReturnValue([]);
75
- nativeModuleMock.getCohort.mockReset();
76
- nativeModuleMock.getCohort.mockReturnValue("123");
77
- nativeModuleMock.getInstallId.mockReset();
78
- nativeModuleMock.getInstallId.mockReturnValue("install-id");
79
- nativeModuleMock.getManifest.mockReset();
80
- nativeModuleMock.getManifest.mockReturnValue({
81
- assets: {
82
- "index.android.bundle": {
83
- fileHash: "hash-123"
84
- }
85
- },
86
- bundleId: "bundle-id"
87
- });
88
- nativeModuleMock.resetChannel.mockReset();
89
- nativeModuleMock.setCohort.mockReset();
90
- nativeModuleMock.getStorageItem.mockReset();
91
- nativeModuleMock.getStorageItem.mockReturnValue(null);
92
- nativeModuleMock.setStorageItem.mockReset();
93
- nativeModuleMock.updateBundle.mockReset();
94
- });
95
- (0, _vitest.it)("exposes active Release state without internal Catalog identity or history", async () => {
96
- const receipt = {
97
- bundleId: "bundle-123",
98
- releaseId: "release-123",
99
- kind: "BUNDLE",
100
- channel: "production",
101
- catalogId: "private-catalog",
102
- scopeKey: "private-scope",
103
- generation: 10,
104
- catalogHash: "private-hash",
105
- selectionContextHash: "private-context"
106
- };
107
- nativeModuleMock.getActiveUpdateState.mockReturnValue({
108
- activeSelection: receipt,
109
- stableSelection: receipt,
110
- verificationPending: true,
111
- highestSeenCatalogs: {
112
- "private-catalog|private-scope": {
113
- generation: 10,
114
- catalogHash: "private-hash"
115
- }
116
- }
117
- });
118
- const {
119
- getPublicActiveUpdateState
120
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
121
- const selection = {
122
- bundleId: "bundle-123",
123
- releaseId: "release-123",
124
- kind: "BUNDLE",
125
- channel: "production"
126
- };
127
- (0, _vitest.expect)(getPublicActiveUpdateState()).toEqual({
128
- activeSelection: selection,
129
- stableSelection: selection,
130
- verificationPending: true
131
- });
132
- });
133
- (0, _vitest.it)("tracks same-file promotions without changing artifact or crash identities", async () => {
134
- const state = {
135
- activeSelection: {
136
- kind: "BUNDLE",
137
- bundleId: "bundle-123",
138
- releaseId: "release-1"
139
- }
140
- };
141
- nativeModuleMock.getActiveUpdateState.mockImplementation(() => state);
142
- nativeModuleMock.getBundleId.mockReturnValue("bundle-123");
143
- nativeModuleMock.getManifest.mockReturnValue({
144
- assets: {}
145
- });
146
- nativeModuleMock.getCrashHistory.mockReturnValue(["bundle-failed"]);
147
- const {
148
- getUpdateId,
149
- getBundleId,
150
- getManifest,
151
- getCrashHistory
152
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
153
- (0, _vitest.expect)(getUpdateId()).toBe("release-1");
154
- state.activeSelection.releaseId = "release-2";
155
- (0, _vitest.expect)(getUpdateId()).toBe("release-2");
156
- (0, _vitest.expect)(getBundleId()).toBe("bundle-123");
157
- (0, _vitest.expect)(getManifest().bundleId).toBe("bundle-123");
158
- (0, _vitest.expect)(getCrashHistory()).toEqual(["bundle-failed"]);
159
- });
160
- _vitest.it.each([[null, "min-bundle-id"], ["legacy-bundle", "legacy-bundle"]])("preserves the fallback ID for native bundle %s", async (bundleId, expected) => {
161
- nativeModuleMock.getBundleId.mockReturnValue(bundleId);
162
- const {
163
- getUpdateId
164
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
165
- (0, _vitest.expect)(getUpdateId()).toBe(expected);
166
- });
167
- (0, _vitest.it)("reports a staged update while the manifest still identifies the running file", async () => {
168
- const runningSelection = {
169
- kind: "BUNDLE",
170
- bundleId: "running-file",
171
- releaseId: "running-update"
172
- };
173
- const state = {
174
- activeSelection: runningSelection,
175
- stableSelection: runningSelection
176
- };
177
- nativeModuleMock.getActiveUpdateState.mockImplementation(() => state);
178
- nativeModuleMock.getBundleId.mockReturnValue("running-file");
179
- nativeModuleMock.getManifest.mockReturnValue({
180
- assets: {},
181
- bundleId: "running-file"
182
- });
183
- const {
184
- getUpdateId,
185
- getBundleId,
186
- getManifest
187
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
188
- (0, _vitest.expect)(getUpdateId()).toBe("running-update");
189
- state.activeSelection = {
190
- kind: "BUNDLE",
191
- bundleId: "staged-file",
192
- releaseId: "staged-update"
193
- };
194
- (0, _vitest.expect)(getUpdateId()).toBe("staged-update");
195
- (0, _vitest.expect)(getBundleId()).toBe("running-file");
196
- (0, _vitest.expect)(getManifest().bundleId).toBe("running-file");
197
- });
198
- (0, _vitest.it)("reports an explicit built-in rollback by its update ID", async () => {
199
- nativeModuleMock.getActiveUpdateState.mockReturnValue(JSON.stringify({
200
- activeSelection: {
201
- kind: "EMBEDDED",
202
- releaseId: "rollback-1",
203
- bundleId: "min-bundle-id"
204
- }
205
- }));
206
- nativeModuleMock.getBundleId.mockReturnValue(null);
207
- const {
208
- getUpdateId,
209
- getBundleId
210
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
211
- (0, _vitest.expect)(getUpdateId()).toBe("rollback-1");
212
- (0, _vitest.expect)(getBundleId()).toBe("min-bundle-id");
213
- });
214
- (0, _vitest.it)("normalizes legacy PROMOTED launch reports to UPDATE_APPLIED", async () => {
215
- nativeModuleMock.notifyAppReady.mockReturnValue(JSON.stringify({
216
- fromBundleId: "bundle-123",
217
- status: "PROMOTED",
218
- toBundleId: "bundle-456"
219
- }));
220
- const {
221
- notifyAppReady
222
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
223
- (0, _vitest.expect)(notifyAppReady()).toEqual({
224
- fromBundleId: "bundle-123",
225
- status: "UPDATE_APPLIED",
226
- toBundleId: "bundle-456"
227
- });
228
- (0, _vitest.expect)(nativeModuleMock.notifyAppReady).toHaveBeenCalledWith();
229
- });
230
- (0, _vitest.it)("returns RECOVERED launch reports with directional ids", async () => {
231
- nativeModuleMock.notifyAppReady.mockReturnValue({
232
- fromBundleId: "bundle-123",
233
- status: "RECOVERED",
234
- toBundleId: "bundle-122",
235
- updateStrategy: "appVersion"
236
- });
237
- const {
238
- notifyAppReady,
239
- readNotifyAppReady
240
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
241
- (0, _vitest.expect)(notifyAppReady()).toEqual({
242
- fromBundleId: "bundle-123",
243
- status: "RECOVERED",
244
- toBundleId: "bundle-122"
245
- });
246
- (0, _vitest.expect)(readNotifyAppReady()).toEqual({
247
- previousProcessExit: null,
248
- transition: {
249
- fromBundleId: "bundle-123",
250
- fromReleaseId: null,
251
- toBundleId: "bundle-122",
252
- toReleaseId: null,
253
- type: "RECOVERED",
254
- updateStrategy: "appVersion"
255
- },
256
- pending: false,
257
- result: {
258
- fromBundleId: "bundle-123",
259
- status: "RECOVERED",
260
- toBundleId: "bundle-122"
261
- }
262
- });
263
- });
264
- (0, _vitest.it)("returns UNCHANGED for incomplete recovery payloads", async () => {
265
- nativeModuleMock.notifyAppReady.mockReturnValue({
266
- fromBundleId: "bundle-123",
267
- status: "RECOVERED",
268
- toBundleId: null,
269
- updateStrategy: "appVersion"
270
- });
271
- const {
272
- notifyAppReady,
273
- readNotifyAppReady
274
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
275
- (0, _vitest.expect)(notifyAppReady()).toEqual({
276
- status: "UNCHANGED"
277
- });
278
- (0, _vitest.expect)(readNotifyAppReady()).toEqual({
279
- previousProcessExit: null,
280
- transition: null,
281
- pending: false,
282
- result: {
283
- status: "UNCHANGED"
284
- }
285
- });
286
- });
287
- (0, _vitest.it)("returns UNCHANGED when an applied launch report has no bundle ids", async () => {
288
- nativeModuleMock.notifyAppReady.mockReturnValue({
289
- status: "UPDATE_APPLIED"
290
- });
291
- const {
292
- notifyAppReady,
293
- readNotifyAppReady
294
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
295
- (0, _vitest.expect)(notifyAppReady()).toEqual({
296
- status: "UNCHANGED"
297
- });
298
- (0, _vitest.expect)(readNotifyAppReady()).toEqual({
299
- previousProcessExit: null,
300
- transition: null,
301
- pending: false,
302
- result: {
303
- status: "UNCHANGED"
304
- }
305
- });
306
- });
307
- (0, _vitest.it)("normalizes malformed old-arch notifyAppReady payloads to UNCHANGED", async () => {
308
- nativeModuleMock.notifyAppReady.mockReturnValue("{");
309
- const {
310
- notifyAppReady,
311
- readNotifyAppReady
312
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
313
- (0, _vitest.expect)(notifyAppReady()).toEqual({
314
- status: "UNCHANGED"
315
- });
316
- (0, _vitest.expect)(readNotifyAppReady()).toEqual({
317
- previousProcessExit: null,
318
- transition: null,
319
- pending: false,
320
- result: {
321
- status: "UNCHANGED"
322
- }
323
- });
324
- });
325
- (0, _vitest.it)("keeps the internal pending state out of the public result", async () => {
326
- nativeModuleMock.notifyAppReady.mockReturnValue({
327
- status: "PENDING"
328
- });
329
- const {
330
- notifyAppReady,
331
- readNotifyAppReady
332
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
333
- (0, _vitest.expect)(notifyAppReady()).toEqual({
334
- status: "UNCHANGED"
335
- });
336
- (0, _vitest.expect)(readNotifyAppReady()).toEqual({
337
- previousProcessExit: null,
338
- transition: null,
339
- pending: true,
340
- result: {
341
- status: "UNCHANGED"
342
- }
343
- });
344
- });
345
- (0, _vitest.it)("returns the native bundle id when available", async () => {
346
- nativeModuleMock.getBundleId.mockReturnValue("bundle-123");
347
- const {
348
- getBundleId
349
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
350
- (0, _vitest.expect)(getBundleId()).toBe("bundle-123");
351
- });
352
- (0, _vitest.it)("throws when native SDK does not expose getBundleId", async () => {
353
- const nativeModule = nativeModuleMock;
354
- const originalGetBundleId = nativeModule.getBundleId;
355
- nativeModule.getBundleId = null;
356
- try {
357
- const {
358
- getBundleId
359
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
360
- (0, _vitest.expect)(() => getBundleId()).toThrow("Native module is missing 'getBundleId()'");
361
- } finally {
362
- nativeModule.getBundleId = originalGetBundleId;
363
- }
364
- });
365
- (0, _vitest.it)("falls back to MIN_BUNDLE_ID when native reports an empty bundle id", async () => {
366
- nativeModuleMock.getBundleId.mockReturnValue("");
367
- const {
368
- getBundleId
369
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
370
- (0, _vitest.expect)(getBundleId()).toBe("min-bundle-id");
371
- });
372
- (0, _vitest.it)("falls back to MIN_BUNDLE_ID when native bundle id is null", async () => {
373
- nativeModuleMock.getBundleId.mockReturnValue(null);
374
- const {
375
- getBundleId
376
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
377
- (0, _vitest.expect)(getBundleId()).toBe("min-bundle-id");
378
- });
379
- (0, _vitest.it)("falls back to MIN_BUNDLE_ID for legacy NIL_UUID bundle ids", async () => {
380
- nativeModuleMock.getBundleId.mockReturnValue("00000000-0000-0000-0000-000000000000");
381
- const {
382
- getBundleId
383
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
384
- (0, _vitest.expect)(getBundleId()).toBe("min-bundle-id");
385
- });
386
- (0, _vitest.it)("returns manifest from native objects", async () => {
387
- nativeModuleMock.getManifest.mockReturnValue({
388
- assets: {
389
- "assets/logo.png": {
390
- fileHash: "hash-logo",
391
- signature: "sig-logo"
392
- },
393
- "index.android.bundle": {
394
- fileHash: "hash-bundle"
395
- }
396
- },
397
- bundleId: "bundle-123"
398
- });
399
- const {
400
- getManifest
401
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
402
- (0, _vitest.expect)(getManifest()).toEqual({
403
- assets: {
404
- "assets/logo.png": {
405
- fileHash: "hash-logo",
406
- signature: "sig-logo"
407
- },
408
- "index.android.bundle": {
409
- fileHash: "hash-bundle"
410
- }
411
- },
412
- bundleId: "bundle-123"
413
- });
414
- });
415
- (0, _vitest.it)("normalizes legacy manifest asset entries from native objects", async () => {
416
- nativeModuleMock.getManifest.mockReturnValue({
417
- assets: {
418
- "assets/logo.png": "hash-logo"
419
- },
420
- bundleId: "bundle-123"
421
- });
422
- const {
423
- getManifest
424
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
425
- (0, _vitest.expect)(getManifest()).toEqual({
426
- assets: {
427
- "assets/logo.png": {
428
- fileHash: "hash-logo"
429
- }
430
- },
431
- bundleId: "bundle-123"
432
- });
433
- });
434
- (0, _vitest.it)("parses manifest from old-arch JSON payloads", async () => {
435
- nativeModuleMock.getManifest.mockReturnValue(JSON.stringify({
436
- assets: {
437
- "assets/logo.png": {
438
- fileHash: "hash-logo"
439
- }
440
- },
441
- bundleId: "bundle-123"
442
- }));
443
- const {
444
- getManifest
445
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
446
- (0, _vitest.expect)(getManifest()).toEqual({
447
- assets: {
448
- "assets/logo.png": {
449
- fileHash: "hash-logo"
450
- }
451
- },
452
- bundleId: "bundle-123"
453
- });
454
- });
455
- (0, _vitest.it)("normalizes legacy manifest asset entries from old-arch JSON payloads", async () => {
456
- nativeModuleMock.getManifest.mockReturnValue(JSON.stringify({
457
- assets: {
458
- "assets/logo.png": "hash-logo"
459
- },
460
- bundleId: "bundle-123"
461
- }));
462
- const {
463
- getManifest
464
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
465
- (0, _vitest.expect)(getManifest()).toEqual({
466
- assets: {
467
- "assets/logo.png": {
468
- fileHash: "hash-logo"
469
- }
470
- },
471
- bundleId: "bundle-123"
472
- });
473
- });
474
- (0, _vitest.it)("returns an empty-assets manifest for malformed payloads", async () => {
475
- nativeModuleMock.getManifest.mockReturnValue("{");
476
- const {
477
- getManifest
478
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
479
- (0, _vitest.expect)(getManifest()).toEqual({
480
- assets: {},
481
- bundleId: "bundle-id"
482
- });
483
- });
484
- (0, _vitest.it)("caches active bundle getters within a JS runtime", async () => {
485
- nativeModuleMock.getBundleId.mockReturnValue("bundle-123");
486
- nativeModuleMock.getManifest.mockReturnValue({
487
- assets: {
488
- "assets/logo.png": {
489
- fileHash: "hash-logo"
490
- }
491
- },
492
- bundleId: "bundle-123"
493
- });
494
- nativeModuleMock.getBaseURL.mockReturnValue("file:///bundle-123");
495
- const {
496
- getBaseURL,
497
- getBundleId,
498
- getManifest
499
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
500
- (0, _vitest.expect)(getBundleId()).toBe("bundle-123");
501
- (0, _vitest.expect)(getBundleId()).toBe("bundle-123");
502
- (0, _vitest.expect)(nativeModuleMock.getBundleId).toHaveBeenCalledTimes(1);
503
- const firstManifest = getManifest();
504
- firstManifest.assets["assets/logo.png"] = {
505
- fileHash: "mutated-hash"
506
- };
507
- (0, _vitest.expect)(getManifest()).toEqual({
508
- assets: {
509
- "assets/logo.png": {
510
- fileHash: "hash-logo"
511
- }
512
- },
513
- bundleId: "bundle-123"
514
- });
515
- (0, _vitest.expect)(nativeModuleMock.getManifest).toHaveBeenCalledTimes(1);
516
- (0, _vitest.expect)(getBaseURL()).toBe("file:///bundle-123");
517
- (0, _vitest.expect)(getBaseURL()).toBe("file:///bundle-123");
518
- (0, _vitest.expect)(nativeModuleMock.getBaseURL).toHaveBeenCalledTimes(1);
519
- });
520
- (0, _vitest.it)("uses the launched bundle reported by native after updateBundle succeeds", async () => {
521
- nativeModuleMock.getBundleId.mockReturnValue("bundle-123");
522
- nativeModuleMock.getManifest.mockReturnValue({
523
- assets: {},
524
- bundleId: "bundle-123"
525
- });
526
- nativeModuleMock.getBaseURL.mockReturnValue("file:///bundle-123");
527
- nativeModuleMock.updateBundle.mockResolvedValue(true);
528
- const {
529
- getBaseURL,
530
- getBundleId,
531
- getManifest,
532
- updateBundle
533
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
534
- (0, _vitest.expect)(getBundleId()).toBe("bundle-123");
535
- (0, _vitest.expect)(getManifest()).toEqual({
536
- assets: {},
537
- bundleId: "bundle-123"
538
- });
539
- (0, _vitest.expect)(getBaseURL()).toBe("file:///bundle-123");
540
- await updateBundle({
541
- assets: {},
542
- bundleId: "bundle-456",
543
- archiveUrl: "https://example.com/bundle.tar.br",
544
- manifestFileHash: "manifest-hash",
545
- manifestUrl: "https://example.com/manifest.json",
546
- status: "UPDATE"
547
- });
548
- (0, _vitest.expect)(getBundleId()).toBe("bundle-123");
549
- (0, _vitest.expect)(nativeModuleMock.updateBundle).toHaveBeenCalledWith(_vitest.expect.objectContaining({
550
- archiveUrl: "https://example.com/bundle.tar.br"
551
- }));
552
- (0, _vitest.expect)(getManifest()).toEqual({
553
- assets: {},
554
- bundleId: "bundle-123"
555
- });
556
- (0, _vitest.expect)(getBaseURL()).toBe("file:///bundle-123");
557
- (0, _vitest.expect)(nativeModuleMock.getBundleId).toHaveBeenCalledTimes(3);
558
- (0, _vitest.expect)(nativeModuleMock.getManifest).toHaveBeenCalledTimes(2);
559
- (0, _vitest.expect)(nativeModuleMock.getBaseURL).toHaveBeenCalledTimes(2);
560
- });
561
- (0, _vitest.it)("reinstalls a session-installed bundle after native resets to built-in", async () => {
562
- nativeModuleMock.getConstants.mockReturnValue({
563
- APP_VERSION: null,
564
- CHANNEL: "production",
565
- DEFAULT_CHANNEL: "production",
566
- FINGERPRINT_HASH: null,
567
- MIN_BUNDLE_ID: "00000000-0000-0000-0000-000000000001"
568
- });
569
- nativeModuleMock.getBundleId.mockReturnValue("00000000-0000-0000-0000-000000000002");
570
- nativeModuleMock.updateBundle.mockResolvedValue(true);
571
- const {
572
- getBundleId,
573
- updateBundle
574
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
575
- await updateBundle({
576
- assets: {},
577
- bundleId: "00000000-0000-0000-0000-000000000003",
578
- manifestFileHash: "manifest-hash",
579
- manifestUrl: "https://example.com/manifest.json",
580
- status: "UPDATE"
581
- });
582
- nativeModuleMock.getBundleId.mockReturnValue("00000000-0000-0000-0000-000000000003");
583
- (0, _vitest.expect)(getBundleId()).toBe("00000000-0000-0000-0000-000000000003");
584
- nativeModuleMock.getBundleId.mockReturnValue(null);
585
- await (0, _vitest.expect)(updateBundle({
586
- assets: {},
587
- bundleId: "00000000-0000-0000-0000-000000000003",
588
- manifestFileHash: "manifest-hash",
589
- manifestUrl: "https://example.com/manifest.json",
590
- status: "UPDATE"
591
- })).resolves.toBe(true);
592
- (0, _vitest.expect)(nativeModuleMock.updateBundle).toHaveBeenCalledTimes(2);
593
- });
594
- (0, _vitest.it)("skips a session-installed bundle when native still reports it active", async () => {
595
- nativeModuleMock.getConstants.mockReturnValue({
596
- APP_VERSION: null,
597
- CHANNEL: "production",
598
- DEFAULT_CHANNEL: "production",
599
- FINGERPRINT_HASH: null,
600
- MIN_BUNDLE_ID: "00000000-0000-0000-0000-000000000001"
601
- });
602
- nativeModuleMock.getBundleId.mockReturnValue("00000000-0000-0000-0000-000000000002");
603
- nativeModuleMock.updateBundle.mockResolvedValue(true);
604
- const {
605
- updateBundle
606
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
607
- await updateBundle({
608
- assets: {},
609
- bundleId: "00000000-0000-0000-0000-000000000003",
610
- manifestFileHash: "manifest-hash",
611
- manifestUrl: "https://example.com/manifest.json",
612
- status: "UPDATE"
613
- });
614
- nativeModuleMock.getBundleId.mockReturnValue("00000000-0000-0000-0000-000000000003");
615
- await (0, _vitest.expect)(updateBundle({
616
- assets: {},
617
- bundleId: "00000000-0000-0000-0000-000000000003",
618
- manifestFileHash: "manifest-hash",
619
- manifestUrl: "https://example.com/manifest.json",
620
- status: "UPDATE"
621
- })).resolves.toBe(true);
622
- (0, _vitest.expect)(nativeModuleMock.updateBundle).toHaveBeenCalledTimes(1);
623
- });
624
- (0, _vitest.it)("forwards manifest artifact parameters to native updateBundle", async () => {
625
- nativeModuleMock.getBundleId.mockReturnValue("bundle-123");
626
- nativeModuleMock.updateBundle.mockResolvedValue(true);
627
- const {
628
- updateBundle
629
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
630
- await updateBundle({
631
- bundleId: "bundle-789",
632
- assets: {
633
- "index.ios.bundle": {
634
- file: {
635
- compression: "br",
636
- url: "https://example.com/files/index.ios.bundle.br"
637
- },
638
- fileHash: "hash-next",
639
- patch: {
640
- algorithm: "bsdiff",
641
- baseBundleId: "bundle-123",
642
- baseFileHash: "hash-prev",
643
- patchFileHash: "hash-patch",
644
- patchUrl: "https://example.com/files/index.ios.bundle.bsdiff"
645
- }
646
- }
647
- },
648
- manifestFileHash: "sig:manifest",
649
- manifestUrl: "https://example.com/manifest.json",
650
- status: "UPDATE"
651
- });
652
- (0, _vitest.expect)(nativeModuleMock.updateBundle).toHaveBeenCalledWith({
653
- bundleId: "bundle-789",
654
- assets: {
655
- "index.ios.bundle": {
656
- file: {
657
- compression: "br",
658
- url: "https://example.com/files/index.ios.bundle.br"
659
- },
660
- fileHash: "hash-next",
661
- patch: {
662
- algorithm: "bsdiff",
663
- baseBundleId: "bundle-123",
664
- baseFileHash: "hash-prev",
665
- patchFileHash: "hash-patch",
666
- patchUrl: "https://example.com/files/index.ios.bundle.bsdiff"
667
- }
668
- }
669
- },
670
- channel: undefined,
671
- manifestFileHash: "sig:manifest",
672
- manifestUrl: "https://example.com/manifest.json"
673
- });
674
- });
675
- (0, _vitest.it)("resolves how native delivered a staged bundle", async () => {
676
- nativeModuleMock.getBundleId.mockReturnValue("bundle-123");
677
- nativeModuleMock.updateBundle.mockResolvedValue({
678
- delivery: "patch",
679
- patchFallback: true
680
- });
681
- const {
682
- stageBundle,
683
- updateBundle
684
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
685
- const params = {
686
- assets: {},
687
- bundleId: "bundle-789",
688
- manifestFileHash: "sig:manifest",
689
- manifestUrl: "https://example.com/manifest.json",
690
- status: "UPDATE"
691
- };
692
- await (0, _vitest.expect)(stageBundle(params)).resolves.toEqual({
693
- delivery: "patch",
694
- patchFallback: true
695
- });
696
- // Native still reports bundle-123, so the same bundle downloads again.
697
- await (0, _vitest.expect)(updateBundle(params)).resolves.toBe(true);
698
- nativeModuleMock.getBundleId.mockReturnValue("bundle-789");
699
- // Now native reports it: this runtime already staged it.
700
- await (0, _vitest.expect)(stageBundle(params)).resolves.toBeNull();
701
- (0, _vitest.expect)(nativeModuleMock.updateBundle).toHaveBeenCalledTimes(2);
702
- });
703
- (0, _vitest.it)("passes on why the previous process exited from the launch report", async () => {
704
- nativeModuleMock.notifyAppReady.mockReturnValue({
705
- previousProcessExit: "LOW_MEMORY",
706
- status: "UNCHANGED"
707
- });
708
- const {
709
- readNotifyAppReady
710
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
711
- (0, _vitest.expect)(readNotifyAppReady()).toEqual({
712
- previousProcessExit: "LOW_MEMORY",
713
- transition: null,
714
- pending: false,
715
- result: {
716
- status: "UNCHANGED"
717
- }
718
- });
719
- });
720
- (0, _vitest.it)("invalidates cached bundle getters after resetChannel succeeds", async () => {
721
- nativeModuleMock.getConstants.mockReturnValue({
722
- APP_VERSION: null,
723
- CHANNEL: "beta",
724
- DEFAULT_CHANNEL: "production",
725
- FINGERPRINT_HASH: null,
726
- MIN_BUNDLE_ID: "min-bundle-id"
727
- });
728
- nativeModuleMock.getBundleId.mockReturnValue("bundle-beta");
729
- nativeModuleMock.getManifest.mockReturnValue({
730
- assets: {},
731
- bundleId: "bundle-beta"
732
- });
733
- nativeModuleMock.getBaseURL.mockReturnValue("file:///bundle-beta");
734
- nativeModuleMock.resetChannel.mockResolvedValue(true);
735
- const {
736
- getBaseURL,
737
- getBundleId,
738
- getManifest,
739
- resetChannel
740
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
741
- (0, _vitest.expect)(getBundleId()).toBe("bundle-beta");
742
- (0, _vitest.expect)(getManifest()).toEqual({
743
- assets: {},
744
- bundleId: "bundle-beta"
745
- });
746
- (0, _vitest.expect)(getBaseURL()).toBe("file:///bundle-beta");
747
- nativeModuleMock.getBundleId.mockReturnValue(null);
748
- nativeModuleMock.getManifest.mockReturnValue({});
749
- nativeModuleMock.getBaseURL.mockReturnValue("");
750
- await (0, _vitest.expect)(resetChannel()).resolves.toBe(true);
751
- (0, _vitest.expect)(getBundleId()).toBe("min-bundle-id");
752
- (0, _vitest.expect)(getManifest()).toEqual({
753
- assets: {},
754
- bundleId: "min-bundle-id"
755
- });
756
- (0, _vitest.expect)(getBaseURL()).toBeNull();
757
- (0, _vitest.expect)(nativeModuleMock.getBundleId).toHaveBeenCalledTimes(2);
758
- (0, _vitest.expect)(nativeModuleMock.getManifest).toHaveBeenCalledTimes(2);
759
- (0, _vitest.expect)(nativeModuleMock.getBaseURL).toHaveBeenCalledTimes(2);
760
- });
761
- (0, _vitest.it)("delegates resetChannel to native even when exported channel constants already match", async () => {
762
- nativeModuleMock.getConstants.mockReturnValue({
763
- APP_VERSION: null,
764
- CHANNEL: "beta",
765
- DEFAULT_CHANNEL: "beta",
766
- FINGERPRINT_HASH: null,
767
- MIN_BUNDLE_ID: "min-bundle-id"
768
- });
769
- nativeModuleMock.resetChannel.mockResolvedValue(true);
770
- const {
771
- resetChannel
772
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
773
- await (0, _vitest.expect)(resetChannel()).resolves.toBe(true);
774
- (0, _vitest.expect)(nativeModuleMock.resetChannel).toHaveBeenCalledTimes(1);
775
- });
776
- (0, _vitest.it)("parses crash history from legacy JSON payloads", async () => {
777
- nativeModuleMock.getCrashHistory.mockReturnValue(JSON.stringify(["bundle-1", "bundle-2"]));
778
- const {
779
- getCrashHistory
780
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
781
- (0, _vitest.expect)(getCrashHistory()).toEqual(["bundle-1", "bundle-2"]);
782
- });
783
- (0, _vitest.it)("falls back to an empty crash history for malformed payloads", async () => {
784
- nativeModuleMock.getCrashHistory.mockReturnValue("{");
785
- const {
786
- getCrashHistory
787
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
788
- (0, _vitest.expect)(getCrashHistory()).toEqual([]);
789
- });
790
- (0, _vitest.it)("passes normalized cohort overrides to native", async () => {
791
- const {
792
- setCohort
793
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
794
- setCohort(" QA-Group ");
795
- (0, _vitest.expect)(nativeModuleMock.setCohort).toHaveBeenCalledWith("qa-group");
796
- });
797
- (0, _vitest.it)("returns the most recently set cohort before native reads catch up", async () => {
798
- nativeModuleMock.getCohort.mockReturnValue("123");
799
- const {
800
- getCohort,
801
- setCohort
802
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
803
- setCohort(" QA-Group ");
804
- (0, _vitest.expect)(getCohort()).toBe("qa-group");
805
- (0, _vitest.expect)(nativeModuleMock.getCohort).not.toHaveBeenCalled();
806
- });
807
- (0, _vitest.it)("throws when attempting to clear the cohort with an empty value", async () => {
808
- const {
809
- setCohort
810
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
811
- (0, _vitest.expect)(() => setCohort("")).toThrow(_core.INVALID_COHORT_ERROR_MESSAGE);
812
- (0, _vitest.expect)(nativeModuleMock.setCohort).not.toHaveBeenCalled();
813
- });
814
- (0, _vitest.it)("throws for invalid cohort overrides", async () => {
815
- const {
816
- setCohort
817
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
818
- (0, _vitest.expect)(() => setCohort("Bad Cohort")).toThrow(_core.INVALID_COHORT_ERROR_MESSAGE);
819
- (0, _vitest.expect)(nativeModuleMock.setCohort).not.toHaveBeenCalled();
820
- });
821
- (0, _vitest.it)("throws for cohort overrides longer than the limit", async () => {
822
- const {
823
- setCohort
824
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
825
- (0, _vitest.expect)(() => setCohort("a".repeat(65))).toThrow(_core.INVALID_COHORT_ERROR_MESSAGE);
826
- (0, _vitest.expect)(nativeModuleMock.setCohort).not.toHaveBeenCalled();
827
- });
828
- (0, _vitest.it)("returns the install id reported by native", async () => {
829
- nativeModuleMock.getInstallId.mockReturnValue("install-123");
830
- const {
831
- getInstallId
832
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
833
- (0, _vitest.expect)(getInstallId()).toBe("install-123");
834
- });
835
- (0, _vitest.it)("normalizes an omitted native fingerprint constant to null", async () => {
836
- nativeModuleMock.getConstants.mockReturnValue({
837
- APP_VERSION: null,
838
- CHANNEL: "production",
839
- DEFAULT_CHANNEL: "production",
840
- FINGERPRINT_HASH: undefined,
841
- MIN_BUNDLE_ID: "min-bundle-id"
842
- });
843
- const {
844
- getFingerprintHash
845
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
846
- (0, _vitest.expect)(getFingerprintHash()).toBeNull();
847
- });
848
- (0, _vitest.it)("throws when native SDK does not expose getInstallId", async () => {
849
- const nativeModule = nativeModuleMock;
850
- const originalGetInstallId = nativeModule.getInstallId;
851
- nativeModule.getInstallId = null;
852
- try {
853
- const {
854
- getInstallId
855
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
856
- (0, _vitest.expect)(() => getInstallId()).toThrow("Native module is missing 'getInstallId()'");
857
- } finally {
858
- nativeModule.getInstallId = originalGetInstallId;
859
- }
860
- });
861
- (0, _vitest.it)("reads and writes the native key-value store", async () => {
862
- nativeModuleMock.getStorageItem.mockImplementation(key => key === "plugins/example/state" ? "stored" : null);
863
- const {
864
- getStorageItem,
865
- setStorageItem
866
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
867
- (0, _vitest.expect)(getStorageItem("plugins/example/state")).toBe("stored");
868
- (0, _vitest.expect)(getStorageItem("plugins/example/missing")).toBeNull();
869
- setStorageItem("plugins/example/state", "next");
870
- setStorageItem("plugins/example/state", null);
871
- (0, _vitest.expect)(nativeModuleMock.setStorageItem).toHaveBeenNthCalledWith(1, "plugins/example/state", "next");
872
- (0, _vitest.expect)(nativeModuleMock.setStorageItem).toHaveBeenNthCalledWith(2, "plugins/example/state", null);
873
- });
874
- _vitest.it.each(["getStorageItem", "setStorageItem"])("throws when native SDK does not expose %s", async name => {
875
- const nativeModule = nativeModuleMock;
876
- const original = nativeModule[name];
877
- nativeModule[name] = undefined;
878
- try {
879
- const {
880
- getStorageItem,
881
- setStorageItem
882
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
883
- (0, _vitest.expect)(() => name === "getStorageItem" ? getStorageItem("key") : setStorageItem("key", "value")).toThrow(`Native module is missing '${name}()'`);
884
- } finally {
885
- nativeModule[name] = original;
886
- }
887
- });
888
- (0, _vitest.it)("returns the cohort reported by native", async () => {
889
- nativeModuleMock.getCohort.mockReturnValue("qa-group");
890
- const {
891
- getCohort
892
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
893
- (0, _vitest.expect)(getCohort()).toBe("qa-group");
894
- });
895
- (0, _vitest.it)("normalizes the cohort reported by native", async () => {
896
- nativeModuleMock.getCohort.mockReturnValue(" QA-GROUP ");
897
- const {
898
- getCohort
899
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
900
- (0, _vitest.expect)(getCohort()).toBe("qa-group");
901
- });
902
- (0, _vitest.it)("throws when native reports an invalid cohort", async () => {
903
- nativeModuleMock.getCohort.mockReturnValue("1001");
904
- const {
905
- getCohort
906
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./native")));
907
- (0, _vitest.expect)(() => getCohort()).toThrow(_core.INVALID_COHORT_ERROR_MESSAGE);
908
- });
909
- });
910
- //# sourceMappingURL=native.spec.js.map