diff --git a/scripts/test.sh b/scripts/test.sh index ebf4f6a9..daf019d5 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -18,16 +18,6 @@ PATH="$PWD/node_modules/.bin:$PATH" if [[ $TARGET = *-android ]]; then # Inform the prepublish script to build Android modules. export REALM_BUILD_ANDROID=1 -else - while pgrep -q Simulator; do - # Kill all the current simulator processes as they may be from a - # different Xcode version - pkill Simulator 2>/dev/null || true - # CoreSimulatorService doesn't exit when sent SIGTERM - pkill -9 Simulator 2>/dev/null || true - done - - DESTINATION="-destination id=$(xcrun simctl list devices | grep -v unavailable | grep -m 1 -o '[0-9A-F\-]\{36\}')" fi PACKAGER_OUT="$SRCROOT/packager_out.txt" @@ -40,6 +30,16 @@ cleanup() { rm -f "$PACKAGER_OUT" "$LOGCAT_OUT" } +kill_ios_simulator() { + while pgrep -q Simulator; do + # Kill all the current simulator processes as they may be from a + # different Xcode version + pkill Simulator 2>/dev/null || true + # CoreSimulatorService doesn't exit when sent SIGTERM + pkill -9 Simulator 2>/dev/null || true + done +} + open_chrome() { local dir for dir in "$HOME/Applications" "/Applications"; do @@ -64,8 +64,11 @@ start_packager() { done } -unlock_device() { - adb shell input keyevent 82 +xctest() { + kill_ios_simulator + + local dest="$(xcrun simctl list devices | grep -v unavailable | grep -m 1 -o '[0-9A-F\-]\{36\}')" + xcodebuild -scheme "$1" -configuration "$CONFIGURATION" -sdk iphonesimulator -destination id="$dest" build test } # Cleanup now and also cleanup when this script exits. @@ -91,7 +94,7 @@ case "$TARGET" in ;; "realmjs") pushd src/ios - xcodebuild -scheme RealmJS -configuration "$CONFIGURATION" -sdk iphonesimulator $DESTINATION build test + xctest RealmJS ;; "react-tests") pushd tests/react-test-app @@ -105,7 +108,7 @@ case "$TARGET" in start_packager pushd ios - xcodebuild -scheme ReactTestApp -configuration "$CONFIGURATION" -sdk iphonesimulator $DESTINATION build test + xctest ReactTestApp ;; "react-example") pushd examples/ReactExample @@ -119,7 +122,7 @@ case "$TARGET" in start_packager pushd ios - xcodebuild -scheme ReactExample -configuration "$CONFIGURATION" -sdk iphonesimulator $DESTINATION build test + xctest ReactExample ;; "react-tests-android") [[ $CONFIGURATION == 'Debug' ]] && exit 0 @@ -156,12 +159,13 @@ case "$TARGET" in "node") npm install scripts/download-core.sh + src/node/build-node.sh $CONFIGURATION - pushd src/node - bash build-node.sh $CONFIGURATION - popd + # Change to a temp directory. + cd "$(mktemp -q -d -t realm.node.XXXXXX)" + trap "rm -rf '$PWD'" EXIT - node tests + node "$SRCROOT/tests" ;; "object-store") pushd src/object-store diff --git a/src/node/build-node.sh b/src/node/build-node.sh index 101450ed..fbd41593 100755 --- a/src/node/build-node.sh +++ b/src/node/build-node.sh @@ -22,5 +22,6 @@ else fi # Link to the appropriate module in the build directory. -mkdir -p ../../build -ln -fs "build/$CONFIGURATION/realm.node" ../../build +cd ../.. +mkdir -p build +ln -fs "../src/node/build/$CONFIGURATION/realm.node" build/ diff --git a/tests/index.js b/tests/index.js index 67d9abc8..acc0576b 100644 --- a/tests/index.js +++ b/tests/index.js @@ -21,13 +21,35 @@ 'use strict'; +const fs = require('fs'); +const path = require('path'); const mockery = require('mockery'); function runTests() { + const Realm = require('realm'); const RealmTests = require('./js'); const testNames = RealmTests.getTestNames(); let passed = true; + // 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)); + } + }; + for (let suiteName in testNames) { console.log('Starting ' + suiteName);