2
0
mirror of synced 2025-01-22 20:31:59 +00:00

[tests][bridge] added device time drift checks

This commit is contained in:
Salakar 2018-03-25 19:24:18 +01:00
parent 1572aa10a2
commit c69c6b9082
3 changed files with 34 additions and 2 deletions

View File

@ -3,8 +3,10 @@ global.bridge.context = null;
const consoleContext = require('./console');
const { createContext } = require('vm');
const chalk = require('chalk');
let customBridgeProps = [];
let driftCheckStart = null;
module.exports = {
/**
@ -58,6 +60,34 @@ module.exports = {
console: consoleContext(),
__bridgeNode: {
_ready() {
if (!driftCheckStart) {
driftCheckStart = Date.now();
global.bridge.context.__driftCheck(1);
} else {
setTimeout(() => process.emit('bridge-attached'), 1);
}
},
_callbackDriftCheck() {
const timeTaken = Date.now() - driftCheckStart;
if (timeTaken > 5000) {
console.log(
`${chalk.blue(
'[bridge] ⚠️ '
)} It looks like there's an issue with device timer performance...`
);
console.log(
`${chalk.blue(
'[bridge] ⚠️ '
)} You may experience slow testing times as a result - ensure your device date/time correctly matches your debugger machine.`
);
// todo android only
// fake the RN warning for this
global.bridge.context.console.warn(
`Debugger and device times have drifted. ` +
`Please correct this by running adb shell "date \`date +%m%d%H%M%Y.%S\`" on your debugger machine.`
);
}
setTimeout(() => process.emit('bridge-attached'), 1);
},

View File

@ -47,13 +47,11 @@ async function downloadBundle(bundleUrl) {
async function getBundle(request) {
if (bundle) return bundle;
console.log('');
console.log(
`${chalk.blue(
'[bridge]'
)} debugger has connected! Downloading app JS bundle...`
);
console.log('');
const parsedUrl = url.parse(request.url, true);
invariant(parsedUrl.query);

View File

@ -36,6 +36,10 @@ if (Platform.OS === 'ios' && !bridgeNode) {
}
}
global.__driftCheck = delay => {
setTimeout(bridgeNode._callbackDriftCheck, delay);
};
let hasInitialized = false;
export default {