wip
This commit is contained in:
parent
c94d408f1b
commit
b2ae5f857d
|
@ -93,3 +93,7 @@ Add `--inspect` to e2e/mocha.opts file
|
|||
To open node debugger tools on chrome navigate to chrome://inspect/#devices and click the `Open dedicated DevTools for Node` link.
|
||||
|
||||
Add the default connection of `localhost:9229` if you haven't already - then the debugger will automatically connect everytime you start tests with inspect flag.
|
||||
|
||||
#### Mocha options
|
||||
|
||||
See https://mochajs.org/#usage
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
* @flow
|
||||
*/
|
||||
|
||||
require('sinon');
|
||||
require('should-sinon');
|
||||
require('should');
|
||||
|
||||
// must import before all else
|
||||
import Bridge from './bridge/env/rn';
|
||||
|
||||
|
@ -15,7 +19,9 @@ import firebase from './firebase';
|
|||
class Root extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
this.state = {
|
||||
message: 'React Native Firebase Test App',
|
||||
};
|
||||
Bridge.provideRoot(this);
|
||||
Bridge.provideModule(firebase);
|
||||
}
|
||||
|
@ -23,7 +29,7 @@ class Root extends Component {
|
|||
render() {
|
||||
return (
|
||||
<View>
|
||||
<Text testID="tap">React Native Firebase Test App</Text>
|
||||
<Text testID="tap">{this.state.message}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
const detox = require('detox');
|
||||
const vm = require('./vm');
|
||||
const ws = require('./ws');
|
||||
global.bridge = {};
|
||||
|
||||
// TODO each reload/relaunch should capture __coverage__
|
||||
const detox = require('detox');
|
||||
|
||||
require('./vm');
|
||||
const ws = require('./ws');
|
||||
|
||||
const detoxOriginalInit = detox.init.bind(detox);
|
||||
const detoxOriginalCleanup = detox.cleanup.bind(detox);
|
||||
|
@ -21,7 +22,8 @@ function onceBridgeReady() {
|
|||
|
||||
function shimDevice() {
|
||||
// reloadReactNative
|
||||
const detoxOriginalReloadReactNative = device.reloadReactNative.bind(device);
|
||||
// todo detoxOriginalReloadReactNative currently broken
|
||||
// const detoxOriginalReloadReactNative = device.reloadReactNative.bind(device);
|
||||
device.reloadReactNative = async () => {
|
||||
bridgeReady = false;
|
||||
global.bridge.reload();
|
||||
|
@ -36,7 +38,7 @@ function shimDevice() {
|
|||
return onceBridgeReady();
|
||||
};
|
||||
|
||||
// todo other device methods
|
||||
// todo other device reloading related methods
|
||||
}
|
||||
|
||||
detox.init = async (...args) => {
|
||||
|
@ -51,12 +53,3 @@ detox.cleanup = async (...args) =>
|
|||
detoxOriginalCleanup(...args).then(() => {
|
||||
ws.close();
|
||||
});
|
||||
|
||||
global.bridge = {
|
||||
_ws: null,
|
||||
|
||||
rootSetState(state) {
|
||||
// todo
|
||||
return Promise.resolve();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -4,12 +4,23 @@ const invariant = require('assert');
|
|||
const { createContext, Script } = require('vm');
|
||||
const ws = require('./ws');
|
||||
|
||||
let currentContext = null;
|
||||
global.context = null;
|
||||
let scriptCached = null;
|
||||
|
||||
// this is a dummy file path - without a file name the source map is not used in the vm
|
||||
const TEMP_BUNDLE_PATH = '/tmp/bridge/react-native.js';
|
||||
|
||||
// TODO
|
||||
// TODO
|
||||
// TODO
|
||||
// TODO
|
||||
// TODO This is just dirty code created just as a proof of concept
|
||||
// TODO - need to cleanup
|
||||
// TODO
|
||||
// TODO
|
||||
// TODO
|
||||
// TODO
|
||||
|
||||
/**
|
||||
*
|
||||
* @param replyId
|
||||
|
@ -114,33 +125,33 @@ process.on('ws-message', request => {
|
|||
// console.log(request.method);
|
||||
switch (request.method) {
|
||||
case 'prepareJSRuntime':
|
||||
if (currentContext) {
|
||||
if (global.context) {
|
||||
try {
|
||||
for (const name in currentContext.__fbBatchedBridge) {
|
||||
currentContext.__fbBatchedBridge[name] = undefined;
|
||||
delete currentContext.__fbBatchedBridge[name];
|
||||
for (const name in global.context.__fbBatchedBridge) {
|
||||
global.context.__fbBatchedBridge[name] = undefined;
|
||||
delete global.context.__fbBatchedBridge[name];
|
||||
}
|
||||
|
||||
for (const name in currentContext.__fbGenNativeModule) {
|
||||
currentContext.__fbGenNativeModule[name] = undefined;
|
||||
delete currentContext.__fbGenNativeModule[name];
|
||||
for (const name in global.context.__fbGenNativeModule) {
|
||||
global.context.__fbGenNativeModule[name] = undefined;
|
||||
delete global.context.__fbGenNativeModule[name];
|
||||
}
|
||||
|
||||
for (const name in currentContext.__fbBatchedBridgeConfig) {
|
||||
currentContext.__fbBatchedBridgeConfig[name] = undefined;
|
||||
delete currentContext.__fbBatchedBridgeConfig[name];
|
||||
for (const name in global.context.__fbBatchedBridgeConfig) {
|
||||
global.context.__fbBatchedBridgeConfig[name] = undefined;
|
||||
delete global.context.__fbBatchedBridgeConfig[name];
|
||||
}
|
||||
|
||||
for (const name in currentContext) {
|
||||
currentContext[name] = undefined;
|
||||
delete currentContext[name];
|
||||
for (const name in global.context) {
|
||||
global.context[name] = undefined;
|
||||
delete global.context[name];
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
currentContext = undefined;
|
||||
currentContext = createContext({
|
||||
global.context = undefined;
|
||||
global.context = createContext({
|
||||
console: consoleShim(),
|
||||
__bridgeNode: {
|
||||
ready() {
|
||||
|
@ -182,19 +193,19 @@ process.on('ws-message', request => {
|
|||
return;
|
||||
}
|
||||
|
||||
if (currentContext == null) {
|
||||
if (global.context == null) {
|
||||
sendError('JS runtime not prepared');
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.inject) {
|
||||
for (const name in request.inject) {
|
||||
currentContext[name] = JSON.parse(request.inject[name]);
|
||||
global.context[name] = JSON.parse(request.inject[name]);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
script.runInContext(currentContext, TEMP_BUNDLE_PATH);
|
||||
script.runInContext(global.context, TEMP_BUNDLE_PATH);
|
||||
} catch (e) {
|
||||
sendError(e);
|
||||
}
|
||||
|
@ -207,10 +218,10 @@ process.on('ws-message', request => {
|
|||
let returnValue = [[], [], [], 0];
|
||||
try {
|
||||
if (
|
||||
currentContext != null &&
|
||||
typeof currentContext.__fbBatchedBridge === 'object'
|
||||
global.context != null &&
|
||||
typeof global.context.__fbBatchedBridge === 'object'
|
||||
) {
|
||||
returnValue = currentContext.__fbBatchedBridge[request.method].apply(
|
||||
returnValue = global.context.__fbBatchedBridge[request.method].apply(
|
||||
null,
|
||||
request.arguments
|
||||
);
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
const WebSocket = require('ws');
|
||||
|
||||
const ws = new WebSocket(
|
||||
// todo read url from somewhere
|
||||
'ws://' + 'localhost:8081' + '/debugger-proxy?role=debugger&name=Chrome'
|
||||
'ws://localhost:8081/debugger-proxy?role=debugger&name=Chrome'
|
||||
);
|
||||
|
||||
ws.onmessage = message => process.emit('ws-message', JSON.parse(message.data));
|
||||
// ws.onopen = () => console.log('WS open');
|
||||
ws.onclose = event => (!event.wasClean ? console.log('WS close', event) : '');
|
||||
|
||||
module.exports = ws;
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
import reactNative, { Platform, NativeModules } from 'react-native';
|
||||
import RNRestart from 'react-native-restart'; // Import package from node modules
|
||||
|
||||
require('sinon');
|
||||
require('should-sinon');
|
||||
require('should');
|
||||
|
||||
const bridgeNode = global.__bridgeNode;
|
||||
|
||||
// https://github.com/ptmt/react-native-macos/blob/master/React/Modules/RCTDevSettings.mm
|
||||
|
@ -35,4 +31,4 @@ export default {
|
|||
setInterval(() => {
|
||||
// I don't do anything lol
|
||||
// BUT i am needed - otherwise RN's batch bridge starts to hang in detox... ???
|
||||
}, 50);
|
||||
}, 60);
|
||||
|
|
|
@ -1,23 +1,8 @@
|
|||
const sinon = require('sinon');
|
||||
require('should-sinon');
|
||||
const should = require('should');
|
||||
|
||||
const randomString = (length, chars) => {
|
||||
let mask = '';
|
||||
if (chars.indexOf('a') > -1) mask += 'abcdefghijklmnopqrstuvwxyz';
|
||||
if (chars.indexOf('A') > -1) mask += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
if (chars.indexOf('#') > -1) mask += '0123456789';
|
||||
if (chars.indexOf('!') > -1) mask += '~`!@#$%^&*()_+-={}[]:";\'<>?,./|\\';
|
||||
let result = '';
|
||||
for (let i = length; i > 0; --i) {
|
||||
result += mask[Math.round(Math.random() * (mask.length - 1))];
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
describe('.auth()', () => {
|
||||
beforeEach(async () => {
|
||||
beforeEach(async function beforeEach() {
|
||||
await device.reloadReactNative();
|
||||
// just an example of setting the root components state from inside a test :)
|
||||
bridge.root.setState({ message: this.currentTest.title });
|
||||
});
|
||||
|
||||
describe('.signInAnonymously()', () => {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
const detox = require('detox');
|
||||
const config = require('../package.json').detox;
|
||||
global.sinon = require('sinon');
|
||||
require('should-sinon');
|
||||
global.should = require('should');
|
||||
|
||||
before(async () => {
|
||||
await detox.init(config);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
--recursive
|
||||
--timeout 120000
|
||||
--slow 1200
|
||||
--slow 1400
|
||||
--bail
|
||||
--exit
|
||||
--require ./bridge/env/node
|
||||
|
|
Loading…
Reference in New Issue