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

72 lines
1.6 KiB
JavaScript
Raw Normal View History

/* eslint-disable no-param-reassign */
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
const ws = require('./ws');
const ready = require('./ready');
const coverage = require('./coverage');
/* ---------------------
* DEVICE OVERRIDES
* --------------------- */
let device;
Object.defineProperty(global, 'device', {
get() {
return device;
},
set(originalDevice) {
// device.reloadReactNative({ ... })
// todo detoxOriginalReloadReactNative currently broken it seems
// const detoxOriginalReloadReactNative = originalDevice.reloadReactNative.bind(originalDevice);
originalDevice.reloadReactNative = async () => {
ready.reset();
global.bridge.reload();
return ready.wait();
};
// device.launchApp({ ... })
const detoxOriginalLaunchApp = originalDevice.launchApp.bind(
originalDevice
);
originalDevice.launchApp = async (...args) => {
ready.reset();
await detoxOriginalLaunchApp(...args);
return ready.wait();
};
device = originalDevice;
return originalDevice;
},
2018-03-24 02:02:59 +00:00
});
/* -------------------
* DETOX OVERRIDES
* ------------------- */
2018-03-24 02:02:59 +00:00
// detox.init()
const detoxOriginalInit = detox.init.bind(detox);
2018-03-24 05:53:49 +00:00
detox.init = async (...args) => {
ready.reset();
await detoxOriginalInit(...args);
return ready.wait();
2018-03-24 02:02:59 +00:00
};
// detox.cleanup()
const detoxOriginalCleanup = detox.cleanup.bind(detox);
detox.cleanup = async (...args) => {
try {
ws.close();
} catch (e) {
// do nothing
}
await detoxOriginalCleanup(...args);
};
// setup after hook to ensure final context coverage is captured
process.nextTick(() => {
after(() => {
coverage.collect();
});
});