@hot-updater/test-utils 1.0.0-rc.27 → 1.0.0-rc.28

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/dist/index.mjs CHANGED
@@ -4713,6 +4713,92 @@ const setupInsightsHttpTestSuite = (options) => {
4713
4713
  return (await (await client.admin(`/overview?platform=ios&channel=${encodeURIComponent(channel)}&window=24h`)).json()).reportingInstallations.count;
4714
4714
  }, 1);
4715
4715
  });
4716
+ it.each([
4717
+ {
4718
+ type: "UNCHANGED",
4719
+ status: 200,
4720
+ body: "{\"releases\":[]}"
4721
+ },
4722
+ {
4723
+ type: "UNCHANGED",
4724
+ status: 304,
4725
+ body: ""
4726
+ },
4727
+ {
4728
+ type: "UPDATE_FAILED",
4729
+ status: 503,
4730
+ body: "{\"error\":\"Database unavailable\"}"
4731
+ },
4732
+ {
4733
+ type: "UPDATE_DOWNLOADED",
4734
+ status: 200,
4735
+ body: "{\"artifactProtocolVersion\":1}"
4736
+ },
4737
+ {
4738
+ type: "UPDATE_APPLIED",
4739
+ status: 200,
4740
+ body: "{}"
4741
+ },
4742
+ {
4743
+ type: "RECOVERED",
4744
+ status: 502,
4745
+ body: null
4746
+ }
4747
+ ])("keeps HTTP $status diagnostics on an existing $type report", async ({ type, status, body }) => {
4748
+ const client = options.getClient();
4749
+ const installId = `install-${crypto.randomUUID()}`;
4750
+ const channel = `http-${crypto.randomUUID()}`;
4751
+ const bundleId = "00000000-0000-7000-8000-000000000001";
4752
+ const httpResponse = {
4753
+ resource: "catalog",
4754
+ path: "/release-catalogs/app-version/ios/production/1.0.0",
4755
+ status,
4756
+ body,
4757
+ bodyTruncated: false,
4758
+ receivedAtMs: Date.now() - 1e3
4759
+ };
4760
+ const event = {
4761
+ eventId: "01929f4e-2b7c-7a51-9d3e-5c1f0a6b8e21",
4762
+ type,
4763
+ installId,
4764
+ platform: "ios",
4765
+ appVersion: "1.0.0",
4766
+ channel,
4767
+ cohort: "1",
4768
+ fingerprintHash: null,
4769
+ sdkVersion: "1.0.0",
4770
+ fromBundleId: type === "UNCHANGED" ? null : bundleId,
4771
+ toBundleId: bundleId,
4772
+ fromReleaseId: null,
4773
+ toReleaseId: null,
4774
+ updateStrategy: type === "UNCHANGED" ? null : "appVersion",
4775
+ metadata: {
4776
+ httpResponse,
4777
+ ...type === "UPDATE_FAILED" ? { failure: {
4778
+ stage: "check",
4779
+ reason: "http",
4780
+ httpStatus: status
4781
+ } } : {}
4782
+ }
4783
+ };
4784
+ for (let attempt = 0; attempt < 2; attempt++) {
4785
+ const response = await client.client("/events", jsonRequest$1("POST", event));
4786
+ expect(response.status).toBe(204);
4787
+ await response.text();
4788
+ }
4789
+ const installation = await client.admin(`/installations/${encodeURIComponent(installId)}`);
4790
+ if (type === "UPDATE_FAILED") expect(installation.status).toBe(404);
4791
+ else expect(await installation.json()).toMatchObject({
4792
+ latestStatus: type,
4793
+ httpResponse
4794
+ });
4795
+ const data = (await (await client.admin(`/installations/${encodeURIComponent(installId)}/events`)).json()).data;
4796
+ expect(data).toHaveLength(type === "UNCHANGED" ? 0 : 1);
4797
+ if (type !== "UNCHANGED") expect(data[0]).toMatchObject({
4798
+ type,
4799
+ httpResponse
4800
+ });
4801
+ });
4716
4802
  it("records an update failure in installation history and the failures read", async () => {
4717
4803
  const client = options.getClient();
4718
4804
  const installId = `install-${crypto.randomUUID()}`;
@@ -154,7 +154,8 @@ const setupClientPlugins = (plugins, options = {}) => {
154
154
  onAppReady: call("onAppReady"),
155
155
  onUpdateCheck: call("onUpdateCheck"),
156
156
  onBundleDownloaded: call("onBundleDownloaded"),
157
- onUpdateError: call("onUpdateError")
157
+ onUpdateError: call("onUpdateError"),
158
+ onHttpResponse: call("onHttpResponse")
158
159
  },
159
160
  listens: (name) => host.hasPluginHook(name),
160
161
  requests,
@@ -1,4 +1,4 @@
1
- import { AppReadyResult, BundleDownloadedInfo, HotUpdaterBaseURL, HotUpdaterClientPlugin, UpdateCheckResult, UpdateError } from "@hot-updater/protocol";
1
+ import { AppReadyResult, BundleDownloadedInfo, HotUpdaterBaseURL, HotUpdaterClientPlugin, UpdateCheckResult, UpdateError, UpdateHttpResponse } from "@hot-updater/protocol";
2
2
  //#region src/setupClientPlugins.d.ts
3
3
  /** A value the test fixes, or reads each time a plugin asks for it. */
4
4
  type TestValue<T> = T | (() => T);
@@ -68,6 +68,7 @@ interface ClientPluginTestHooks {
68
68
  onUpdateCheck(result: UpdateCheckResult): void;
69
69
  onBundleDownloaded(info: BundleDownloadedInfo): void;
70
70
  onUpdateError(error: UpdateError): void;
71
+ onHttpResponse(response: UpdateHttpResponse): void;
71
72
  }
72
73
  /** One JavaScript runtime with the plugins set up, as after `HotUpdater.init`. */
73
74
  interface ClientPluginTestRuntime {
@@ -1,4 +1,4 @@
1
- import { AppReadyResult, BundleDownloadedInfo, HotUpdaterBaseURL, HotUpdaterClientPlugin, UpdateCheckResult, UpdateError } from "@hot-updater/protocol";
1
+ import { AppReadyResult, BundleDownloadedInfo, HotUpdaterBaseURL, HotUpdaterClientPlugin, UpdateCheckResult, UpdateError, UpdateHttpResponse } from "@hot-updater/protocol";
2
2
  //#region src/setupClientPlugins.d.ts
3
3
  /** A value the test fixes, or reads each time a plugin asks for it. */
4
4
  type TestValue<T> = T | (() => T);
@@ -68,6 +68,7 @@ interface ClientPluginTestHooks {
68
68
  onUpdateCheck(result: UpdateCheckResult): void;
69
69
  onBundleDownloaded(info: BundleDownloadedInfo): void;
70
70
  onUpdateError(error: UpdateError): void;
71
+ onHttpResponse(response: UpdateHttpResponse): void;
71
72
  }
72
73
  /** One JavaScript runtime with the plugins set up, as after `HotUpdater.init`. */
73
74
  interface ClientPluginTestRuntime {
@@ -153,7 +153,8 @@ const setupClientPlugins = (plugins, options = {}) => {
153
153
  onAppReady: call("onAppReady"),
154
154
  onUpdateCheck: call("onUpdateCheck"),
155
155
  onBundleDownloaded: call("onBundleDownloaded"),
156
- onUpdateError: call("onUpdateError")
156
+ onUpdateError: call("onUpdateError"),
157
+ onHttpResponse: call("onHttpResponse")
157
158
  },
158
159
  listens: (name) => host.hasPluginHook(name),
159
160
  requests,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/test-utils",
3
- "version": "1.0.0-rc.27",
3
+ "version": "1.0.0-rc.28",
4
4
  "type": "module",
5
5
  "description": "Test utilities for Hot Updater packages",
6
6
  "sideEffects": false,
@@ -50,10 +50,10 @@
50
50
  "mysql2": "*",
51
51
  "pg": "*",
52
52
  "vitest": "^4.0.0",
53
- "@hot-updater/protocol": "^1.0.0-rc.27",
54
- "@hot-updater/plugin-insights": "^1.0.0-rc.27",
55
- "@hot-updater/plugin-core": "^1.0.0-rc.27",
56
- "@hot-updater/server": "^1.0.0-rc.27"
53
+ "@hot-updater/plugin-insights": "^1.0.0-rc.29",
54
+ "@hot-updater/protocol": "^1.0.0-rc.28",
55
+ "@hot-updater/plugin-core": "^1.0.0-rc.28",
56
+ "@hot-updater/server": "^1.0.0-rc.29"
57
57
  },
58
58
  "peerDependenciesMeta": {
59
59
  "@electric-sql/pglite": {
@@ -83,11 +83,11 @@
83
83
  "typescript": "npm:@typescript/typescript6@6.0.2",
84
84
  "vitest": "4.1.4",
85
85
  "workspace-tools": "^0.41.7",
86
- "@hot-updater/plugin-insights": "1.0.0-rc.27",
87
- "@hot-updater/protocol": "1.0.0-rc.27",
86
+ "@hot-updater/plugin-insights": "1.0.0-rc.29",
87
+ "@hot-updater/protocol": "1.0.0-rc.28",
88
88
  "@hot-updater/js": "1.0.0-rc.27",
89
- "@hot-updater/server": "1.0.0-rc.27",
90
- "@hot-updater/plugin-core": "1.0.0-rc.27"
89
+ "@hot-updater/plugin-core": "1.0.0-rc.28",
90
+ "@hot-updater/server": "1.0.0-rc.29"
91
91
  },
92
92
  "inlinedDependencies": {
93
93
  "@nodelib/fs.scandir": "2.1.5",