2018-04-12 07:13:29 +00:00
|
|
|
/* eslint-disable global-require */
|
2018-04-09 16:27:23 +00:00
|
|
|
global.sinon = require('sinon');
|
|
|
|
require('should-sinon');
|
|
|
|
global.should = require('should');
|
|
|
|
|
|
|
|
Object.defineProperty(global, 'firebase', {
|
|
|
|
get() {
|
|
|
|
return bridge.module;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-05-03 19:14:23 +00:00
|
|
|
// TODO move as part of bridge
|
|
|
|
const { Uint8Array } = global;
|
|
|
|
Object.defineProperty(global, 'Uint8Array', {
|
|
|
|
get() {
|
|
|
|
const { stack } = new Error();
|
|
|
|
if (
|
|
|
|
(stack.includes('Context.it') || stack.includes('Context.beforeEach')) &&
|
|
|
|
global.bridge &&
|
|
|
|
global.bridge.context
|
|
|
|
) {
|
|
|
|
return bridge.context.window.Uint8Array;
|
|
|
|
}
|
|
|
|
return Uint8Array;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO move as part of bridge
|
|
|
|
const { Array } = global;
|
|
|
|
Object.defineProperty(global, 'Array', {
|
|
|
|
get() {
|
|
|
|
const { stack } = new Error();
|
|
|
|
if (
|
|
|
|
(stack.includes('Context.it') || stack.includes('Context.beforeEach')) &&
|
|
|
|
global.bridge &&
|
|
|
|
global.bridge.context
|
|
|
|
) {
|
|
|
|
return bridge.context.window.Array;
|
|
|
|
}
|
|
|
|
return Array;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-04-22 15:04:35 +00:00
|
|
|
global.isObject = function isObject(item) {
|
|
|
|
return item
|
|
|
|
? typeof item === 'object' && !Array.isArray(item) && item !== null
|
|
|
|
: false;
|
|
|
|
};
|
|
|
|
|
2018-04-09 16:27:23 +00:00
|
|
|
global.sleep = duration =>
|
|
|
|
new Promise(resolve => setTimeout(resolve, duration));
|
|
|
|
|
|
|
|
global.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;
|
|
|
|
};
|
2018-05-03 19:14:23 +00:00
|
|
|
global.testRunId = randomString(4, 'aA#');
|
2018-04-09 16:27:23 +00:00
|
|
|
|
2018-05-03 19:14:23 +00:00
|
|
|
/** ------------------
|
|
|
|
* Init WEB SDK
|
|
|
|
---------------------*/
|
2018-04-09 16:27:23 +00:00
|
|
|
|
2018-05-03 19:14:23 +00:00
|
|
|
/** ------------------
|
|
|
|
* Init ADMIN SDK
|
|
|
|
---------------------*/
|
|
|
|
global.firebaseAdmin = require('firebase-admin');
|
2018-04-12 07:13:29 +00:00
|
|
|
|
2018-04-09 16:27:23 +00:00
|
|
|
firebaseAdmin.initializeApp({
|
|
|
|
credential: firebaseAdmin.credential.cert(require('./service-account')),
|
|
|
|
databaseURL: 'https://rnfirebase-b9ad4.firebaseio.com',
|
|
|
|
});
|
2018-04-09 19:11:49 +00:00
|
|
|
|
|
|
|
const originalLog = console.log;
|
|
|
|
console.log = (...args) => {
|
|
|
|
if (
|
|
|
|
args &&
|
|
|
|
args[0] &&
|
|
|
|
typeof args[0] === 'string' &&
|
2018-04-16 17:05:31 +00:00
|
|
|
(args[0].toLowerCase().includes('deprecated') ||
|
|
|
|
args[0].toLowerCase().includes('restrictions in the native sdk'))
|
2018-04-09 19:11:49 +00:00
|
|
|
) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return originalLog(...args);
|
|
|
|
};
|
2018-04-12 07:13:29 +00:00
|
|
|
|
|
|
|
global.TestHelpers = {
|
|
|
|
firestore: require('./firestore'),
|
2018-04-21 22:59:47 +00:00
|
|
|
database: require('./database'),
|
2018-04-12 07:13:29 +00:00
|
|
|
};
|