diff --git a/package.json b/package.json index afd5fa6e..e1a57f23 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "eslint-plugin-jasmine": "^2.1.0", "eslint-plugin-react": "^6.7.0", "jsdoc": "^3.4.0", + "mockery": "^2.0.0", "semver": "^5.1.0" }, "rnpm": { diff --git a/tests/js/async-tests.js b/tests/js/async-tests.js index 25a273b9..f5c0b759 100644 --- a/tests/js/async-tests.js +++ b/tests/js/async-tests.js @@ -29,7 +29,7 @@ function createNotificationTest(config, getObservable, addListener, removeListen return new Promise((resolve, reject) => { let realm = new Realm(config); let observable = getObservable(realm); - let worker = new Worker(__dirname + '/worker-tests-script.js', [require.resolve('realm')]); + let worker = new Worker(__dirname + '/worker-tests-script.js', [REALM_MODULE_PATH]); // Test will fail if it does not receive a change event within a second. let timer = setTimeout(() => { diff --git a/tests/package.json b/tests/package.json index a137ee93..35c19bb7 100644 --- a/tests/package.json +++ b/tests/package.json @@ -15,7 +15,6 @@ "scripts": { "test": "jasmine spec/unit_tests.js spec/sync_tests.js", "test-nosync": "jasmine spec/unit_tests.js", - "test-sync-integration": "jasmine spec/sync_integration_tests.js", - "postinstall": "rm -f node_modules/realm && ln -s ../.. node_modules/realm" + "test-sync-integration": "jasmine spec/sync_integration_tests.js" } } diff --git a/tests/spec/helpers/mock_realm.js b/tests/spec/helpers/mock_realm.js new file mode 100644 index 00000000..f5673be2 --- /dev/null +++ b/tests/spec/helpers/mock_realm.js @@ -0,0 +1,16 @@ +'use strict'; + +const mockery = require('mockery'); + +module.exports = function(realmModulePath) { + if (typeof REALM_MODULE_PATH !== 'undefined') + return; + + global.REALM_MODULE_PATH = realmModulePath; + + mockery.enable({ + warnOnReplace: false, + warnOnUnregistered: false + }); + mockery.registerSubstitute('realm', REALM_MODULE_PATH); +} diff --git a/tests/spec/helpers/setup-module-path.js b/tests/spec/helpers/setup-module-path.js new file mode 100644 index 00000000..faf32f4c --- /dev/null +++ b/tests/spec/helpers/setup-module-path.js @@ -0,0 +1,4 @@ +const mock_helper = require('./mock_realm') +const path = require('path'); + +mock_helper(path.resolve(__dirname, '../../..'))