Use mockery in tests to setup the realm module path(#727)

* Use mockery to set up the realm module path

* Use the right path

* Add mockery to devDependencies

* Remove unnecessary symbolic link
This commit is contained in:
Radu Tutueanu 2016-12-09 09:05:15 +01:00 committed by GitHub
parent 8eb639678e
commit d7c44fa7e9
5 changed files with 23 additions and 3 deletions

View File

@ -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": {

View File

@ -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(() => {

View File

@ -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"
}
}

View File

@ -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);
}

View File

@ -0,0 +1,4 @@
const mock_helper = require('./mock_realm')
const path = require('path');
mock_helper(path.resolve(__dirname, '../../..'))