How to use the realm.copyBundledRealmFiles function in realm

To help you get started, we’ve selected a few realm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github realm / realm-js / tests / electron / spec.js View on Github external
assert.equal(Realm.name, "Realm");
  });

  /*
  it("fails", (done) => {
    assert(false);
  });
  */
});

// Almost a copy-paste from the ../spec/unit_tests.js - so it might be possible to generalize.

// Setting the timeout to the same as the ../../spec/unit_tests.js
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;

Realm.copyBundledRealmFiles = function() {
  const sourceDir = path.join(__dirname, '../data');
  const destinationDir = path.dirname(Realm.defaultPath);

  for (let filename of fs.readdirSync(sourceDir)) {
    let src = path.join(sourceDir, filename);
    let dest = path.join(destinationDir, filename);

    // If the destination file already exists, then don't overwrite it.
    try {
        fs.accessSync(dest);
        continue;
    } catch (e) {}

    fs.writeFileSync(dest, fs.readFileSync(src));
  }
};
github realm / realm-js / tests / spec / unit_tests.js View on Github external
RealmLogging.patch(Realm);

const RealmTests = require('../js');

jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
let isDebuggerAttached = typeof v8debug === 'object';
if (!isDebuggerAttached && isNodeProccess) {
    isDebuggerAttached = /--debug|--inspect/.test(process.execArgv.join(' '));
}

if (isDebuggerAttached) {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000000;
}

// Create this method with appropriate implementation for Node testing.
Realm.copyBundledRealmFiles = function () {
    let sourceDir = path.join(__dirname, '../data');
    let destinationDir = path.dirname(Realm.defaultPath);

    for (let filename of fs.readdirSync(sourceDir)) {
        let src = path.join(sourceDir, filename);
        let dest = path.join(destinationDir, filename);

        // If the destination file already exists, then don't overwrite it.
        try {
            fs.accessSync(dest);
            continue;
        } catch (e) { }

        fs.writeFileSync(dest, fs.readFileSync(src));
    }
};
github realm / realm-js / tests / js / realm-tests.js View on Github external
testCopyBundledRealmFiles: function() {
        Realm.copyBundledRealmFiles();

        let realm = new Realm({path: 'dates-v5.realm', schema: [schemas.DateObject]});
        TestCase.assertEqual(realm.objects('Date').length, 2);
        TestCase.assertEqual(realm.objects('Date')[0].currentDate.getTime(), 1462500087955);

        const newDate = new Date(1);
        realm.write(() => {
            realm.objects('Date')[0].currentDate = newDate;
        });
        realm.close();

        // copy should not overwrite existing files
        Realm.copyBundledRealmFiles();
        realm = new Realm({path: 'dates-v5.realm', schema: [schemas.DateObject]});
        TestCase.assertEqual(realm.objects('Date')[0].currentDate.getTime(), 1);
    },
github realm / realm-js / tests / js / object-tests.js View on Github external
testDates: function() {
        Realm.copyBundledRealmFiles();

        // test file format upgrade
        var realm_v3 = new Realm({path: 'dates-v3.realm', schema: [schemas.DateObject]});
        TestCase.assertEqual(realm_v3.objects('Date').length, 2);
        TestCase.assertEqual(realm_v3.objects('Date')[0].currentDate.getTime(), 1462500087955);
        TestCase.assertEqual(realm_v3.objects('Date')[0].nullDate.getTime(), 1462500087955);
        TestCase.assertEqual(realm_v3.objects('Date')[1].currentDate.getTime(), -10000);
        TestCase.assertEqual(realm_v3.objects('Date')[1].nullDate, null);

        // get new file format is not upgraded
        var realm_v5 = new Realm({path: 'dates-v5.realm', schema: [schemas.DateObject]});
        TestCase.assertEqual(realm_v5.objects('Date').length, 2);
        TestCase.assertEqual(realm_v3.objects('Date')[0].currentDate.getTime(), 1462500087955);
        TestCase.assertEqual(realm_v3.objects('Date')[0].nullDate.getTime(), 1462500087955);
        TestCase.assertEqual(realm_v3.objects('Date')[1].currentDate.getTime(), -10000);
        TestCase.assertEqual(realm_v3.objects('Date')[1].nullDate, null);
github realm / realm-js / tests / js / session-tests.js View on Github external
testIncompatibleSyncedRealmConsructor() {
        let realm = "sync-v1.realm";
        if (isNodeProcess) {
            realm = copyFileToTempDir(path.join(process.cwd(), "data", realm));
        }
        else {
            //copy the bundled RN realm files for the test
            Realm.copyBundledRealmFiles();
        }

        return Realm.Sync.User.login('http://127.0.0.1:9080', Realm.Sync.Credentials.anonymous()).then(user => {
            return new Promise((resolve, _reject) => {
                    const config = {
                        path: realm,
                        sync: {
                            user,
                            error : err => console.log(err),
                            url: 'realm://127.0.0.1:9080/~/sync-v1'
                        }
                    };

                    try {
                        const realm = new Realm(config);
                        _reject("Should fail with IncompatibleSyncedRealmError");