Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix realm-react progress tests #6833

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion packages/realm-react/src/__tests__/useProgress.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe("useProgress", () => {
[ProgressMode.ForCurrentlyOutstandingWork, ProgressDirection.Download],
[ProgressMode.ForCurrentlyOutstandingWork, ProgressDirection.Upload],
] as [ProgressMode, ProgressDirection][]
).forEach(async ([mode, direction]) => {
).forEach(([mode, direction]) => {
it(`should provide correct progress with ${mode} and ${direction}`, 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",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing me issues before and existed pre-refactor; was the new refactor meant to resolve this? @kraenhansen

Copy link
Member

@kraenhansen kraenhansen Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think of that issue 👍 good catch. I believe it'll be good to have a set of ignored props.

]);

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
4 changes: 3 additions & 1 deletion packages/realm/src/platform/react-native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import "./sync-proxy-config";
import { Realm } from "../../Realm";
import { binding } from "../binding";

console.log("runnnniinn");
// Clear the internal state to prevent crashes when reloading the app
binding.RealmCoordinator.clearAllCaches();
binding.App.clearConnectionChangeCallbacks();
binding.App.clearCachedApps();
binding.RealmCoordinator.clearAllCaches();

export = Realm;

Expand Down
Loading