Skip to content

Commit

Permalink
RJS-2636: Add progress notifications and tests (#6743)
Browse files Browse the repository at this point in the history
* wip

* WIP: useProgress

* update realm-core

* Use main

* Check sinon in CI

* remove beforeeach import

* Add manual closing

* Check CI fix

* Add better tests

* Delete

* test: update flexible.ts and sync-session.ts

* Add deprecation

* test: update flexible.ts

* Add new tests

* Readd newlines

* build: update package.json

* Fix

* build: update package.json

* build: update package.json

* Fix following tests

* update CHANGELOG.md

* Add assert for react native compatibility

* Check with more proper cleanup

* Check more proper cleanup

* Add waiting

* Fix tests

* Make tests less flakey

* Ensure clear state always

* Fix cleanup ordering for tests

* Remove clearing state

* Skip tests and see

* Downgrade sinon to support more platforms

* Fix lock file

* Unskip tests

* Use a timeout

* Skip more complex tests

* Readd simple test

* Fix file and specify subscription

* Use immediate stops

* Use a different path and remove subs

* Use a different path

* Move to after

* Use sinon-chai

* Do a test

* Don't skip test

* Use a different user

* Use one user for the test suite

* Don't use relalmOpen

* Clear beforeEach

* Manual unsubscribe

* Fix package lock

* Readd tests and manually unsubscribe

* Comment out unreliable tests

* Update progress listener token.

* Export and use 'isEstimateProgressNotificationCallback()'.

* Fix 'toBindingProgressNotificationCallback()'.

* Update API docs and export new public types.

* Make 'emitProgress()' a method.

* Fix binding to 'emitProgress()'.

* Allow PBS notifiers.

* Linting.

* Update tests with 'openRealmBeforeEach()' and 'authenticateUserBefore()'.

* Consistency updates.

* Update test assertions.

* Add comments about flakyness.

* Remove explicit 'realm.close()' in tests.

* Update name of token.

* Add comments.

* Update CHANGELOG.

Using link to the PR rather than the issue as we'll add more info there.

* Remove 'assert' library.

* Linting.

* Add 'util' dependency in test for 'sinon'.

Needed on iOS.

* Update link to preferred callback in docs.

---------

Co-authored-by: Kenneth Geisshirt <[email protected]>
Co-authored-by: LJ <[email protected]>
  • Loading branch information
3 people authored Jul 5, 2024
1 parent 7b6a79b commit b4fd42b
Show file tree
Hide file tree
Showing 12 changed files with 791 additions and 85 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
## vNext (TBD)

### Deprecations
* None
* The callback for `SyncSession.addProgressNotification` taking `transferred` and `transferable` arguments is deprecated and will be removed. See **Enhancements** below for the new callback supporting both Flexible Sync and Partition-Based Sync. ([#6743](https://github.com/realm/realm-js/pull/6743))

### Enhancements
* None
* Added progress notifications support for Flexible Sync using an `estimate` as the new callback argument. The `estimate` is roughly equivalent to an estimated value of `transferred / transferable` in the deprecated Partition-Based Sync callback. ([#6743](https://github.com/realm/realm-js/pull/6743))
```typescript
realm.syncSession?.addProgressNotification(
ProgressDirection.Upload,
ProgressMode.ReportIndefinitely,
(estimate) => console.log(`progress: ${estimate}/1.0`)
);
```

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ PODS:
- React-Core
- React-jsi
- ReactTestApp-Resources (1.0.0-dev)
- RealmJS (12.11.0):
- RealmJS (12.11.1):
- React
- RNFS (2.20.0):
- React-Core
Expand Down Expand Up @@ -1448,7 +1448,7 @@ SPEC CHECKSUMS:
ReactNativeHost: a365307db1ece0c4825b9d0f8b35de1bb2a61b0a
ReactTestApp-DevSupport: 9052e9a0ba3a96a3cc574ee66c7b6089ee76b341
ReactTestApp-Resources: d200e68756fa45c648f369210bd7ee0c14759f5a
RealmJS: 5f96d3e02420b5f579296c465a437f6e20026da9
RealmJS: ecd23895a68689ce2c048d28df3d699cf76cedb7
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Yoga: 348f8b538c3ed4423eb58a8e5730feec50bce372
Expand Down
7 changes: 6 additions & 1 deletion integration-tests/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
"@types/chai-as-promised": "^7.1.5",
"@types/jsrsasign": "^10.5.4",
"@types/mocha": "^10.0.0",
"@types/sinon": "9.0.5",
"@types/sinon-chai": "3.2.12",
"mocha": "^10.1.0",
"nyc": "^15.1.0",
"platform": "^1.3.6",
Expand All @@ -94,7 +96,10 @@
"chai": "4.3.6",
"chai-as-promised": "^7.1.1",
"jsrsasign": "^11.0.0",
"node-fetch": "^3.3.2"
"node-fetch": "^3.3.2",
"sinon": "9.2.4",
"sinon-chai": "3.7.0",
"util": "^0.12.5"
},
"files": [
"/src"
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/src/hooks/authenticate-user-before.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
////////////////////////////////////////////////////////////////////////////
import { Credentials } from "realm";

export function authenticateUserBefore(): void {
export function authenticateUserBefore({ reuse } = { reuse: true }): void {
before(authenticateUserBefore.name, async function (this: AppContext & Partial<UserContext>) {
this.longTimeout();
if (this.app) {
this.user = this.app.currentUser || (await this.app.logIn(Credentials.anonymous()));
this.user = this.app.currentUser || (await this.app.logIn(Credentials.anonymous(reuse)));
} else {
throw new Error("Missing app on context. Did you forget to use the importAppBefore hook?");
}
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/tests/src/setup-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import chai from "chai";
// See https://stackoverflow.com/a/45882252
chai.config.truncateThreshold = 0;

import sinonChai from "sinon-chai";
chai.use(sinonChai);

import chaiAsPromised from "chai-as-promised";
chai.use(chaiAsPromised);

Expand Down
Loading

0 comments on commit b4fd42b

Please sign in to comment.