react-native-firebase/tests-new/bridge/env/node/index.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-03-24 06:31:04 +00:00
global.bridge = {};
2018-03-24 02:02:59 +00:00
const detox = require('detox');
2018-03-24 06:31:04 +00:00
require('./vm');
const ws = require('./ws');
2018-03-24 05:53:49 +00:00
2018-03-24 02:02:59 +00:00
const detoxOriginalInit = detox.init.bind(detox);
const detoxOriginalCleanup = detox.cleanup.bind(detox);
let bridgeReady = false;
process.on('rn-ready', () => {
bridgeReady = true;
});
function onceBridgeReady() {
if (bridgeReady) return Promise.resolve();
return new Promise(resolve => {
process.once('rn-ready', resolve);
});
}
2018-03-24 05:53:49 +00:00
function shimDevice() {
// reloadReactNative
2018-03-24 06:31:04 +00:00
// todo detoxOriginalReloadReactNative currently broken
// const detoxOriginalReloadReactNative = device.reloadReactNative.bind(device);
2018-03-24 05:53:49 +00:00
device.reloadReactNative = async () => {
bridgeReady = false;
global.bridge.reload();
return onceBridgeReady();
};
2018-03-24 02:02:59 +00:00
2018-03-24 05:53:49 +00:00
// launchApp
const detoxOriginalLaunchApp = device.launchApp.bind(device);
device.launchApp = async (...args) => {
bridgeReady = false;
await detoxOriginalLaunchApp(...args);
return onceBridgeReady();
};
2018-03-24 02:02:59 +00:00
2018-03-24 06:31:04 +00:00
// todo other device reloading related methods
2018-03-24 05:53:49 +00:00
}
2018-03-24 02:02:59 +00:00
2018-03-24 05:53:49 +00:00
detox.init = async (...args) => {
bridgeReady = false;
return detoxOriginalInit(...args).then(() => {
shimDevice();
2018-03-24 02:02:59 +00:00
return onceBridgeReady();
});
};
2018-03-24 05:53:49 +00:00
detox.cleanup = async (...args) =>
detoxOriginalCleanup(...args).then(() => {
2018-03-24 02:02:59 +00:00
ws.close();
});