realm-js icon indicating copy to clipboard operation
realm-js copied to clipboard

TypeError: externalRealm.syncSession.uploadAllLocalChanges is not a function

Open tkaye407 opened this issue 5 years ago • 4 comments

Goals

I am trying to await the uploading of all changes

Expected Results

Expected it to upload all of the changes

Actual Results

TypeError: externalRealm.syncSession.uploadAllLocalChanges is not a function

Steps to Reproduce

Open a synced realm, and call realm.syncSession.uploadAllChanges()

Code Sample

externalRealm.syncSession.uploadAllLocalChanges()

Version of Realm and Tooling

  • Realm JS SDK Version: 2.29.2
  • Node or React Native: v10.16.0
  • Client OS & Version: Mac
  • Which debugger for React Native: ?/None

tkaye407 avatar Aug 21 '19 12:08 tkaye407

As we have a test of uploadAllLocalChanges(), we need to be able to reproduce it. Moreover, I routinely use the method (and its twin downloadAllServerChanges()) in small scripts and apps.

kneth avatar Aug 22 '19 07:08 kneth

We no longer experience this issue, since we modified our jest environment to use jest-environment-node, so I'll close this.

adamchel avatar Nov 20 '19 12:11 adamchel

➤ Unito Sync Bot commented:

Transition made by Unito

RealmBot avatar Nov 20 '19 12:11 RealmBot

We no longer experience this issue, since we modified our jest environment to use jest-environment-node, so I'll close this.

We aren't using jest-environment-node as-is but are instead doing the following in order to use script.runInThisContext() instead of script.runInContext().

// Adapted from https://github.com/facebook/jest/issues/2549#issuecomment-521250266.
//
// Note that this must be a JavaScript module until jest supports transforms on the
// "testEnvironment" configuration option to allow transparently converting it from TypeScript.
// See https://github.com/facebook/jest/issues/8479 for more details.
const NodeEnvironment = require('jest-environment-node');

module.exports = class extends NodeEnvironment {
  constructor(config) {
    super(config);
    this.global = global;
  }

  runScript(script) {
    return script.runInThisContext();
  }
};

As I mentioned in my comment in https://github.com/realm/realm-js/issues/1096#issuecomment-542741556, this issue isn't specific to jest and is a problem with how Realm fails to install prototypes correctly when the module is loaded in a separate VM context.

visemet avatar Nov 20 '19 13:11 visemet