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

Enable strictNullChecks for integration tests #4193

Merged
merged 2 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ x.x.x Release notes (yyyy-MM-dd)
* <Using Realm Core vX.Y.Z>
* <Upgraded Realm Core from vX.Y.Z to vA.B.C>
* Removed `.dir-locals.el`. Please configure Emacs to use `clang-format` e.g. https://github.com/SavchenkoValeriy/emacs-clang-format-plus.
* Enabled `strictNullChecks` for integration tests

10.11.0 Release notes (2021-12-21)
=============================================================
Expand Down
6 changes: 5 additions & 1 deletion integration-tests/tests/src/hooks/open-realm-before.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ export function openRealmHook(config: LocalConfiguration | SyncedConfiguration =
} as Realm.Configuration;
this.realm = new Realm(this.config);
// Upload the schema, ensuring a valid connection
if (!this.realm.syncSession) {
throw new Error("No syncSession found on realm");
}
await this.realm.syncSession.uploadAllLocalChanges();
tomduncalf marked this conversation as resolved.
Show resolved Hide resolved
}
};
}

export function closeRealm(this: RealmContext): void {
export function closeRealm(this: Partial<RealmContext> & Mocha.Context): 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;
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/tests/src/tests/dynamic-schema-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ describe("realm._updateSchema", () => {
const updatedSchema = [...realm.schema];
// Locate the Dog schema
const dogSchema = updatedSchema.find((s) => s.name === "Dog");
if (!dogSchema) throw new Error("Schema not found");

// Add a fields property
dogSchema.properties.friends = "Dog[]";
// Update the schema
Expand Down
10 changes: 8 additions & 2 deletions integration-tests/tests/src/tests/iterators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,19 @@ describe("Iterating", () => {

describe("linkingObjects collections", () => {
itCanIterate(() => {
return realm.objectForPrimaryKey<IPerson>("Person", "Alice").dogs;
const result = realm.objectForPrimaryKey<IPerson>("Person", "Alice");
if (!result) throw new Error("Object not found");

return result.dogs;
}, ["Max", "Rex"]);
});

describe("lists", () => {
itCanIterate(() => {
return realm.objectForPrimaryKey<IPerson>("Person", "Bob").friends;
const result = realm.objectForPrimaryKey<IPerson>("Person", "Bob");
if (!result) throw new Error("Object not found");

return result.friends;
}, ["Charlie"]);
});
});
27 changes: 12 additions & 15 deletions integration-tests/tests/src/tests/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ describe("Realm objects", () => {
describe("Interface & object literal", () => {
it("can be created", () => {
const realm = new Realm({ schema: [PersonSchema] });
let john: IPerson;

realm.write(() => {
john = realm.create<IPerson>(PersonSchema.name, {
const john = realm.write(() => {
return realm.create<IPerson>(PersonSchema.name, {
name: "John Doe",
age: 42,
});
Expand All @@ -51,10 +50,9 @@ describe("Realm objects", () => {

it("can have it's properties read", () => {
const realm = new Realm({ schema: [PersonSchema] });
let john: IPerson;

realm.write(() => {
john = realm.create<IPerson>(PersonSchema.name, {
const john = realm.write(() => {
return realm.create<IPerson>(PersonSchema.name, {
name: "John Doe",
age: 42,
});
Expand All @@ -77,6 +75,7 @@ describe("Realm objects", () => {
});

const john = realm.objectForPrimaryKey<IPersonWithId>(PersonSchemaWithId.name, _id);
if (!john) throw new Error("Object not found");
takameyer marked this conversation as resolved.
Show resolved Hide resolved

expect(john).instanceOf(Realm.Object);
expect(john._id.equals(_id)).equals(true);
Expand All @@ -86,11 +85,10 @@ describe("Realm objects", () => {

it("can be updated", () => {
const realm = new Realm({ schema: [PersonSchemaWithId] });
let john: IPersonWithId;
const _id = new Realm.BSON.ObjectId();

realm.write(() => {
john = realm.create<IPersonWithId>(PersonSchemaWithId.name, {
const john = realm.write(() => {
return realm.create<IPersonWithId>(PersonSchemaWithId.name, {
_id,
name: "John Doe",
age: 42,
Expand Down Expand Up @@ -160,10 +158,9 @@ describe("Realm objects", () => {
describe("Class Model", () => {
it("can be created", () => {
const realm = new Realm({ schema: [Person] });
let john: Person;

realm.write(() => {
john = realm.create(Person, {
const john = realm.write(() => {
return realm.create(Person, {
name: "John Doe",
age: 42,
});
Expand Down Expand Up @@ -202,6 +199,7 @@ describe("Realm objects", () => {
});

const john = realm.objectForPrimaryKey(PersonWithId, _id);
if (!john) throw new Error("Object not found");

expect(john).instanceOf(PersonWithId);
expect(john._id.equals(_id)).equals(true);
Expand All @@ -211,11 +209,10 @@ describe("Realm objects", () => {

it("can be updated", () => {
const realm = new Realm({ schema: [PersonWithId] });
let john: PersonWithId;
const _id = new Realm.BSON.ObjectId();

realm.write(() => {
john = realm.create(PersonWithId, {
const john = realm.write(() => {
return realm.create(PersonWithId, {
_id,
name: "John Doe",
age: 42,
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/tests/src/tests/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ describe("JSON serialization", () => {
afterEach(() => {
if (realm) {
realm.write(() => {
realm.deleteAll();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
realm!.deleteAll();
tomduncalf marked this conversation as resolved.
Show resolved Hide resolved
});
realm.close();
realm = null;
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/tests/src/tests/sync/mixed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ function describeRoundtrip(typeName: string, value: Value, testValue: ValueTeste

it("reads", function (this: RealmContext) {
const obj = this.realm.objectForPrimaryKey<MixedClass>("MixedClass", this._id);
if (!obj) throw new Error("Object not found");

expect(typeof obj).equals("object");
// Test the single value
performTest(obj.value, this.value);
Expand Down
10 changes: 10 additions & 0 deletions integration-tests/tests/src/tests/sync/upload-delete-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export function itUploadsDeletesAndDownloads(): void {
if (!this.realm) {
throw new Error("Expected a 'realm' on the mocha context");
}
if (!this.config) {
throw new Error("Expected a 'config' on the mocha context");
}
if (!this.realm.syncSession) {
throw new Error("Expected a 'syncSession' on the realm");
}

// Ensure everything has been uploaded
await this.realm.syncSession.uploadAllLocalChanges();
// Close, delete and download the Realm from the server
Expand All @@ -29,6 +36,9 @@ export function itUploadsDeletesAndDownloads(): void {
Realm.deleteFile(this.config);
// Re-open the Realm with the old configuration
this.realm = new Realm(this.config);
if (!this.realm.syncSession) {
throw new Error("Expected a 'syncSession' on the realm");
}
await this.realm.syncSession.downloadAllServerChanges();
});
}
3 changes: 2 additions & 1 deletion integration-tests/tests/src/utils/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export function itPerforms(title: string, fn: () => void, options?: Partial<Benc
maximumFractionDigits: 0,
});
const sd = Number(result.sd.toFixed(2));
this.test.title += ` (${ops} ops/sec, ±${sd}%)`;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.test!.title += ` (${ops} ops/sec, ±${sd}%)`;
tomduncalf marked this conversation as resolved.
Show resolved Hide resolved
this.result = result;
});
}
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"mocha",
"chai"
],
"noImplicitAny": true
"noImplicitAny": true,
"strictNullChecks": true
},
"include": [
"src/typings.d.ts",
Expand Down