@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.
- package/lib/commonjs/checkForUpdate.js +7 -9
- package/lib/commonjs/checkForUpdate.js.map +1 -1
- package/lib/commonjs/clientPlugin.js +7 -43
- package/lib/commonjs/clientPlugin.js.map +1 -1
- package/lib/commonjs/httpClient.js +7 -9
- package/lib/commonjs/httpClient.js.map +1 -1
- package/lib/commonjs/index.js +10 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/native.js +4 -4
- package/lib/commonjs/native.js.map +1 -1
- package/lib/commonjs/pluginHost.js +26 -190
- package/lib/commonjs/pluginHost.js.map +1 -1
- package/lib/commonjs/releaseCatalogCache.js +7 -59
- package/lib/commonjs/releaseCatalogCache.js.map +1 -1
- package/lib/commonjs/sdkVersion.js +1 -1
- package/lib/module/checkForUpdate.js +1 -3
- package/lib/module/checkForUpdate.js.map +1 -1
- package/lib/module/clientPlugin.js +1 -41
- package/lib/module/clientPlugin.js.map +1 -1
- package/lib/module/httpClient.js +1 -3
- package/lib/module/httpClient.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/native.js +1 -1
- package/lib/module/native.js.map +1 -1
- package/lib/module/pluginHost.js +22 -187
- package/lib/module/pluginHost.js.map +1 -1
- package/lib/module/releaseCatalogCache.js +3 -54
- package/lib/module/releaseCatalogCache.js.map +1 -1
- package/lib/module/sdkVersion.js +1 -1
- package/lib/typescript/commonjs/checkForUpdate.d.ts.map +1 -1
- package/lib/typescript/commonjs/clientPlugin.d.ts +1 -184
- package/lib/typescript/commonjs/clientPlugin.d.ts.map +1 -1
- package/lib/typescript/commonjs/httpClient.d.ts +1 -2
- package/lib/typescript/commonjs/httpClient.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +1 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/native.d.ts +1 -1
- package/lib/typescript/commonjs/native.d.ts.map +1 -1
- package/lib/typescript/commonjs/pluginHost.d.ts +3 -28
- package/lib/typescript/commonjs/pluginHost.d.ts.map +1 -1
- package/lib/typescript/commonjs/releaseCatalogCache.d.ts +1 -13
- package/lib/typescript/commonjs/releaseCatalogCache.d.ts.map +1 -1
- package/lib/typescript/commonjs/sdkVersion.d.ts +1 -1
- package/lib/typescript/commonjs/types.d.ts +1 -1
- package/lib/typescript/commonjs/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/wrap.types.d.ts +2 -2
- package/lib/typescript/module/checkForUpdate.d.ts.map +1 -1
- package/lib/typescript/module/clientPlugin.d.ts +1 -184
- package/lib/typescript/module/clientPlugin.d.ts.map +1 -1
- package/lib/typescript/module/httpClient.d.ts +1 -2
- package/lib/typescript/module/httpClient.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +1 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/native.d.ts +1 -1
- package/lib/typescript/module/native.d.ts.map +1 -1
- package/lib/typescript/module/pluginHost.d.ts +3 -28
- package/lib/typescript/module/pluginHost.d.ts.map +1 -1
- package/lib/typescript/module/releaseCatalogCache.d.ts +1 -13
- package/lib/typescript/module/releaseCatalogCache.d.ts.map +1 -1
- package/lib/typescript/module/sdkVersion.d.ts +1 -1
- package/lib/typescript/module/types.d.ts +1 -1
- package/lib/typescript/module/types.d.ts.map +1 -1
- package/lib/typescript/module/wrap.types.d.ts +2 -2
- package/package.json +7 -16
- package/src/checkForUpdate.ts +4 -6
- package/src/clientPlugin.ts +17 -231
- package/src/httpClient.ts +4 -4
- package/src/index.ts +7 -0
- package/src/native.ts +1 -1
- package/src/pluginHost.ts +24 -241
- package/src/releaseCatalogCache.ts +7 -136
- package/src/sdkVersion.ts +1 -1
- package/src/types.ts +1 -1
- package/src/wrap.types.ts +2 -2
- package/android/src/test/java/com/hotupdater/BsdiffPatchTest.kt +0 -46
- package/android/src/test/java/com/hotupdater/BundleFileStorageServiceTest.kt +0 -2236
- package/android/src/test/java/com/hotupdater/HotUpdaterExceptionTest.kt +0 -220
- package/android/src/test/java/com/hotupdater/HotUpdaterImplTest.kt +0 -264
- package/android/src/test/java/com/hotupdater/HotUpdaterRecoveryStateTest.kt +0 -97
- package/android/src/test/java/com/hotupdater/InstallIdentityServiceTest.kt +0 -71
- package/android/src/test/java/com/hotupdater/KeyValueStorageServiceTest.kt +0 -106
- package/android/src/test/java/com/hotupdater/NativeConfigUtilsTest.kt +0 -20
- package/android/src/test/java/com/hotupdater/NoBackupContext.kt +0 -11
- package/android/src/test/java/com/hotupdater/OkHttpDownloadServiceTest.kt +0 -397
- package/android/src/test/java/com/hotupdater/PendingCrashRecoveryTest.kt +0 -44
- package/android/src/test/java/com/hotupdater/PreviousProcessExitTest.kt +0 -57
- package/android/src/test/java/com/hotupdater/RelativePathResolverTest.kt +0 -41
- package/android/src/test/java/com/hotupdater/ReleaseCatalogCacheServiceTest.kt +0 -118
- package/android/src/test/java/com/hotupdater/TarBrArchiveExtractorTest.kt +0 -206
- package/lib/commonjs/appReady.spec.js +0 -360
- package/lib/commonjs/appReady.spec.js.map +0 -1
- package/lib/commonjs/appReady.test-utils.js +0 -25
- package/lib/commonjs/appReady.test-utils.js.map +0 -1
- package/lib/commonjs/baseURL.js +0 -16
- package/lib/commonjs/baseURL.js.map +0 -1
- package/lib/commonjs/catalogCacheNative.spec.js +0 -31
- package/lib/commonjs/catalogCacheNative.spec.js.map +0 -1
- package/lib/commonjs/checkForUpdate.releaseCatalog.spec.js +0 -936
- package/lib/commonjs/checkForUpdate.releaseCatalog.spec.js.map +0 -1
- package/lib/commonjs/entryImportGraph.spec.js +0 -50
- package/lib/commonjs/entryImportGraph.spec.js.map +0 -1
- package/lib/commonjs/httpClient.spec.js +0 -171
- package/lib/commonjs/httpClient.spec.js.map +0 -1
- package/lib/commonjs/index.spec.js +0 -395
- package/lib/commonjs/index.spec.js.map +0 -1
- package/lib/commonjs/iosInterop.spec.js +0 -18
- package/lib/commonjs/iosInterop.spec.js.map +0 -1
- package/lib/commonjs/native.spec.js +0 -910
- package/lib/commonjs/native.spec.js.map +0 -1
- package/lib/commonjs/pluginHost.spec.js +0 -292
- package/lib/commonjs/pluginHost.spec.js.map +0 -1
- package/lib/commonjs/plugins/insights/eventId.js +0 -129
- package/lib/commonjs/plugins/insights/eventId.js.map +0 -1
- package/lib/commonjs/plugins/insights/eventId.spec.js +0 -47
- package/lib/commonjs/plugins/insights/eventId.spec.js.map +0 -1
- package/lib/commonjs/plugins/insights/index.js +0 -272
- package/lib/commonjs/plugins/insights/index.js.map +0 -1
- package/lib/commonjs/plugins/insights/insights.spec.js +0 -640
- package/lib/commonjs/plugins/insights/insights.spec.js.map +0 -1
- package/lib/commonjs/plugins/insights/sender.js +0 -128
- package/lib/commonjs/plugins/insights/sender.js.map +0 -1
- package/lib/commonjs/plugins/insights/sender.spec.js +0 -265
- package/lib/commonjs/plugins/insights/sender.spec.js.map +0 -1
- package/lib/commonjs/plugins/insights/state.js +0 -145
- package/lib/commonjs/plugins/insights/state.js.map +0 -1
- package/lib/commonjs/releaseCatalogCache.spec.js +0 -213
- package/lib/commonjs/releaseCatalogCache.spec.js.map +0 -1
- package/lib/commonjs/releaseCatalogCacheNativeContract.spec.js +0 -64
- package/lib/commonjs/releaseCatalogCacheNativeContract.spec.js.map +0 -1
- package/lib/commonjs/store.notification.spec.js +0 -84
- package/lib/commonjs/store.notification.spec.js.map +0 -1
- package/lib/commonjs/store.spec.js +0 -182
- package/lib/commonjs/store.spec.js.map +0 -1
- package/lib/commonjs/updateError.spec.js +0 -149
- package/lib/commonjs/updateError.spec.js.map +0 -1
- package/lib/commonjs/wrap.progress.spec.js +0 -195
- package/lib/commonjs/wrap.progress.spec.js.map +0 -1
- package/lib/commonjs/wrap.spec.js +0 -232
- package/lib/commonjs/wrap.spec.js.map +0 -1
- package/lib/module/appReady.spec.js +0 -359
- package/lib/module/appReady.spec.js.map +0 -1
- package/lib/module/appReady.test-utils.js +0 -19
- package/lib/module/appReady.test-utils.js.map +0 -1
- package/lib/module/baseURL.js +0 -11
- package/lib/module/baseURL.js.map +0 -1
- package/lib/module/catalogCacheNative.spec.js +0 -31
- package/lib/module/catalogCacheNative.spec.js.map +0 -1
- package/lib/module/checkForUpdate.releaseCatalog.spec.js +0 -935
- package/lib/module/checkForUpdate.releaseCatalog.spec.js.map +0 -1
- package/lib/module/entryImportGraph.spec.js +0 -50
- package/lib/module/entryImportGraph.spec.js.map +0 -1
- package/lib/module/httpClient.spec.js +0 -171
- package/lib/module/httpClient.spec.js.map +0 -1
- package/lib/module/index.spec.js +0 -394
- package/lib/module/index.spec.js.map +0 -1
- package/lib/module/iosInterop.spec.js +0 -18
- package/lib/module/iosInterop.spec.js.map +0 -1
- package/lib/module/native.spec.js +0 -909
- package/lib/module/native.spec.js.map +0 -1
- package/lib/module/pluginHost.spec.js +0 -291
- package/lib/module/pluginHost.spec.js.map +0 -1
- package/lib/module/plugins/insights/eventId.js +0 -122
- package/lib/module/plugins/insights/eventId.js.map +0 -1
- package/lib/module/plugins/insights/eventId.spec.js +0 -47
- package/lib/module/plugins/insights/eventId.spec.js.map +0 -1
- package/lib/module/plugins/insights/index.js +0 -268
- package/lib/module/plugins/insights/index.js.map +0 -1
- package/lib/module/plugins/insights/insights.spec.js +0 -639
- package/lib/module/plugins/insights/insights.spec.js.map +0 -1
- package/lib/module/plugins/insights/sender.js +0 -123
- package/lib/module/plugins/insights/sender.js.map +0 -1
- package/lib/module/plugins/insights/sender.spec.js +0 -265
- package/lib/module/plugins/insights/sender.spec.js.map +0 -1
- package/lib/module/plugins/insights/state.js +0 -139
- package/lib/module/plugins/insights/state.js.map +0 -1
- package/lib/module/releaseCatalogCache.spec.js +0 -213
- package/lib/module/releaseCatalogCache.spec.js.map +0 -1
- package/lib/module/releaseCatalogCacheNativeContract.spec.js +0 -64
- package/lib/module/releaseCatalogCacheNativeContract.spec.js.map +0 -1
- package/lib/module/store.notification.spec.js +0 -85
- package/lib/module/store.notification.spec.js.map +0 -1
- package/lib/module/store.spec.js +0 -181
- package/lib/module/store.spec.js.map +0 -1
- package/lib/module/updateError.spec.js +0 -149
- package/lib/module/updateError.spec.js.map +0 -1
- package/lib/module/wrap.progress.spec.js +0 -196
- package/lib/module/wrap.progress.spec.js.map +0 -1
- package/lib/module/wrap.spec.js +0 -233
- package/lib/module/wrap.spec.js.map +0 -1
- package/lib/typescript/commonjs/appReady.test-utils.d.ts +0 -9
- package/lib/typescript/commonjs/appReady.test-utils.d.ts.map +0 -1
- package/lib/typescript/commonjs/baseURL.d.ts +0 -4
- package/lib/typescript/commonjs/baseURL.d.ts.map +0 -1
- package/lib/typescript/commonjs/plugins/insights/eventId.d.ts +0 -18
- package/lib/typescript/commonjs/plugins/insights/eventId.d.ts.map +0 -1
- package/lib/typescript/commonjs/plugins/insights/index.d.ts +0 -40
- package/lib/typescript/commonjs/plugins/insights/index.d.ts.map +0 -1
- package/lib/typescript/commonjs/plugins/insights/sender.d.ts +0 -74
- package/lib/typescript/commonjs/plugins/insights/sender.d.ts.map +0 -1
- package/lib/typescript/commonjs/plugins/insights/state.d.ts +0 -46
- package/lib/typescript/commonjs/plugins/insights/state.d.ts.map +0 -1
- package/lib/typescript/module/appReady.test-utils.d.ts +0 -9
- package/lib/typescript/module/appReady.test-utils.d.ts.map +0 -1
- package/lib/typescript/module/baseURL.d.ts +0 -4
- package/lib/typescript/module/baseURL.d.ts.map +0 -1
- package/lib/typescript/module/plugins/insights/eventId.d.ts +0 -18
- package/lib/typescript/module/plugins/insights/eventId.d.ts.map +0 -1
- package/lib/typescript/module/plugins/insights/index.d.ts +0 -40
- package/lib/typescript/module/plugins/insights/index.d.ts.map +0 -1
- package/lib/typescript/module/plugins/insights/sender.d.ts +0 -74
- package/lib/typescript/module/plugins/insights/sender.d.ts.map +0 -1
- package/lib/typescript/module/plugins/insights/state.d.ts +0 -46
- package/lib/typescript/module/plugins/insights/state.d.ts.map +0 -1
- package/plugins/insights/package.json +0 -8
- package/src/appReady.spec.ts +0 -393
- package/src/appReady.test-utils.ts +0 -31
- package/src/baseURL.ts +0 -15
- package/src/catalogCacheNative.spec.ts +0 -63
- package/src/checkForUpdate.releaseCatalog.spec.ts +0 -966
- package/src/entryImportGraph.spec.ts +0 -65
- package/src/httpClient.spec.ts +0 -216
- package/src/index.spec.ts +0 -434
- package/src/iosInterop.spec.ts +0 -30
- package/src/native.spec.ts +0 -978
- package/src/pluginHost.spec.ts +0 -297
- package/src/plugins/insights/eventId.spec.ts +0 -60
- package/src/plugins/insights/eventId.ts +0 -171
- package/src/plugins/insights/index.ts +0 -367
- package/src/plugins/insights/insights.spec.ts +0 -732
- package/src/plugins/insights/sender.spec.ts +0 -287
- package/src/plugins/insights/sender.ts +0 -221
- package/src/plugins/insights/state.ts +0 -184
- package/src/releaseCatalogCache.spec.ts +0 -304
- package/src/releaseCatalogCacheNativeContract.spec.ts +0 -80
- package/src/store.notification.spec.ts +0 -102
- package/src/store.spec.ts +0 -215
- package/src/updateError.spec.ts +0 -144
- package/src/wrap.progress.spec.ts +0 -232
- package/src/wrap.spec.ts +0 -262
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { dirname, join, relative, resolve } from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
5
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
-
|
|
7
|
-
const sourceRoot = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
|
|
9
|
-
/** Every relative module a file imports, statically or dynamically. */
|
|
10
|
-
const readImports = (file: string): string[] => {
|
|
11
|
-
const source = readFileSync(file, "utf8");
|
|
12
|
-
const specifiers = [
|
|
13
|
-
...source.matchAll(/\b(?:import|export)\s[^;]*?\bfrom\s*["']([^"']+)["']/g),
|
|
14
|
-
...source.matchAll(/\bimport\s*["']([^"']+)["']/g),
|
|
15
|
-
...source.matchAll(/\bimport\(\s*["']([^"']+)["']\s*\)/g),
|
|
16
|
-
].map((match) => match[1]!);
|
|
17
|
-
return specifiers.filter((specifier) => specifier.startsWith("."));
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const resolveModule = (from: string, specifier: string): string => {
|
|
21
|
-
const base = resolve(dirname(from), specifier);
|
|
22
|
-
const file = [
|
|
23
|
-
`${base}.ts`,
|
|
24
|
-
`${base}.tsx`,
|
|
25
|
-
join(base, "index.ts"),
|
|
26
|
-
join(base, "index.tsx"),
|
|
27
|
-
].find((path) => existsSync(path));
|
|
28
|
-
if (file === undefined) {
|
|
29
|
-
throw new Error(`Cannot resolve ${specifier} from ${from}`);
|
|
30
|
-
}
|
|
31
|
-
return file;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const collectGraph = (entry: string): Set<string> => {
|
|
35
|
-
const seen = new Set<string>();
|
|
36
|
-
const pending = [entry];
|
|
37
|
-
while (pending.length > 0) {
|
|
38
|
-
const file = pending.pop()!;
|
|
39
|
-
if (seen.has(file)) continue;
|
|
40
|
-
seen.add(file);
|
|
41
|
-
for (const specifier of readImports(file)) {
|
|
42
|
-
pending.push(resolveModule(file, specifier));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return seen;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
describe("@hot-updater/react-native root entry", () => {
|
|
49
|
-
const graph = [...collectGraph(join(sourceRoot, "index.ts"))].map((file) =>
|
|
50
|
-
relative(sourceRoot, file),
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
it("bundles no plugin, since Metro does not tree-shake", () => {
|
|
54
|
-
expect(graph).toContain("pluginHost.ts");
|
|
55
|
-
expect(graph.filter((file) => file.startsWith("plugins/"))).toEqual([]);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("sends no Insights request", () => {
|
|
59
|
-
const insightsCode = graph.filter((file) => {
|
|
60
|
-
const source = readFileSync(join(sourceRoot, file), "utf8");
|
|
61
|
-
return /["'`/]events["'`]/.test(source);
|
|
62
|
-
});
|
|
63
|
-
expect(insightsCode).toEqual([]);
|
|
64
|
-
});
|
|
65
|
-
});
|
package/src/httpClient.spec.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import type { ArtifactInfo, ReleaseCatalog } from "@hot-updater/core";
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { FetchJSONResponseError } from "./fetchJSON";
|
|
5
|
-
import { createHttpClient } from "./httpClient";
|
|
6
|
-
import { InvalidUpdateResponseError } from "./updateError";
|
|
7
|
-
|
|
8
|
-
const mocks = vi.hoisted(() => ({
|
|
9
|
-
fetchCatalog: vi.fn(),
|
|
10
|
-
fetchJSON: vi.fn(),
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
vi.mock("./releaseCatalogCache", () => ({
|
|
14
|
-
fetchReleaseCatalogWithCache: mocks.fetchCatalog,
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
vi.mock("./fetchJSON", () => ({
|
|
18
|
-
FetchJSONResponseError: class FetchJSONResponseError extends Error {
|
|
19
|
-
constructor(
|
|
20
|
-
readonly status: number,
|
|
21
|
-
statusText: string,
|
|
22
|
-
) {
|
|
23
|
-
super(statusText);
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
fetchJSON: mocks.fetchJSON,
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
const artifact: ArtifactInfo = {
|
|
30
|
-
artifactProtocolVersion: 1,
|
|
31
|
-
assets: {
|
|
32
|
-
"index.ios.bundle": {
|
|
33
|
-
file: { url: "/storage/index.bundle.br" },
|
|
34
|
-
fileHash: "bundle-hash",
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
manifestFileHash: "manifest-hash",
|
|
38
|
-
manifestUrl: "/storage/manifest.json",
|
|
39
|
-
archiveUrl: "/storage/bundle.tar.br",
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const catalog: ReleaseCatalog = {
|
|
43
|
-
catalogId: "server-owned-project",
|
|
44
|
-
catalogHash: `sha256:${"a".repeat(64)}`,
|
|
45
|
-
fallbackPolicy: "BUILTIN_IF_ACTIVE_INELIGIBLE",
|
|
46
|
-
generation: 1,
|
|
47
|
-
releases: [],
|
|
48
|
-
schemaVersion: 1,
|
|
49
|
-
scopeKey: "v1:app-version:server-owned-project:ios:cHJvZHVjdGlvbg",
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
describe("private HotUpdater HTTP client", () => {
|
|
53
|
-
beforeEach(() => {
|
|
54
|
-
vi.clearAllMocks();
|
|
55
|
-
mocks.fetchCatalog.mockResolvedValue(catalog);
|
|
56
|
-
mocks.fetchJSON.mockResolvedValue(artifact);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("fetches a catalog without putting its internal identity in the route", async () => {
|
|
60
|
-
const session = await createHttpClient(
|
|
61
|
-
"https://updates.example.com/hot-updater/",
|
|
62
|
-
).createSession();
|
|
63
|
-
|
|
64
|
-
await expect(
|
|
65
|
-
session.fetchReleaseCatalog({
|
|
66
|
-
appVersion: "1.2.0",
|
|
67
|
-
channel: "production",
|
|
68
|
-
fingerprintHash: null,
|
|
69
|
-
platform: "ios",
|
|
70
|
-
updateStrategy: "appVersion",
|
|
71
|
-
}),
|
|
72
|
-
).resolves.toBe(catalog);
|
|
73
|
-
|
|
74
|
-
expect(mocks.fetchCatalog).toHaveBeenCalledWith({
|
|
75
|
-
baseURL: "https://updates.example.com/hot-updater",
|
|
76
|
-
expectedScope: {
|
|
77
|
-
channelKey: "cHJvZHVjdGlvbg",
|
|
78
|
-
platform: "ios",
|
|
79
|
-
strategy: "APP_VERSION",
|
|
80
|
-
},
|
|
81
|
-
requestHeaders: undefined,
|
|
82
|
-
requestTimeout: undefined,
|
|
83
|
-
url: "https://updates.example.com/hot-updater/release-catalogs/app-version/ios/cHJvZHVjdGlvbg/1.2.0",
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("resolves a functional baseURL once per session and captures it for a deferred artifact", async () => {
|
|
88
|
-
const resolveBaseURL = vi
|
|
89
|
-
.fn()
|
|
90
|
-
.mockResolvedValueOnce("https://first.example.com/hot-updater")
|
|
91
|
-
.mockResolvedValueOnce("https://second.example.com/hot-updater");
|
|
92
|
-
const client = createHttpClient(resolveBaseURL);
|
|
93
|
-
const firstSession = await client.createSession();
|
|
94
|
-
|
|
95
|
-
await firstSession.fetchReleaseCatalog({
|
|
96
|
-
appVersion: "1.2.0",
|
|
97
|
-
channel: "production",
|
|
98
|
-
fingerprintHash: null,
|
|
99
|
-
platform: "ios",
|
|
100
|
-
updateStrategy: "appVersion",
|
|
101
|
-
});
|
|
102
|
-
await expect(
|
|
103
|
-
firstSession.resolveArtifact({
|
|
104
|
-
currentBundleId: "current",
|
|
105
|
-
targetBundleId: "target",
|
|
106
|
-
}),
|
|
107
|
-
).resolves.toEqual({
|
|
108
|
-
...artifact,
|
|
109
|
-
assets: {
|
|
110
|
-
"index.ios.bundle": {
|
|
111
|
-
file: {
|
|
112
|
-
url: "https://first.example.com/hot-updater/storage/index.bundle.br",
|
|
113
|
-
},
|
|
114
|
-
fileHash: "bundle-hash",
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
manifestUrl:
|
|
118
|
-
"https://first.example.com/hot-updater/storage/manifest.json",
|
|
119
|
-
archiveUrl: "https://first.example.com/hot-updater/storage/bundle.tar.br",
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
expect(resolveBaseURL).toHaveBeenCalledOnce();
|
|
123
|
-
expect(mocks.fetchJSON).toHaveBeenCalledWith({
|
|
124
|
-
requestHeaders: undefined,
|
|
125
|
-
requestTimeout: undefined,
|
|
126
|
-
url: "https://first.example.com/hot-updater/artifacts/v1/target/from/current",
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
await client.createSession();
|
|
130
|
-
expect(resolveBaseURL).toHaveBeenCalledTimes(2);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("rejects non-storage relative artifact URLs", async () => {
|
|
134
|
-
mocks.fetchJSON.mockResolvedValue({
|
|
135
|
-
...artifact,
|
|
136
|
-
assets: {
|
|
137
|
-
"index.ios.bundle": {
|
|
138
|
-
file: { url: "/private/index.bundle.br" },
|
|
139
|
-
fileHash: "bundle-hash",
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
const session = await createHttpClient(
|
|
144
|
-
"https://updates.example.com",
|
|
145
|
-
).createSession();
|
|
146
|
-
|
|
147
|
-
await expect(
|
|
148
|
-
session.resolveArtifact({
|
|
149
|
-
currentBundleId: "current",
|
|
150
|
-
targetBundleId: "target",
|
|
151
|
-
}),
|
|
152
|
-
).rejects.toThrow("client-relative storage paths");
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("rejects a legacy artifact response", async () => {
|
|
156
|
-
mocks.fetchJSON.mockResolvedValue({
|
|
157
|
-
fileHash: "archive-hash",
|
|
158
|
-
fileUrl: "/storage/bundle.zip",
|
|
159
|
-
});
|
|
160
|
-
const session = await createHttpClient(
|
|
161
|
-
"https://updates.example.com",
|
|
162
|
-
).createSession();
|
|
163
|
-
|
|
164
|
-
await expect(
|
|
165
|
-
session.resolveArtifact({
|
|
166
|
-
currentBundleId: "current",
|
|
167
|
-
targetBundleId: "target",
|
|
168
|
-
}),
|
|
169
|
-
).rejects.toThrow("does not support artifact protocol 1");
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("reports an old server without the v1 endpoint explicitly", async () => {
|
|
173
|
-
mocks.fetchJSON.mockRejectedValue(
|
|
174
|
-
new FetchJSONResponseError(404, "Not Found"),
|
|
175
|
-
);
|
|
176
|
-
const session = await createHttpClient(
|
|
177
|
-
"https://updates.example.com",
|
|
178
|
-
).createSession();
|
|
179
|
-
|
|
180
|
-
await expect(
|
|
181
|
-
session.resolveArtifact({
|
|
182
|
-
currentBundleId: "current",
|
|
183
|
-
targetBundleId: "target",
|
|
184
|
-
}),
|
|
185
|
-
).rejects.toThrow("does not support artifact protocol 1");
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it.each([
|
|
189
|
-
{ label: "a legacy response", response: { fileUrl: "/storage/a.zip" } },
|
|
190
|
-
{
|
|
191
|
-
label: "an invalid absolute URL",
|
|
192
|
-
response: {
|
|
193
|
-
...artifact,
|
|
194
|
-
manifestUrl: "https://",
|
|
195
|
-
},
|
|
196
|
-
},
|
|
197
|
-
])("marks $label as an invalid update response", async ({ response }) => {
|
|
198
|
-
mocks.fetchJSON.mockResolvedValue(response);
|
|
199
|
-
const session = await createHttpClient(
|
|
200
|
-
"https://updates.example.com",
|
|
201
|
-
).createSession();
|
|
202
|
-
|
|
203
|
-
await expect(
|
|
204
|
-
session.resolveArtifact({
|
|
205
|
-
currentBundleId: "current",
|
|
206
|
-
targetBundleId: "target",
|
|
207
|
-
}),
|
|
208
|
-
).rejects.toBeInstanceOf(InvalidUpdateResponseError);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("requires a functional baseURL to resolve to a non-empty string", async () => {
|
|
212
|
-
await expect(createHttpClient(() => "").createSession()).rejects.toThrow(
|
|
213
|
-
"baseURL function must return a non-empty string",
|
|
214
|
-
);
|
|
215
|
-
});
|
|
216
|
-
});
|