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

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-03-24 02:02:59 +00:00
const detox = require('detox');
const vm = require('./vm');
const ws = require('./ws');
2018-03-24 05:53:49 +00:00
// TODO each reload/relaunch should capture __coverage__
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
const detoxOriginalReloadReactNative = device.reloadReactNative.bind(device);
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 05:53:49 +00:00
// todo other device methods
}
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();
});
global.bridge = {
_ws: null,
rootSetState(state) {
// todo
return Promise.resolve();
},
};