Merge remote-tracking branch 'origin/bridge-detox' into bridge-detox
This commit is contained in:
commit
58dc8a4cac
@ -10,7 +10,10 @@
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
# Default value: -Xmx10248m -XX:MaxPermSize=256m
|
||||
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
org.gradle.daemon=true
|
||||
org.gradle.parallel=true
|
||||
org.gradle.configureondemand=true
|
||||
org.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
@ -19,4 +22,3 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryErro
|
||||
|
||||
android.useDeprecatedNdk=true
|
||||
android.enableAapt2=false
|
||||
org.gradle.jvmargs=-Xmx1536M
|
||||
|
121
tests-new/bridge/env/node/index.js
vendored
121
tests-new/bridge/env/node/index.js
vendored
@ -1,72 +1,81 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
/* eslint-disable no-param-reassign,global-require */
|
||||
global.bridge = {};
|
||||
require('./source-map');
|
||||
|
||||
const detox = require('detox');
|
||||
const ws = require('./ws');
|
||||
const ready = require('./ready');
|
||||
const coverage = require('./coverage');
|
||||
|
||||
/* ---------------------
|
||||
* DEVICE OVERRIDES
|
||||
* --------------------- */
|
||||
let detox;
|
||||
try {
|
||||
detox = require('detox');
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
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();
|
||||
};
|
||||
if (detox) {
|
||||
/* ---------------------
|
||||
* DEVICE OVERRIDES
|
||||
* --------------------- */
|
||||
|
||||
// device.launchApp({ ... })
|
||||
const detoxOriginalLaunchApp = originalDevice.launchApp.bind(
|
||||
originalDevice
|
||||
);
|
||||
originalDevice.launchApp = async (...args) => {
|
||||
ready.reset();
|
||||
await detoxOriginalLaunchApp(...args);
|
||||
return ready.wait();
|
||||
};
|
||||
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 = originalDevice;
|
||||
return originalDevice;
|
||||
},
|
||||
});
|
||||
// device.launchApp({ ... })
|
||||
const detoxOriginalLaunchApp = originalDevice.launchApp.bind(
|
||||
originalDevice
|
||||
);
|
||||
originalDevice.launchApp = async (...args) => {
|
||||
ready.reset();
|
||||
await detoxOriginalLaunchApp(...args);
|
||||
return ready.wait();
|
||||
};
|
||||
|
||||
/* -------------------
|
||||
* DETOX OVERRIDES
|
||||
* ------------------- */
|
||||
device = originalDevice;
|
||||
return originalDevice;
|
||||
},
|
||||
});
|
||||
|
||||
// detox.init()
|
||||
const detoxOriginalInit = detox.init.bind(detox);
|
||||
detox.init = async (...args) => {
|
||||
ready.reset();
|
||||
await detoxOriginalInit(...args);
|
||||
return ready.wait();
|
||||
};
|
||||
/* -------------------
|
||||
* DETOX OVERRIDES
|
||||
* ------------------- */
|
||||
|
||||
// detox.cleanup()
|
||||
const detoxOriginalCleanup = detox.cleanup.bind(detox);
|
||||
detox.cleanup = async (...args) => {
|
||||
try {
|
||||
ws.close();
|
||||
} catch (e) {
|
||||
// do nothing
|
||||
}
|
||||
await detoxOriginalCleanup(...args);
|
||||
};
|
||||
// detox.init()
|
||||
const detoxOriginalInit = detox.init.bind(detox);
|
||||
detox.init = async (...args) => {
|
||||
ready.reset();
|
||||
await detoxOriginalInit(...args);
|
||||
return ready.wait();
|
||||
};
|
||||
|
||||
// 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();
|
||||
});
|
||||
if (global.after) {
|
||||
after(() => {
|
||||
coverage.collect();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
39
tests-new/bridge/env/node/source-map.js
vendored
39
tests-new/bridge/env/node/source-map.js
vendored
@ -1,12 +1,16 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
const Mocha = require('mocha');
|
||||
const ErrorStack = require('error-stack-parser');
|
||||
const { SourceMapConsumer } = require('source-map');
|
||||
/* eslint-disable no-param-reassign,global-require */
|
||||
let Mocha;
|
||||
try {
|
||||
Mocha = require('mocha');
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
let bundleFileName = null;
|
||||
const Runner = Mocha.Runner;
|
||||
let sourceMapConsumer = null;
|
||||
const originalFail = Runner.prototype.fail;
|
||||
|
||||
const ErrorStack = require('error-stack-parser');
|
||||
const { SourceMapConsumer } = require('source-map');
|
||||
|
||||
/**
|
||||
* Convert an error frame into a source mapped string
|
||||
@ -23,8 +27,13 @@ function frameToStr(parsed) {
|
||||
parsed.columnNumber})`;
|
||||
}
|
||||
|
||||
// override mocha fail so we can replace stack traces
|
||||
Runner.prototype.fail = function fail(test, error) {
|
||||
/**
|
||||
* Convert an errors stack frames to their original source mapped positions
|
||||
*
|
||||
* @param error
|
||||
* @return {*}
|
||||
*/
|
||||
function sourceMappedError(error) {
|
||||
const original = error.stack.split('\n');
|
||||
const parsed = ErrorStack.parse(error);
|
||||
|
||||
@ -37,10 +46,20 @@ Runner.prototype.fail = function fail(test, error) {
|
||||
}
|
||||
|
||||
error.stack = newStack.join('\n');
|
||||
return originalFail.call(this, test, error);
|
||||
};
|
||||
return error;
|
||||
}
|
||||
|
||||
if (Mocha) {
|
||||
// override mocha fail so we can replace stack traces
|
||||
const Runner = Mocha.Runner;
|
||||
const originalFail = Runner.prototype.fail;
|
||||
Runner.prototype.fail = function fail(test, error) {
|
||||
return originalFail.call(this, test, sourceMappedError(error));
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sourceMappedError,
|
||||
/**
|
||||
* Build a source map consumer from source map bundle contents
|
||||
* @param str
|
||||
|
4
tests-new/bridge/env/node/vm.js
vendored
4
tests-new/bridge/env/node/vm.js
vendored
@ -87,7 +87,7 @@ module.exports = {
|
||||
|
||||
case EXECUTE: {
|
||||
const script = await getBundle(request);
|
||||
if (global.bridge.context == null) {
|
||||
if (global.bridge.context === null) {
|
||||
throw new Error('VM context was not prepared.');
|
||||
}
|
||||
if (request.inject) {
|
||||
@ -105,7 +105,7 @@ module.exports = {
|
||||
let returnValue = [[], [], [], 0];
|
||||
try {
|
||||
if (
|
||||
global.bridge.context != null &&
|
||||
global.bridge.context !== null &&
|
||||
typeof global.bridge.context.__fbBatchedBridge === 'object'
|
||||
) {
|
||||
returnValue = global.bridge.context.__fbBatchedBridge[method].apply(
|
||||
|
Loading…
x
Reference in New Issue
Block a user