@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,936 +0,0 @@
1
- "use strict";
2
-
3
- var _core = require("@hot-updater/core");
4
- var _vitest = require("vitest");
5
- var _updateError = require("./updateError.js");
6
- 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); }
7
- const MINIMUM_RELEASE_ID = "00000000-0000-7000-8000-000000000001";
8
- const RELEASE_ID = "00000000-0000-7000-8000-000000000002";
9
- const ACTIVE_RELEASE_ID = "00000000-0000-7000-8000-000000000003";
10
- const CURRENT_BUNDLE_ID = "00000000-0000-7001-8000-000000000001";
11
- const TARGET_BUNDLE_ID = "00000000-0000-7001-8000-000000000002";
12
- const CATALOG_ID = "project-a";
13
- const CHANNEL = "production";
14
- const CATALOG_HASH = `sha256:${"a".repeat(64)}`;
15
- const SCOPE_KEY = (0, _core.createReleaseCatalogScopeKey)({
16
- channelKey: (0, _core.encodeChannelKey)(CHANNEL),
17
- platform: "ios",
18
- strategy: "APP_VERSION"
19
- });
20
- const mocks = _vitest.vi.hoisted(() => {
21
- Reflect.set(globalThis, "HotUpdater", {
22
- SDK_VERSION: "test-sdk-version"
23
- });
24
- return {
25
- addListener: _vitest.vi.fn(() => () => {}),
26
- acceptReleaseCatalog: _vitest.vi.fn(() => true),
27
- commitReleaseSelection: _vitest.vi.fn(async () => true),
28
- getActiveUpdateState: _vitest.vi.fn(() => ({
29
- activeSelection: null,
30
- highestSeenCatalogs: {},
31
- stableSelection: null,
32
- verificationPending: false
33
- })),
34
- getAppVersion: _vitest.vi.fn(() => "1.2"),
35
- getBundleId: _vitest.vi.fn(() => CURRENT_BUNDLE_ID),
36
- getChannel: _vitest.vi.fn(() => CHANNEL),
37
- getCohort: _vitest.vi.fn(() => "123"),
38
- getCrashHistory: _vitest.vi.fn(() => []),
39
- getDefaultChannel: _vitest.vi.fn(() => CHANNEL),
40
- getFingerprintHash: _vitest.vi.fn(() => null),
41
- getInstallId: _vitest.vi.fn(() => "install-id"),
42
- getMinBundleId: _vitest.vi.fn(() => MINIMUM_RELEASE_ID),
43
- isChannelSwitched: _vitest.vi.fn(() => false),
44
- isReleaseSelectionCurrent: _vitest.vi.fn(() => true),
45
- resetChannel: _vitest.vi.fn(),
46
- stageBundle: _vitest.vi.fn(async () => ({
47
- delivery: "manifest",
48
- patchFallback: false
49
- }))
50
- };
51
- });
52
- _vitest.vi.mock("react-native", () => ({
53
- Platform: {
54
- OS: "ios"
55
- }
56
- }));
57
- _vitest.vi.mock("./native", () => mocks);
58
- const createCatalog = (overrides = {}) => ({
59
- catalogId: CATALOG_ID,
60
- catalogHash: CATALOG_HASH,
61
- fallbackPolicy: "BUILTIN_IF_ACTIVE_INELIGIBLE",
62
- generation: 2,
63
- releases: [{
64
- bundleId: TARGET_BUNDLE_ID,
65
- kind: "BUNDLE",
66
- message: "Release two",
67
- releaseId: RELEASE_ID,
68
- rolloutCohortCount: 1000,
69
- shouldForceUpdate: false,
70
- targetCohorts: []
71
- }],
72
- schemaVersion: 1,
73
- scopeKey: SCOPE_KEY,
74
- ...overrides
75
- });
76
- const createClient = (catalog = createCatalog()) => {
77
- const fetchReleaseCatalog = _vitest.vi.fn(async () => catalog);
78
- const artifact = {
79
- artifactProtocolVersion: 1,
80
- assets: {},
81
- manifestFileHash: "manifest-hash",
82
- manifestUrl: "https://updates.example.com/manifest.json",
83
- archiveUrl: "https://updates.example.com/bundle.tar.br"
84
- };
85
- const resolveArtifact = _vitest.vi.fn(async () => artifact);
86
- const session = {
87
- fetchReleaseCatalog,
88
- resolveArtifact
89
- };
90
- const client = {
91
- createSession: _vitest.vi.fn(async () => session)
92
- };
93
- return {
94
- client,
95
- fetchReleaseCatalog,
96
- resolveArtifact
97
- };
98
- };
99
- /** Records what checks report to plugins, in order. */
100
- const recordPluginEvents = async () => {
101
- const {
102
- configurePlugins
103
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./pluginHost")));
104
- const events = [];
105
- configurePlugins([{
106
- id: "recorder",
107
- setup: () => ({
108
- onUpdateCheck: result => {
109
- events.push(["onUpdateCheck", result]);
110
- },
111
- onBundleDownloaded: info => {
112
- events.push(["onBundleDownloaded", info]);
113
- },
114
- onUpdateError: error => {
115
- events.push(["onUpdateError", error]);
116
- }
117
- })
118
- }], {
119
- baseURL: "https://updates.example.com"
120
- });
121
- return events;
122
- };
123
- (0, _vitest.describe)("checkForUpdate Release catalog protocol", () => {
124
- (0, _vitest.beforeEach)(() => {
125
- _vitest.vi.resetModules();
126
- _vitest.vi.clearAllMocks();
127
- _vitest.vi.stubGlobal("__DEV__", false);
128
- mocks.acceptReleaseCatalog.mockReturnValue(true);
129
- mocks.getActiveUpdateState.mockReturnValue({
130
- activeSelection: null,
131
- highestSeenCatalogs: {},
132
- stableSelection: null,
133
- verificationPending: false
134
- });
135
- mocks.isReleaseSelectionCurrent.mockReturnValue(true);
136
- mocks.commitReleaseSelection.mockResolvedValue(true);
137
- mocks.stageBundle.mockResolvedValue({
138
- delivery: "manifest",
139
- patchFallback: false
140
- });
141
- });
142
- (0, _vitest.it)("reports the check, then the download only after staging", async () => {
143
- const {
144
- checkForUpdate
145
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
146
- const events = await recordPluginEvents();
147
- const {
148
- client
149
- } = createClient();
150
- let complete;
151
- mocks.stageBundle.mockImplementationOnce(() => new Promise(resolve => {
152
- complete = resolve;
153
- }));
154
- const update = await checkForUpdate({
155
- client,
156
- updateStrategy: "appVersion"
157
- });
158
- (0, _vitest.expect)(update?.shouldForceUpdate).toBe(false);
159
- (0, _vitest.expect)(events).toEqual([["onUpdateCheck", {
160
- status: "UPDATE_AVAILABLE",
161
- channel: CHANNEL,
162
- fromBundleId: CURRENT_BUNDLE_ID,
163
- fromReleaseId: null,
164
- toBundleId: TARGET_BUNDLE_ID,
165
- toReleaseId: RELEASE_ID,
166
- transitionKind: "INSTALL",
167
- updateStatus: "UPDATE",
168
- shouldForceUpdate: false,
169
- updateStrategy: "appVersion"
170
- }]]);
171
- const pending = update.updateBundle();
172
- await _vitest.vi.waitFor(() => (0, _vitest.expect)(mocks.stageBundle).toHaveBeenCalledOnce());
173
- (0, _vitest.expect)(events).toHaveLength(1);
174
- complete({
175
- delivery: "patch",
176
- patchFallback: true
177
- });
178
- await (0, _vitest.expect)(pending).resolves.toBe(true);
179
- (0, _vitest.expect)(events[1]).toEqual(["onBundleDownloaded", {
180
- channel: CHANNEL,
181
- fromBundleId: CURRENT_BUNDLE_ID,
182
- fromReleaseId: null,
183
- toBundleId: TARGET_BUNDLE_ID,
184
- toReleaseId: RELEASE_ID,
185
- updateStrategy: "appVersion",
186
- delivery: "patch",
187
- patchFallback: true
188
- }]);
189
- });
190
- _vitest.it.each(["nothing new", "failure"])("does not report a download when staging brings %s", async result => {
191
- const {
192
- checkForUpdate
193
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
194
- const events = await recordPluginEvents();
195
- const {
196
- client
197
- } = createClient();
198
- if (result === "nothing new") mocks.stageBundle.mockResolvedValueOnce(null);else mocks.stageBundle.mockRejectedValueOnce(new Error("download failed"));
199
- const update = await checkForUpdate({
200
- client,
201
- updateStrategy: "appVersion"
202
- });
203
- await update.updateBundle().catch(() => false);
204
- (0, _vitest.expect)(events.map(([name]) => name)).not.toContain("onBundleDownloaded");
205
- });
206
- (0, _vitest.it)("selects locally and defers Bundle artifact resolution until install", async () => {
207
- const {
208
- checkForUpdate
209
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
210
- const {
211
- client,
212
- fetchReleaseCatalog,
213
- resolveArtifact
214
- } = createClient();
215
- const result = await checkForUpdate({
216
- client,
217
- updateStrategy: "appVersion"
218
- });
219
- (0, _vitest.expect)(result).toMatchObject({
220
- id: RELEASE_ID,
221
- releaseId: RELEASE_ID,
222
- transitionKind: "INSTALL"
223
- });
224
- (0, _vitest.expect)(fetchReleaseCatalog).toHaveBeenCalledWith({
225
- appVersion: "1.2.0",
226
- channel: CHANNEL,
227
- fingerprintHash: null,
228
- platform: "ios",
229
- requestHeaders: undefined,
230
- requestTimeout: undefined,
231
- updateStrategy: "appVersion"
232
- });
233
- (0, _vitest.expect)(resolveArtifact).not.toHaveBeenCalled();
234
- await (0, _vitest.expect)(result?.updateBundle()).resolves.toBe(true);
235
- (0, _vitest.expect)(resolveArtifact).toHaveBeenCalledWith({
236
- currentBundleId: CURRENT_BUNDLE_ID,
237
- requestHeaders: undefined,
238
- requestTimeout: undefined,
239
- targetBundleId: TARGET_BUNDLE_ID
240
- });
241
- (0, _vitest.expect)(mocks.stageBundle).toHaveBeenCalledWith(_vitest.expect.objectContaining({
242
- bundleId: TARGET_BUNDLE_ID,
243
- archiveUrl: "https://updates.example.com/bundle.tar.br",
244
- selection: _vitest.expect.objectContaining({
245
- catalogId: CATALOG_ID,
246
- releaseId: RELEASE_ID,
247
- scopeKey: SCOPE_KEY
248
- })
249
- }));
250
- });
251
- (0, _vitest.it)("adopts a newer Release for the same Bundle without resolving bytes", async () => {
252
- const active = {
253
- catalogId: CATALOG_ID,
254
- bundleId: TARGET_BUNDLE_ID,
255
- catalogHash: `sha256:${"b".repeat(64)}`,
256
- channel: CHANNEL,
257
- generation: 1,
258
- kind: "BUNDLE",
259
- releaseId: MINIMUM_RELEASE_ID,
260
- scopeKey: SCOPE_KEY,
261
- selectionContextHash: "old-context"
262
- };
263
- mocks.getBundleId.mockReturnValueOnce(TARGET_BUNDLE_ID);
264
- mocks.getActiveUpdateState.mockReturnValueOnce({
265
- activeSelection: active,
266
- highestSeenCatalogs: {},
267
- stableSelection: active,
268
- verificationPending: false
269
- });
270
- const {
271
- checkForUpdate
272
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
273
- const forceCatalog = createCatalog({
274
- releases: [{
275
- ...createCatalog().releases[0],
276
- shouldForceUpdate: true
277
- }]
278
- });
279
- const events = await recordPluginEvents();
280
- const {
281
- client,
282
- resolveArtifact
283
- } = createClient(forceCatalog);
284
- const result = await checkForUpdate({
285
- client,
286
- updateStrategy: "appVersion"
287
- });
288
- (0, _vitest.expect)(result).toMatchObject({
289
- id: RELEASE_ID,
290
- shouldForceUpdate: false,
291
- transitionKind: "ADOPT_RELEASE"
292
- });
293
- await (0, _vitest.expect)(result?.updateBundle()).resolves.toBe(true);
294
- (0, _vitest.expect)(resolveArtifact).not.toHaveBeenCalled();
295
- (0, _vitest.expect)(mocks.stageBundle).not.toHaveBeenCalled();
296
- (0, _vitest.expect)(events.map(([name]) => name)).not.toContain("onBundleDownloaded");
297
- (0, _vitest.expect)(mocks.commitReleaseSelection).toHaveBeenCalledWith({
298
- guard: _vitest.expect.objectContaining({
299
- generation: 2,
300
- scopeKey: SCOPE_KEY
301
- }),
302
- selection: _vitest.expect.objectContaining({
303
- bundleId: TARGET_BUNDLE_ID,
304
- releaseId: RELEASE_ID
305
- })
306
- });
307
- });
308
- (0, _vitest.it)("reports a same-file adoption as UNCHANGED with the adopted Release", async () => {
309
- const active = {
310
- catalogId: CATALOG_ID,
311
- bundleId: TARGET_BUNDLE_ID,
312
- catalogHash: `sha256:${"b".repeat(64)}`,
313
- channel: CHANNEL,
314
- generation: 1,
315
- kind: "BUNDLE",
316
- releaseId: MINIMUM_RELEASE_ID,
317
- scopeKey: SCOPE_KEY,
318
- selectionContextHash: "old-context"
319
- };
320
- mocks.getBundleId.mockReturnValueOnce(TARGET_BUNDLE_ID);
321
- mocks.getActiveUpdateState.mockReturnValueOnce({
322
- activeSelection: active,
323
- highestSeenCatalogs: {},
324
- stableSelection: active,
325
- verificationPending: false
326
- });
327
- const {
328
- checkForUpdate
329
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
330
- const events = await recordPluginEvents();
331
- const {
332
- client
333
- } = createClient();
334
- const result = await checkForUpdate({
335
- client,
336
- updateStrategy: "appVersion"
337
- });
338
- await result?.updateBundle();
339
- (0, _vitest.expect)(events.at(-1)).toEqual(["onUpdateCheck", {
340
- status: "UNCHANGED",
341
- channel: CHANNEL,
342
- bundleId: TARGET_BUNDLE_ID,
343
- releaseId: RELEASE_ID,
344
- previousReleaseId: MINIMUM_RELEASE_ID
345
- }]);
346
- });
347
- (0, _vitest.it)("selects a lower-id Release when explicitly switching scopes", async () => {
348
- const betaChannel = "beta";
349
- const betaScopeKey = (0, _core.createReleaseCatalogScopeKey)({
350
- channelKey: (0, _core.encodeChannelKey)(betaChannel),
351
- platform: "ios",
352
- strategy: "APP_VERSION"
353
- });
354
- const active = {
355
- catalogId: CATALOG_ID,
356
- bundleId: CURRENT_BUNDLE_ID,
357
- catalogHash: `sha256:${"b".repeat(64)}`,
358
- channel: CHANNEL,
359
- generation: 1,
360
- kind: "BUNDLE",
361
- releaseId: ACTIVE_RELEASE_ID,
362
- scopeKey: SCOPE_KEY,
363
- selectionContextHash: "old-context"
364
- };
365
- mocks.getActiveUpdateState.mockReturnValueOnce({
366
- activeSelection: active,
367
- highestSeenCatalogs: {},
368
- stableSelection: active,
369
- verificationPending: false
370
- });
371
- const betaCatalog = createCatalog({
372
- scopeKey: betaScopeKey
373
- });
374
- const {
375
- checkForUpdate
376
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
377
- const {
378
- client
379
- } = createClient(betaCatalog);
380
- const result = await checkForUpdate({
381
- channel: betaChannel,
382
- client,
383
- updateStrategy: "appVersion"
384
- });
385
- (0, _vitest.expect)(result).toMatchObject({
386
- id: RELEASE_ID,
387
- releaseId: RELEASE_ID,
388
- status: "UPDATE",
389
- transitionKind: "INSTALL"
390
- });
391
- });
392
- (0, _vitest.it)("refreshes the same Release receipt when catalog provenance changes", async () => {
393
- const active = {
394
- catalogId: CATALOG_ID,
395
- bundleId: TARGET_BUNDLE_ID,
396
- catalogHash: `sha256:${"b".repeat(64)}`,
397
- channel: CHANNEL,
398
- generation: 1,
399
- kind: "BUNDLE",
400
- releaseId: RELEASE_ID,
401
- scopeKey: SCOPE_KEY,
402
- selectionContextHash: "old-context"
403
- };
404
- mocks.getBundleId.mockReturnValueOnce(TARGET_BUNDLE_ID);
405
- mocks.getActiveUpdateState.mockReturnValueOnce({
406
- activeSelection: active,
407
- highestSeenCatalogs: {},
408
- stableSelection: active,
409
- verificationPending: false
410
- });
411
- const {
412
- checkForUpdate
413
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
414
- const {
415
- client,
416
- resolveArtifact
417
- } = createClient();
418
- const result = await checkForUpdate({
419
- client,
420
- updateStrategy: "appVersion"
421
- });
422
- (0, _vitest.expect)(result).toMatchObject({
423
- id: RELEASE_ID,
424
- releaseId: RELEASE_ID,
425
- transitionKind: "ADOPT_RELEASE"
426
- });
427
- await (0, _vitest.expect)(result?.updateBundle()).resolves.toBe(true);
428
- (0, _vitest.expect)(resolveArtifact).not.toHaveBeenCalled();
429
- (0, _vitest.expect)(mocks.stageBundle).not.toHaveBeenCalled();
430
- (0, _vitest.expect)(mocks.commitReleaseSelection).toHaveBeenCalledWith({
431
- guard: _vitest.expect.objectContaining({
432
- catalogHash: CATALOG_HASH,
433
- generation: 2,
434
- scopeKey: SCOPE_KEY
435
- }),
436
- selection: _vitest.expect.objectContaining({
437
- bundleId: TARGET_BUNDLE_ID,
438
- catalogHash: CATALOG_HASH,
439
- generation: 2,
440
- releaseId: RELEASE_ID
441
- })
442
- });
443
- });
444
- (0, _vitest.it)("rejects a slow artifact completion after a newer catalog wins", async () => {
445
- mocks.isReleaseSelectionCurrent.mockReturnValueOnce(true).mockReturnValueOnce(false);
446
- const {
447
- StaleReleaseCatalogError
448
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./error")));
449
- const {
450
- checkForUpdate
451
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
452
- const {
453
- client
454
- } = createClient();
455
- const result = await checkForUpdate({
456
- client,
457
- updateStrategy: "appVersion"
458
- });
459
- await (0, _vitest.expect)(result?.updateBundle()).rejects.toBeInstanceOf(StaleReleaseCatalogError);
460
- (0, _vitest.expect)(mocks.stageBundle).not.toHaveBeenCalled();
461
- });
462
- (0, _vitest.it)("installs an older enabled Release as a forced rollback", async () => {
463
- const active = {
464
- catalogId: CATALOG_ID,
465
- bundleId: CURRENT_BUNDLE_ID,
466
- catalogHash: `sha256:${"b".repeat(64)}`,
467
- channel: CHANNEL,
468
- generation: 1,
469
- kind: "BUNDLE",
470
- releaseId: ACTIVE_RELEASE_ID,
471
- scopeKey: SCOPE_KEY,
472
- selectionContextHash: "old-context"
473
- };
474
- mocks.getActiveUpdateState.mockReturnValueOnce({
475
- activeSelection: active,
476
- highestSeenCatalogs: {},
477
- stableSelection: active,
478
- verificationPending: false
479
- });
480
- const catalog = createCatalog({
481
- rollbackReleases: [{
482
- bundleId: TARGET_BUNDLE_ID,
483
- kind: "BUNDLE",
484
- message: "Previous Release",
485
- releaseId: RELEASE_ID,
486
- rolloutCohortCount: 0,
487
- shouldForceUpdate: false,
488
- targetCohorts: []
489
- }]
490
- });
491
- const {
492
- checkForUpdate
493
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
494
- const {
495
- client
496
- } = createClient(catalog);
497
- const result = await checkForUpdate({
498
- client,
499
- updateStrategy: "appVersion"
500
- });
501
- (0, _vitest.expect)(result).toMatchObject({
502
- id: RELEASE_ID,
503
- releaseId: RELEASE_ID,
504
- shouldForceUpdate: true,
505
- status: "ROLLBACK",
506
- transitionKind: "INSTALL"
507
- });
508
- await (0, _vitest.expect)(result?.updateBundle()).resolves.toBe(true);
509
- (0, _vitest.expect)(mocks.stageBundle).toHaveBeenCalledWith(_vitest.expect.objectContaining({
510
- bundleId: TARGET_BUNDLE_ID,
511
- status: "ROLLBACK"
512
- }));
513
- });
514
- (0, _vitest.it)("uses current Bundle identity when migrating an unauthenticated receipt", async () => {
515
- const migratedCurrentBundleId = "00000000-0000-7001-8000-000000000003";
516
- const active = {
517
- catalogId: null,
518
- bundleId: migratedCurrentBundleId,
519
- catalogHash: null,
520
- channel: CHANNEL,
521
- generation: null,
522
- kind: "BUNDLE",
523
- releaseId: null,
524
- scopeKey: null,
525
- selectionContextHash: null
526
- };
527
- mocks.getBundleId.mockReturnValueOnce(migratedCurrentBundleId);
528
- mocks.getActiveUpdateState.mockReturnValueOnce({
529
- activeSelection: active,
530
- highestSeenCatalogs: {},
531
- stableSelection: active,
532
- verificationPending: false
533
- });
534
- const catalog = createCatalog({
535
- releases: [],
536
- rollbackReleases: [{
537
- ...createCatalog().releases[0],
538
- rolloutCohortCount: 0
539
- }]
540
- });
541
- const {
542
- checkForUpdate
543
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
544
- const {
545
- client
546
- } = createClient(catalog);
547
- const result = await checkForUpdate({
548
- client,
549
- updateStrategy: "appVersion"
550
- });
551
- (0, _vitest.expect)(result).toMatchObject({
552
- id: RELEASE_ID,
553
- shouldForceUpdate: true,
554
- status: "ROLLBACK",
555
- transitionKind: "INSTALL"
556
- });
557
- });
558
- _vitest.it.each(["EMBEDDED", "BUILTIN"])("returns a forced %s rollback with its console ID or built-in fallback", async kind => {
559
- const active = {
560
- catalogId: CATALOG_ID,
561
- bundleId: CURRENT_BUNDLE_ID,
562
- catalogHash: `sha256:${"b".repeat(64)}`,
563
- channel: CHANNEL,
564
- generation: 1,
565
- kind: "BUNDLE",
566
- releaseId: MINIMUM_RELEASE_ID,
567
- scopeKey: SCOPE_KEY,
568
- selectionContextHash: "old-context"
569
- };
570
- mocks.getActiveUpdateState.mockReturnValueOnce({
571
- activeSelection: active,
572
- highestSeenCatalogs: {},
573
- stableSelection: active,
574
- verificationPending: false
575
- });
576
- const {
577
- checkForUpdate
578
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
579
- const {
580
- client,
581
- resolveArtifact
582
- } = createClient(createCatalog({
583
- releases: kind === "EMBEDDED" ? [{
584
- ...createCatalog().releases[0],
585
- kind,
586
- bundleId: null
587
- }] : [],
588
- rollbackReleases: []
589
- }));
590
- const result = await checkForUpdate({
591
- client,
592
- updateStrategy: "appVersion"
593
- });
594
- (0, _vitest.expect)(result).toMatchObject({
595
- id: kind === "EMBEDDED" ? RELEASE_ID : MINIMUM_RELEASE_ID,
596
- releaseId: kind === "EMBEDDED" ? RELEASE_ID : null,
597
- shouldForceUpdate: true,
598
- status: "ROLLBACK",
599
- transitionKind: kind === "EMBEDDED" ? "USE_EMBEDDED" : "USE_BUILTIN"
600
- });
601
- await (0, _vitest.expect)(result?.updateBundle()).resolves.toBe(true);
602
- (0, _vitest.expect)(mocks.commitReleaseSelection).toHaveBeenCalledWith(_vitest.expect.objectContaining({
603
- selection: _vitest.expect.objectContaining({
604
- bundleId: MINIMUM_RELEASE_ID,
605
- kind,
606
- releaseId: kind === "EMBEDDED" ? RELEASE_ID : null
607
- })
608
- }));
609
- (0, _vitest.expect)(resolveArtifact).not.toHaveBeenCalled();
610
- (0, _vitest.expect)(mocks.stageBundle).not.toHaveBeenCalled();
611
- });
612
- (0, _vitest.it)("does not surface a rollback when the app already uses built-in bytes", async () => {
613
- mocks.getBundleId.mockReturnValueOnce(MINIMUM_RELEASE_ID);
614
- const {
615
- checkForUpdate
616
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
617
- const {
618
- client
619
- } = createClient(createCatalog({
620
- releases: [],
621
- rollbackReleases: []
622
- }));
623
- await (0, _vitest.expect)(checkForUpdate({
624
- client,
625
- updateStrategy: "appVersion"
626
- })).resolves.toBeNull();
627
- (0, _vitest.expect)(mocks.commitReleaseSelection).not.toHaveBeenCalled();
628
- });
629
- (0, _vitest.it)("reports a rejected generation without selecting or resolving artifacts", async () => {
630
- mocks.acceptReleaseCatalog.mockReturnValueOnce(false);
631
- const onError = _vitest.vi.fn();
632
- const {
633
- checkForUpdate
634
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
635
- const {
636
- client,
637
- resolveArtifact
638
- } = createClient();
639
- await (0, _vitest.expect)(checkForUpdate({
640
- client,
641
- onError,
642
- updateStrategy: "appVersion"
643
- })).resolves.toBeNull();
644
- (0, _vitest.expect)(onError).toHaveBeenCalledWith(_vitest.expect.objectContaining({
645
- message: "Rejected a stale or inconsistent Release catalog"
646
- }));
647
- (0, _vitest.expect)(resolveArtifact).not.toHaveBeenCalled();
648
- });
649
- (0, _vitest.it)("rejects mismatched catalog scope before native catalog state mutates", async () => {
650
- const wrongScope = (0, _core.createReleaseCatalogScopeKey)({
651
- channelKey: (0, _core.encodeChannelKey)("beta"),
652
- platform: "ios",
653
- strategy: "APP_VERSION"
654
- });
655
- const onError = _vitest.vi.fn();
656
- const {
657
- checkForUpdate
658
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
659
- const {
660
- client
661
- } = createClient(createCatalog({
662
- scopeKey: wrongScope
663
- }));
664
- await (0, _vitest.expect)(checkForUpdate({
665
- client,
666
- onError,
667
- updateStrategy: "appVersion"
668
- })).resolves.toBeNull();
669
- (0, _vitest.expect)(onError).toHaveBeenCalledWith(_vitest.expect.objectContaining({
670
- message: "Received an invalid Release catalog"
671
- }));
672
- (0, _vitest.expect)(mocks.acceptReleaseCatalog).not.toHaveBeenCalled();
673
- (0, _vitest.expect)(mocks.commitReleaseSelection).not.toHaveBeenCalled();
674
- (0, _vitest.expect)(mocks.stageBundle).not.toHaveBeenCalled();
675
- });
676
- (0, _vitest.it)("rejects an unexpected Catalog identity before accepting catalog state", async () => {
677
- const active = {
678
- catalogId: "existing-project",
679
- bundleId: CURRENT_BUNDLE_ID,
680
- catalogHash: `sha256:${"b".repeat(64)}`,
681
- channel: CHANNEL,
682
- generation: 1,
683
- kind: "BUNDLE",
684
- releaseId: ACTIVE_RELEASE_ID,
685
- scopeKey: (0, _core.createReleaseCatalogScopeKey)({
686
- channelKey: (0, _core.encodeChannelKey)(CHANNEL),
687
- platform: "ios",
688
- strategy: "APP_VERSION"
689
- }),
690
- selectionContextHash: "old-context"
691
- };
692
- mocks.getActiveUpdateState.mockReturnValueOnce({
693
- activeSelection: active,
694
- highestSeenCatalogs: {},
695
- stableSelection: active,
696
- verificationPending: false
697
- });
698
- const onError = _vitest.vi.fn();
699
- const {
700
- checkForUpdate
701
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
702
- const {
703
- client
704
- } = createClient();
705
- await (0, _vitest.expect)(checkForUpdate({
706
- client,
707
- onError,
708
- updateStrategy: "appVersion"
709
- })).resolves.toBeNull();
710
- (0, _vitest.expect)(onError).toHaveBeenCalledWith(_vitest.expect.objectContaining({
711
- message: "Release transition rejected: UNSOLICITED_SCOPE"
712
- }));
713
- (0, _vitest.expect)(mocks.acceptReleaseCatalog).not.toHaveBeenCalled();
714
- });
715
- (0, _vitest.it)("reports a check that found nothing to install as UNCHANGED", async () => {
716
- mocks.getBundleId.mockReturnValueOnce(MINIMUM_RELEASE_ID);
717
- const {
718
- checkForUpdate
719
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
720
- const events = await recordPluginEvents();
721
- const {
722
- client
723
- } = createClient(createCatalog({
724
- releases: [],
725
- rollbackReleases: []
726
- }));
727
- await (0, _vitest.expect)(checkForUpdate({
728
- client,
729
- updateStrategy: "appVersion"
730
- })).resolves.toBeNull();
731
- (0, _vitest.expect)(events).toEqual([["onUpdateCheck", {
732
- status: "UNCHANGED",
733
- channel: CHANNEL,
734
- bundleId: MINIMUM_RELEASE_ID,
735
- releaseId: null,
736
- previousReleaseId: null
737
- }]]);
738
- });
739
- (0, _vitest.it)("treats a scope without a catalog as no update, not a failure", async () => {
740
- const onError = _vitest.vi.fn();
741
- const {
742
- checkForUpdate
743
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
744
- const events = await recordPluginEvents();
745
- const {
746
- client,
747
- fetchReleaseCatalog
748
- } = createClient();
749
- fetchReleaseCatalog.mockResolvedValueOnce(null);
750
- await (0, _vitest.expect)(checkForUpdate({
751
- client,
752
- onError,
753
- updateStrategy: "appVersion"
754
- })).resolves.toBeNull();
755
- (0, _vitest.expect)(onError).not.toHaveBeenCalled();
756
- (0, _vitest.expect)(mocks.acceptReleaseCatalog).not.toHaveBeenCalled();
757
- (0, _vitest.expect)(events).toEqual([["onUpdateCheck", _vitest.expect.objectContaining({
758
- status: "UNCHANGED",
759
- channel: CHANNEL
760
- })]]);
761
- });
762
- _vitest.it.each([{
763
- label: "an HTTP status",
764
- error: () => new _updateError.UpdateHttpError(503, "Service Unavailable"),
765
- expected: {
766
- reason: "http",
767
- httpStatus: 503
768
- }
769
- }, {
770
- label: "no response",
771
- error: () => new TypeError("Network request failed"),
772
- expected: {
773
- reason: "network"
774
- }
775
- }, {
776
- label: "a 404 without the no-catalog mark",
777
- error: () => new _updateError.UpdateHttpError(404, "Not Found"),
778
- expected: {
779
- reason: "http",
780
- httpStatus: 404
781
- }
782
- }, {
783
- label: "a timeout",
784
- error: () => new Error("Request timed out"),
785
- expected: {
786
- reason: "network",
787
- transport: "timeout"
788
- }
789
- }, {
790
- label: "an invalid catalog",
791
- error: () => new _updateError.InvalidUpdateResponseError("Received an invalid Release catalog"),
792
- expected: {
793
- reason: "invalid_response"
794
- }
795
- }])("reports a check failed by $label", async ({
796
- error,
797
- expected
798
- }) => {
799
- const {
800
- checkForUpdate
801
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
802
- const events = await recordPluginEvents();
803
- const {
804
- client,
805
- fetchReleaseCatalog
806
- } = createClient();
807
- const cause = error();
808
- fetchReleaseCatalog.mockRejectedValueOnce(cause);
809
- await (0, _vitest.expect)(checkForUpdate({
810
- client,
811
- updateStrategy: "appVersion"
812
- })).resolves.toBeNull();
813
- (0, _vitest.expect)(events).toEqual([["onUpdateError", {
814
- stage: "check",
815
- resource: "catalog",
816
- ...expected,
817
- channel: CHANNEL,
818
- bundleId: CURRENT_BUNDLE_ID,
819
- releaseId: null,
820
- updateStrategy: "appVersion",
821
- cause
822
- }]]);
823
- });
824
- _vitest.it.each([{
825
- label: "an artifact request answered 500",
826
- fail: resolveArtifact => resolveArtifact.mockRejectedValueOnce(new _updateError.UpdateHttpError(500, "Internal Server Error")),
827
- expected: {
828
- stage: "download",
829
- reason: "http",
830
- resource: "artifact",
831
- httpStatus: 500
832
- }
833
- }, {
834
- label: "native extraction",
835
- fail: () => mocks.stageBundle.mockRejectedValueOnce(Object.assign(new Error("Failed to extract archive"), {
836
- code: "UNKNOWN_ERROR",
837
- userInfo: {
838
- reason: "extract",
839
- stage: "install"
840
- }
841
- })),
842
- expected: {
843
- stage: "install",
844
- reason: "extract"
845
- }
846
- }, {
847
- label: "a native HTTP status",
848
- fail: () => mocks.stageBundle.mockRejectedValueOnce(Object.assign(new Error("Failed to download bundle"), {
849
- code: "DOWNLOAD_FAILED",
850
- userInfo: {
851
- httpStatus: 403,
852
- originCode: "ExpiredToken",
853
- reason: "http",
854
- resource: "archive",
855
- stage: "download"
856
- }
857
- })),
858
- expected: {
859
- stage: "download",
860
- reason: "http",
861
- resource: "archive",
862
- httpStatus: 403,
863
- originCode: "ExpiredToken"
864
- }
865
- }, {
866
- label: "a native connection loss",
867
- fail: () => mocks.stageBundle.mockRejectedValueOnce(Object.assign(new Error("The network connection was lost."), {
868
- code: "DOWNLOAD_FAILED",
869
- userInfo: {
870
- reason: "network",
871
- resource: "file",
872
- stage: "download",
873
- transport: "connection"
874
- }
875
- })),
876
- expected: {
877
- stage: "download",
878
- reason: "network",
879
- resource: "file",
880
- transport: "connection"
881
- }
882
- }])("reports an install failed by $label and rethrows it", async ({
883
- fail,
884
- expected
885
- }) => {
886
- const {
887
- checkForUpdate
888
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
889
- const events = await recordPluginEvents();
890
- const {
891
- client,
892
- resolveArtifact
893
- } = createClient();
894
- fail(resolveArtifact);
895
- const result = await checkForUpdate({
896
- client,
897
- updateStrategy: "appVersion"
898
- });
899
- await (0, _vitest.expect)(result.updateBundle()).rejects.toThrow();
900
- (0, _vitest.expect)(events.filter(([name]) => name === "onUpdateError")).toEqual([["onUpdateError", _vitest.expect.objectContaining({
901
- ...expected,
902
- channel: CHANNEL,
903
- bundleId: CURRENT_BUNDLE_ID,
904
- targetBundleId: TARGET_BUNDLE_ID,
905
- targetReleaseId: RELEASE_ID,
906
- updateStrategy: "appVersion"
907
- })]]);
908
- });
909
- _vitest.it.each([{
910
- label: "a native rejection without a failure class",
911
- fail: () => mocks.stageBundle.mockRejectedValueOnce(Object.assign(new Error("Release catalog selection is stale"), {
912
- code: "UNKNOWN_ERROR"
913
- }))
914
- }, {
915
- label: "a selection that became stale",
916
- fail: () => mocks.isReleaseSelectionCurrent.mockReturnValueOnce(false)
917
- }])("does not report $label as an update failure", async ({
918
- fail
919
- }) => {
920
- const {
921
- checkForUpdate
922
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./checkForUpdate")));
923
- const events = await recordPluginEvents();
924
- const {
925
- client
926
- } = createClient();
927
- const result = await checkForUpdate({
928
- client,
929
- updateStrategy: "appVersion"
930
- });
931
- fail();
932
- await (0, _vitest.expect)(result.updateBundle()).rejects.toThrow();
933
- (0, _vitest.expect)(events.map(([name]) => name)).toEqual(["onUpdateCheck"]);
934
- });
935
- });
936
- //# sourceMappingURL=checkForUpdate.releaseCatalog.spec.js.map