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

Fixing "Right-hand side of 'instanceof' is not an object" and adding dictionary integration tests (again) #3872

Merged
merged 11 commits into from
Jul 23, 2021
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ x.x.x Release notes (yyyy-MM-dd)
* None.

### Fixed
* Fix TypeScript definition of `Realm.Dictionary.remove()`. (since v10.6.0)
* Fixed TypeScript definition of `Realm.Dictionary.remove()`. (since v10.6.0)
* Fixed Realm.Object#toJSON as it threw "Right-hand side of 'instanceof' is not an object". (since v10.6.0)

### Compatibility
* MongoDB Realm Cloud.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const logcat = require("./logcat");
const IOS_DEVICE_NAME = "realm-js-integration-tests";
const IOS_DEVICE_TYPE_ID = "com.apple.CoreSimulator.SimDeviceType.iPhone-11";

const { MOCHA_REMOTE_PORT, PLATFORM, HEADLESS_DEBUGGER, SPAWN_LOGCAT } = process.env;
const { MOCHA_REMOTE_PORT, PLATFORM, HEADLESS_DEBUGGER, SPAWN_LOGCAT, SKIP_RUNNER } = process.env;

if (typeof PLATFORM !== "string") {
throw new Error("Expected a 'PLATFORM' environment variable");
Expand Down Expand Up @@ -204,6 +204,10 @@ function optionalStringToBoolean(value) {
}

if (module.parent === null) {
if (SKIP_RUNNER === "true") {
console.log("Skipping the runner - you're on your own");
process.exit(0);
}
const headlessDebugger = optionalStringToBoolean(HEADLESS_DEBUGGER);
const spawnLogcat = optionalStringToBoolean(SPAWN_LOGCAT);
run(headlessDebugger, spawnLogcat).catch((err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
// Fetching with inlineSourceMap=true to ease debugging.
return [NSURL URLWithString:[[[[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil] absoluteString] stringByAppendingString:@"&inlineSourceMap=true" ]];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
Expand Down
49 changes: 29 additions & 20 deletions integration-tests/tests/src/hooks/open-realm-before.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type SyncedConfiguration = Omit<Realm.Configuration, "sync"> & {
sync?: Partial<Realm.SyncConfiguration>;
};

export function openRealmBefore(config: LocalConfiguration | SyncedConfiguration = {}): void {
before(async function (this: Partial<RealmContext> & Mocha.Context) {
export function openRealmHook(config: LocalConfiguration | SyncedConfiguration = {}) {
return async function openRealm(this: Partial<RealmContext> & Mocha.Context): Promise<void> {
const nonce = new Realm.BSON.ObjectID().toHexString();
const path = `temp-${nonce}.realm`;
if (this.realm) {
Expand All @@ -48,23 +48,32 @@ export function openRealmBefore(config: LocalConfiguration | SyncedConfiguration
// Upload the schema, ensuring a valid connection
await this.realm.syncSession.uploadAllLocalChanges();
}
});
};
}

// Clean up afterwards
after(function (this: RealmContext) {
if (this.realm) {
this.realm.close();
delete this.realm;
} else {
throw new Error("Expected a 'realm' in the context");
}
if (this.config) {
Realm.deleteFile(this.config);
delete this.config;
} else {
throw new Error("Expected a 'config' in the context");
}
// Clearing the test state to ensure the sync session gets completely reset and nothing is cached between tests
Realm.clearTestState();
});
export function closeRealm(this: RealmContext): void {
if (this.realm) {
this.realm.close();
delete this.realm;
} else {
throw new Error("Expected a 'realm' in the context");
}
if (this.config) {
Realm.deleteFile(this.config);
delete this.config;
} else {
throw new Error("Expected a 'config' in the context");
}
// Clearing the test state to ensure the sync session gets completely reset and nothing is cached between tests
Realm.clearTestState();
}

export function openRealmBeforeEach(config: LocalConfiguration | SyncedConfiguration = {}): void {
beforeEach(openRealmHook(config));
afterEach(closeRealm);
}

export function openRealmBefore(config: LocalConfiguration | SyncedConfiguration = {}): void {
before(openRealmHook(config));
after(closeRealm);
}
1 change: 1 addition & 0 deletions integration-tests/tests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ require("./tests/objects");
require("./tests/iterators");
require("./tests/dynamic-schema-updates");
require("./tests/bson");
require("./tests/dictionary");
require("./tests/credentials/anonymous");
require("./tests/sync/mixed");
Loading