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.
|
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.
|
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
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require('sinon');
|
||||||
|
require('should-sinon');
|
||||||
|
require('should');
|
||||||
|
|
||||||
// must import before all else
|
// must import before all else
|
||||||
import Bridge from './bridge/env/rn';
|
import Bridge from './bridge/env/rn';
|
||||||
|
|
||||||
@ -15,7 +19,9 @@ import firebase from './firebase';
|
|||||||
class Root extends Component {
|
class Root extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {};
|
this.state = {
|
||||||
|
message: 'React Native Firebase Test App',
|
||||||
|
};
|
||||||
Bridge.provideRoot(this);
|
Bridge.provideRoot(this);
|
||||||
Bridge.provideModule(firebase);
|
Bridge.provideModule(firebase);
|
||||||
}
|
}
|
||||||
@ -23,7 +29,7 @@ class Root extends Component {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<Text testID="tap">React Native Firebase Test App</Text>
|
<Text testID="tap">{this.state.message}</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
23
tests-new/bridge/env/node/index.js
vendored
23
tests-new/bridge/env/node/index.js
vendored
@ -1,8 +1,9 @@
|
|||||||
const detox = require('detox');
|
global.bridge = {};
|
||||||
const vm = require('./vm');
|
|
||||||
const ws = require('./ws');
|
|
||||||
|
|
||||||
// TODO each reload/relaunch should capture __coverage__
|
const detox = require('detox');
|
||||||
|
|
||||||
|
require('./vm');
|
||||||
|
const ws = require('./ws');
|
||||||
|
|
||||||
const detoxOriginalInit = detox.init.bind(detox);
|
const detoxOriginalInit = detox.init.bind(detox);
|
||||||
const detoxOriginalCleanup = detox.cleanup.bind(detox);
|
const detoxOriginalCleanup = detox.cleanup.bind(detox);
|
||||||
@ -21,7 +22,8 @@ function onceBridgeReady() {
|
|||||||
|
|
||||||
function shimDevice() {
|
function shimDevice() {
|
||||||
// reloadReactNative
|
// reloadReactNative
|
||||||
const detoxOriginalReloadReactNative = device.reloadReactNative.bind(device);
|
// todo detoxOriginalReloadReactNative currently broken
|
||||||
|
// const detoxOriginalReloadReactNative = device.reloadReactNative.bind(device);
|
||||||
device.reloadReactNative = async () => {
|
device.reloadReactNative = async () => {
|
||||||
bridgeReady = false;
|
bridgeReady = false;
|
||||||
global.bridge.reload();
|
global.bridge.reload();
|
||||||
@ -36,7 +38,7 @@ function shimDevice() {
|
|||||||
return onceBridgeReady();
|
return onceBridgeReady();
|
||||||
};
|
};
|
||||||
|
|
||||||
// todo other device methods
|
// todo other device reloading related methods
|
||||||
}
|
}
|
||||||
|
|
||||||
detox.init = async (...args) => {
|
detox.init = async (...args) => {
|
||||||
@ -51,12 +53,3 @@ detox.cleanup = async (...args) =>
|
|||||||
detoxOriginalCleanup(...args).then(() => {
|
detoxOriginalCleanup(...args).then(() => {
|
||||||
ws.close();
|
ws.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
global.bridge = {
|
|
||||||
_ws: null,
|
|
||||||
|
|
||||||
rootSetState(state) {
|
|
||||||
// todo
|
|
||||||
return Promise.resolve();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
55
tests-new/bridge/env/node/vm.js
vendored
55
tests-new/bridge/env/node/vm.js
vendored
@ -4,12 +4,23 @@ const invariant = require('assert');
|
|||||||
const { createContext, Script } = require('vm');
|
const { createContext, Script } = require('vm');
|
||||||
const ws = require('./ws');
|
const ws = require('./ws');
|
||||||
|
|
||||||
let currentContext = null;
|
global.context = null;
|
||||||
let scriptCached = null;
|
let scriptCached = null;
|
||||||
|
|
||||||
// this is a dummy file path - without a file name the source map is not used in the vm
|
// 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';
|
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
|
* @param replyId
|
||||||
@ -114,33 +125,33 @@ process.on('ws-message', request => {
|
|||||||
// console.log(request.method);
|
// console.log(request.method);
|
||||||
switch (request.method) {
|
switch (request.method) {
|
||||||
case 'prepareJSRuntime':
|
case 'prepareJSRuntime':
|
||||||
if (currentContext) {
|
if (global.context) {
|
||||||
try {
|
try {
|
||||||
for (const name in currentContext.__fbBatchedBridge) {
|
for (const name in global.context.__fbBatchedBridge) {
|
||||||
currentContext.__fbBatchedBridge[name] = undefined;
|
global.context.__fbBatchedBridge[name] = undefined;
|
||||||
delete currentContext.__fbBatchedBridge[name];
|
delete global.context.__fbBatchedBridge[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const name in currentContext.__fbGenNativeModule) {
|
for (const name in global.context.__fbGenNativeModule) {
|
||||||
currentContext.__fbGenNativeModule[name] = undefined;
|
global.context.__fbGenNativeModule[name] = undefined;
|
||||||
delete currentContext.__fbGenNativeModule[name];
|
delete global.context.__fbGenNativeModule[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const name in currentContext.__fbBatchedBridgeConfig) {
|
for (const name in global.context.__fbBatchedBridgeConfig) {
|
||||||
currentContext.__fbBatchedBridgeConfig[name] = undefined;
|
global.context.__fbBatchedBridgeConfig[name] = undefined;
|
||||||
delete currentContext.__fbBatchedBridgeConfig[name];
|
delete global.context.__fbBatchedBridgeConfig[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const name in currentContext) {
|
for (const name in global.context) {
|
||||||
currentContext[name] = undefined;
|
global.context[name] = undefined;
|
||||||
delete currentContext[name];
|
delete global.context[name];
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentContext = undefined;
|
global.context = undefined;
|
||||||
currentContext = createContext({
|
global.context = createContext({
|
||||||
console: consoleShim(),
|
console: consoleShim(),
|
||||||
__bridgeNode: {
|
__bridgeNode: {
|
||||||
ready() {
|
ready() {
|
||||||
@ -182,19 +193,19 @@ process.on('ws-message', request => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentContext == null) {
|
if (global.context == null) {
|
||||||
sendError('JS runtime not prepared');
|
sendError('JS runtime not prepared');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.inject) {
|
if (request.inject) {
|
||||||
for (const name in request.inject) {
|
for (const name in request.inject) {
|
||||||
currentContext[name] = JSON.parse(request.inject[name]);
|
global.context[name] = JSON.parse(request.inject[name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
script.runInContext(currentContext, TEMP_BUNDLE_PATH);
|
script.runInContext(global.context, TEMP_BUNDLE_PATH);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
sendError(e);
|
sendError(e);
|
||||||
}
|
}
|
||||||
@ -207,10 +218,10 @@ process.on('ws-message', request => {
|
|||||||
let returnValue = [[], [], [], 0];
|
let returnValue = [[], [], [], 0];
|
||||||
try {
|
try {
|
||||||
if (
|
if (
|
||||||
currentContext != null &&
|
global.context != null &&
|
||||||
typeof currentContext.__fbBatchedBridge === 'object'
|
typeof global.context.__fbBatchedBridge === 'object'
|
||||||
) {
|
) {
|
||||||
returnValue = currentContext.__fbBatchedBridge[request.method].apply(
|
returnValue = global.context.__fbBatchedBridge[request.method].apply(
|
||||||
null,
|
null,
|
||||||
request.arguments
|
request.arguments
|
||||||
);
|
);
|
||||||
|
4
tests-new/bridge/env/node/ws.js
vendored
4
tests-new/bridge/env/node/ws.js
vendored
@ -1,12 +1,10 @@
|
|||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
|
|
||||||
const ws = new WebSocket(
|
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.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) : '');
|
ws.onclose = event => (!event.wasClean ? console.log('WS close', event) : '');
|
||||||
|
|
||||||
module.exports = ws;
|
module.exports = ws;
|
||||||
|
6
tests-new/bridge/env/rn.js
vendored
6
tests-new/bridge/env/rn.js
vendored
@ -1,10 +1,6 @@
|
|||||||
import reactNative, { Platform, NativeModules } from 'react-native';
|
import reactNative, { Platform, NativeModules } from 'react-native';
|
||||||
import RNRestart from 'react-native-restart'; // Import package from node modules
|
import RNRestart from 'react-native-restart'; // Import package from node modules
|
||||||
|
|
||||||
require('sinon');
|
|
||||||
require('should-sinon');
|
|
||||||
require('should');
|
|
||||||
|
|
||||||
const bridgeNode = global.__bridgeNode;
|
const bridgeNode = global.__bridgeNode;
|
||||||
|
|
||||||
// https://github.com/ptmt/react-native-macos/blob/master/React/Modules/RCTDevSettings.mm
|
// https://github.com/ptmt/react-native-macos/blob/master/React/Modules/RCTDevSettings.mm
|
||||||
@ -35,4 +31,4 @@ export default {
|
|||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
// I don't do anything lol
|
// I don't do anything lol
|
||||||
// BUT i am needed - otherwise RN's batch bridge starts to hang in detox... ???
|
// 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()', () => {
|
describe('.auth()', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async function beforeEach() {
|
||||||
await device.reloadReactNative();
|
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()', () => {
|
describe('.signInAnonymously()', () => {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
const detox = require('detox');
|
const detox = require('detox');
|
||||||
const config = require('../package.json').detox;
|
const config = require('../package.json').detox;
|
||||||
|
global.sinon = require('sinon');
|
||||||
|
require('should-sinon');
|
||||||
|
global.should = require('should');
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
await detox.init(config);
|
await detox.init(config);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
--recursive
|
--recursive
|
||||||
--timeout 120000
|
--timeout 120000
|
||||||
--slow 1200
|
--slow 1400
|
||||||
--bail
|
--bail
|
||||||
|
--exit
|
||||||
--require ./bridge/env/node
|
--require ./bridge/env/node
|
||||||
|
Loading…
x
Reference in New Issue
Block a user