Skip to content

Commit

Permalink
Fix bundling and realm-react progress tests (#6833)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik authored Aug 12, 2024
1 parent 281b586 commit ff3d889
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
5 changes: 2 additions & 3 deletions packages/realm-react/src/__tests__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import { act } from "@testing-library/react-native";
import { EstimateProgressNotificationCallback, ProgressRealmPromise, Realm } from "realm";
import { sleep } from "../helpers";
import { SyncSession } from "../../../realm/dist/public-types/internal";
import { sleep } from "./helpers";

/**
* Mocks {@link Realm.ProgressRealmPromise} with a custom
Expand Down Expand Up @@ -145,7 +144,7 @@ export function mockRealmOpen(
}

/** Mocks a {@link Realm} with a custom syncSession and returns it. */
export function mockSyncedRealm({ syncSession }: { syncSession: Partial<SyncSession> }) {
export function mockSyncedRealm({ syncSession }: { syncSession: Partial<Realm["syncSession"]> }) {
const mockedSyncedRealm = new Realm();

//@ts-expect-error The mock currently supports supplying a subset of methods
Expand Down
16 changes: 7 additions & 9 deletions packages/realm-react/src/__tests__/useProgress.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ describe("useProgress", () => {
jest.restoreAllMocks();
});

(
[
[ProgressMode.ReportIndefinitely, ProgressDirection.Download],
[ProgressMode.ReportIndefinitely, ProgressDirection.Upload],
[ProgressMode.ForCurrentlyOutstandingWork, ProgressDirection.Download],
[ProgressMode.ForCurrentlyOutstandingWork, ProgressDirection.Upload],
] as [ProgressMode, ProgressDirection][]
).forEach(async ([mode, direction]) => {
for (const [mode, direction] of [
[ProgressMode.ReportIndefinitely, ProgressDirection.Download],
[ProgressMode.ReportIndefinitely, ProgressDirection.Upload],
[ProgressMode.ForCurrentlyOutstandingWork, ProgressDirection.Download],
[ProgressMode.ForCurrentlyOutstandingWork, ProgressDirection.Upload],
] as const) {
it(`should provide correct progress with ${mode} and ${direction}`, async () => {
const realm = mockSyncedRealmWithProgress();

Expand All @@ -103,7 +101,7 @@ describe("useProgress", () => {

expect(renderedProgressValues).toStrictEqual([null, ...expectedProgress[mode][direction]]);
});
});
}

it("should handle multiple useProgress hooks with different options", async () => {
const realm = mockSyncedRealmWithProgress();
Expand Down
9 changes: 0 additions & 9 deletions packages/realm-react/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,3 @@ export type RestrictivePick<T, K extends keyof T> = Pick<T, K> & { [RestrictedKe
export function isClassModelConstructor(value: unknown): value is RealmClassType<unknown> {
return Object.getPrototypeOf(value) === Realm.Object;
}

/**
* Adapted from integration-tests
* @param ms For how long should the promise be pending?
* @returns A promise that returns after `ms` milliseconds.
*/
export function sleep(ms = 1000): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
7 changes: 6 additions & 1 deletion packages/realm/src/indirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ type Indirects = {
*/
export const indirect = {} as Indirects;

const IGNORED_PROPS = new Set([
// See https://github.com/realm/realm-js/issues/6522
"$$typeof",
]);

const THROW_ON_ACCESS_HANDLER: ProxyHandler<object> = {
get(_target, prop) {
if (typeof prop === "string") {
if (typeof prop === "string" && !IGNORED_PROPS.has(prop)) {
throw new AccessError(prop);
}
},
Expand Down

0 comments on commit ff3d889

Please sign in to comment.