diff --git a/dependencies.list b/dependencies.list index 5eecf97c..8a44bc5a 100644 --- a/dependencies.list +++ b/dependencies.list @@ -1,5 +1,5 @@ PACKAGE_NAME=realm-js VERSION=1.2.0 -REALM_CORE_VERSION=2.5.1 -REALM_SYNC_VERSION=1.5.0 +REALM_CORE_VERSION=2.6.0 +REALM_SYNC_VERSION=1.5.2 REALM_OBJECT_SERVER_VERSION=1.3.0 diff --git a/package.json b/package.json index 191b2f04..69634f05 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,8 @@ "scripts": { "get-version": "node -p process.env.npm_package_version", "set-version": "scripts/set-version.sh", - "get-core-version": "scripts/download-core.sh --version", - "get-sync-version": "scripts/download-core.sh --versionSync", + "get-core-version": "env-cmd ./dependencies.list node -p process.env.REALM_CORE_VERSION", + "get-sync-version": "env-cmd ./dependencies.list node -p process.env.REALM_SYNC_VERSION", "lint": "eslint", "test": "scripts/test.sh", "install": "node-pre-gyp install --fallback-to-build", @@ -63,7 +63,17 @@ "test-runner:jest": "cd tests/test-runners/jest && npm install && npm test", "test-runners": "npm run test-runner:ava && npm run test-runner:mocha && npm run test-runner:jest", "isMac": "node -p \"if (process.platform == 'darwin') { process.exit(0); } else { process.exit(-1); }\"", - "testMac": "npm run isMac -s && echo this is mac || echo . " + "testMac": "npm run isMac -s && echo this is mac || echo . ", + "isWin": "node -p \"if (process.platform == 'win32') { process.exit(0); } else { process.exit(-1); }\"", + "prealias:win:apply" : "git config alias.apply-win-symlink-aliases \"!f() { $(scripts/git-win-symlink-aliases); }; f\"", + "alias:win:apply" : "git apply-win-symlink-aliases", + "postalias:win:apply" : "git config --unset alias.apply-win-symlink-aliases", + "alias:win:revert" : "git config alias.rm-symlink \"\" && git config alias.rm-symlinks \"\" && git config alias.checkout-symlinks \"\"", + "win-fix-symlinks" : "npm run isWin -s && npm run alias:win:apply && git checkout-symlinks && git rm-symlinks || echo . ", + "win-revert-symlinks" : "npm run isWin -s && npm run alias:win:apply && git checkout-symlinks && npm run alias:win:revert || echo .", + "prereact-tests-android": "npm run isWin -s && npm run win-fix-symlinks || echo . ", + "react-tests-android": "node scripts/react-tests-android.js || npm run postreact-tests-android", + "postreact-tests-android": "npm run win-revert-symlinks" }, "dependencies": { "extract-zip": "^1.6.0", @@ -77,6 +87,7 @@ }, "devDependencies": { "babel-eslint": "^6.0.4", + "env-cmd": "^5.0.0", "eslint": "^3.2.2", "eslint-plugin-jasmine": "^2.1.0", "eslint-plugin-react": "^6.7.0", @@ -84,7 +95,9 @@ "license-checker": "^8.0.3", "mockery": "^2.0.0", "rimraf": "^2.6.1", - "semver": "^5.1.0" + "semver": "^5.1.0", + "shelljs": "^0.7.7", + "shx": "^0.2.2" }, "rnpm": { "ios": { diff --git a/react-native/android/build.gradle b/react-native/android/build.gradle index 020d8241..f0601c1b 100644 --- a/react-native/android/build.gradle +++ b/react-native/android/build.gradle @@ -32,9 +32,13 @@ import org.apache.tools.ant.filters.ReplaceTokens // We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk. // After that we build native code from src/main/jni with module path pointing at third-party-ndk. + ext.coreVersion = getDependenciesVersion("REALM_CORE_VERSION").trim() ext.syncVersion = getDependenciesVersion("REALM_SYNC_VERSION").trim() def currentVersion = getDependenciesVersion("VERSION").trim() +println "Realm Core Version: $ext.coreVersion" +println "Realm Sync Version: $ext.syncVersion" + def downloadsDir = new File("$projectDir/downloads") def jscDownloadDir = new File("$projectDir/src/main/jni/jsc") def coreDownloadDir = new File("$projectDir/src/main/jni") diff --git a/scripts/git-win-symlink-aliases b/scripts/git-win-symlink-aliases new file mode 100644 index 00000000..6f9e3388 --- /dev/null +++ b/scripts/git-win-symlink-aliases @@ -0,0 +1,39 @@ +#Based on http://stackoverflow.com/questions/5917249/git-symlinks-in-windows +git config alias.rm-symlink '!__git_rm_symlink(){ + git checkout -- "$1" + link=$(echo "$1") + POS=$'\''/'\'' + DOS=$'\''\\\\'\'' + doslink=${link//$POS/$DOS} + dest=$(dirname "$link")/$(cat "$link") + dosdest=${dest//$POS/$DOS} + if [ -f "$dest" ]; then + rm -f "$link" + cmd //C mklink //H "$doslink" "$dosdest" + elif [ -d "$dest" ]; then + rm -f "$link" + cmd //C mklink //J "$doslink" "$dosdest" + else + echo "ERROR: Something went wrong when processing $1 . . ." + echo " $dest may not actually exist as a valid target." + fi +}; __git_rm_symlink "$1"' + +git config alias.rm-symlinks '!__git_rm_symlinks(){ + for symlink in $(git ls-files -s | egrep "^120000" | cut -f2); do + git rm-symlink "$symlink" + git update-index --assume-unchanged "$symlink" + done +}; __git_rm_symlinks' + +git config alias.checkout-symlinks '!__git_checkout_symlinks(){ + POS=$'\''/'\'' + DOS=$'\''\\\\'\'' + for symlink in $(git ls-files -s | egrep "^120000" | cut -f2); do + git update-index --no-assume-unchanged "$symlink" + dossymlink=${symlink//$POS/$DOS} + cmd //C rmdir //Q "$dossymlink" 2>/dev/null + git checkout -- "$symlink" + echo "Restored git symlink $symlink <<===>> $(cat $symlink)" + done +}; __git_checkout_symlinks' \ No newline at end of file diff --git a/scripts/prepublish.js b/scripts/prepublish.js index 0c32e663..0a534c19 100644 --- a/scripts/prepublish.js +++ b/scripts/prepublish.js @@ -30,7 +30,7 @@ if ('REALM_BUILD_ANDROID' in process.env) { const gradlew = process.platform === 'win32' ? 'gradlew.bat' : 'gradlew'; const androidPath = path.resolve(__dirname, '../react-native/android'); - exec(`${androidPath}/${gradlew}`, ['publishAndroid', '-PbuildWithSync=true'], { cwd: androidPath, stdio: 'inherit' }); + exec(`${androidPath}/${gradlew}`, ['publishAndroid'], { cwd: androidPath, stdio: 'inherit' }); } function ini(string) { diff --git a/scripts/react-tests-android.js b/scripts/react-tests-android.js new file mode 100644 index 00000000..3edf421b --- /dev/null +++ b/scripts/react-tests-android.js @@ -0,0 +1,49 @@ +var shell = require("shelljs"); + +shell.set("-e"); + +shell.pushd("./tests/react-test-app"); + +shell.exec("npm install"); + +if (process.platform !== "win32") { + shell.env["PATH"] = "/opt/android-sdk-linux/platform-tools:$PATH" +} + +if (shell.env["REALM_BUILD_ANDROID"]) { + shell.echo("Realm is already installed"); +} else { + shell.env["REALM_BUILD_ANDROID"] = 1; + shell.exec("npm install realm"); + shell.exec("npm install realm-tests"); +} + +shell.cp("../../src/object-store/tests/query.json", "node_modules/realm-tests/query-tests.json"); + +shell.echo("Uninstalling old apk"); +shell.exec("adb uninstall io.realm.react.testapp"); + +shell.set("+e"); +shell.echo("Reversing port for physical device"); +shell.exec("adb reverse tcp:8081 tcp:8081"); + +shell.echo("Reversing port for Realm Object Server"); +shell.exec("adb reverse tcp:9080 tcp:9080"); + +shell.set("-e"); + +shell.echo("Building Release APK"); +shell.pushd("android"); +shell.exec("gradlew assembleRelease"); + +shell.echo("Installing APK"); +shell.exec("adb install app/build/outputs/apk/app-release.apk"); + +shell.echo("Starting the Main Activity"); +shell.exec("adb shell am start -n io.realm.react.testapp/.MainActivity"); + +shell.popd(); + +shell.exec("adb shell \"logcat -c && logcat | grep -m 1 __REALM_REACT_ANDROID_TESTS_COMPLETED__\""); + +shell.exec("adb pull /sdcard/tests.xml"); \ No newline at end of file diff --git a/src/js_sync.hpp b/src/js_sync.hpp index 369cfb5f..784c013a 100644 --- a/src/js_sync.hpp +++ b/src/js_sync.hpp @@ -123,7 +123,7 @@ void UserClass::create_user(ContextType ctx, FunctionType, ObjectType this_ob Value::validated_to_string(ctx, arguments[1]), Value::validated_to_string(ctx, arguments[2]), (std::string)Value::validated_to_string(ctx, arguments[0]), - Value::validated_to_boolean(ctx, arguments[3]))); + Value::validated_to_boolean(ctx, arguments[3]) ? SyncUser::TokenType::Admin : SyncUser::TokenType::Normal)); return_value.set(create_object>(ctx, user)); } diff --git a/src/object-store b/src/object-store index dd68cd72..91b460fa 160000 --- a/src/object-store +++ b/src/object-store @@ -1 +1 @@ -Subproject commit dd68cd727ae8702390f3231ef4df934fe214acd3 +Subproject commit 91b460fa5ad4083bdb5c59955cfd231bb2b25c54 diff --git a/tests/js/session-tests.js b/tests/js/session-tests.js index aa926053..c0f88575 100644 --- a/tests/js/session-tests.js +++ b/tests/js/session-tests.js @@ -42,10 +42,6 @@ function promisifiedRegister(server, username, password) { }); } -function wait(delay) { - return new Promise((resolve, reject) => setTimeout(resolve, delay)); -} - module.exports = { testLocalRealmHasNoSession() { let realm = new Realm(); @@ -55,13 +51,17 @@ module.exports = { testProperties() { return promisifiedRegister('http://localhost:9080', uuid(), 'password').then(user => { return new Promise((resolve, _reject) => { - const accessTokenRefreshed = Symbol(); - let session; + const accessTokenRefreshed = this; - let postTokenRefreshChecks = (sender, error) => { - TestCase.assertEqual(error, accessTokenRefreshed); - TestCase.assertEqual(session.url, `realm://localhost:9080/${user.identity}/myrealm`); - resolve(); + function postTokenRefreshChecks(sender, error) { + try { + TestCase.assertEqual(error, accessTokenRefreshed); + TestCase.assertEqual(sender.url, `realm://localhost:9080/${user.identity}/myrealm`); + resolve(); + } + catch (e) { + _reject(e) + } }; // Let the error handler trigger our checks when the access token was refreshed. @@ -69,7 +69,8 @@ module.exports = { const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm', error: postTokenRefreshChecks } }; const realm = new Realm(config); - session = realm.syncSession; + const session = realm.syncSession; + TestCase.assertInstanceOf(session, Realm.Sync.Session); TestCase.assertEqual(session.user.identity, user.identity); @@ -83,22 +84,23 @@ module.exports = { testErrorHandling() { return promisifiedRegister('http://localhost:9080', uuid(), 'password').then(user => { - let errors = []; - let config = { sync: { user, - url: 'realm://localhost:9080/~/myrealm', - error: (sender, error) => errors.push([sender, error]) - } }; - let realm = new Realm(config); - let session = realm.syncSession; + return new Promise((resolve, _reject) => { + const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } }; + config.sync.error = (sender, error) => { + try { + TestCase.assertEqual(error.message, 'simulated error'); + TestCase.assertEqual(error.code, 123); + resolve(); + } + catch (e) { + _reject(e); + } + }; + const realm = new Realm(config); + const session = realm.syncSession; - TestCase.assertEqual(session.config.error, config.sync.error); - session._simulateError(123, 'simulated error'); - - return wait(2000).then(() => { - TestCase.assertArrayLength(errors, 1); - TestCase.assertEqual(errors[0][0].config.url, session.config.url); - TestCase.assertEqual(errors[0][1].message, 'simulated error'); - TestCase.assertEqual(errors[0][1].code, 123); + TestCase.assertEqual(session.config.error, config.sync.error); + session._simulateError(123, 'simulated error'); }); }); } diff --git a/tests/spec/unit_tests.js b/tests/spec/unit_tests.js index 50f96172..d84d349c 100644 --- a/tests/spec/unit_tests.js +++ b/tests/spec/unit_tests.js @@ -27,7 +27,7 @@ const path = require('path'); const Realm = require('realm'); const RealmTests = require('../js'); -jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; +jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; // Create this method with appropriate implementation for Node testing. Realm.copyBundledRealmFiles = function() {