From 966c808aa31e5243d2d9d98c8a98b1317d9fc756 Mon Sep 17 00:00:00 2001 From: Salakar Date: Sat, 24 Mar 2018 07:09:45 +0000 Subject: [PATCH] [tests] new test infra - wip --- tests-new/bridge/env/node/vm.js | 60 ++++++++++++++++----------------- tests-new/bridge/env/rn.js | 9 +++++ tests-new/package-lock.json | 5 +++ tests-new/package.json | 1 + 4 files changed, 44 insertions(+), 31 deletions(-) diff --git a/tests-new/bridge/env/node/vm.js b/tests-new/bridge/env/node/vm.js index 53f7d235..24de3ea0 100644 --- a/tests-new/bridge/env/node/vm.js +++ b/tests-new/bridge/env/node/vm.js @@ -3,8 +3,10 @@ const http = require('http'); const invariant = require('assert'); const { createContext, Script } = require('vm'); const ws = require('./ws'); +const { merge } = require('deeps'); -global.context = null; +global.bridge.context = null; +global.__coverage__ = {}; let scriptCached = null; // this is a dummy file path - without a file name the source map is not used in the vm @@ -135,33 +137,36 @@ process.on('ws-message', request => { // console.log(request.method); switch (request.method) { case 'prepareJSRuntime': - if (global.context) { + if (global.bridge.context) { + // todo __coverage__ not working - mostly empty statements in output + merge(global.__coverage__, global.bridge.context.__coverage__ || {}); + try { - for (const name in global.context.__fbBatchedBridge) { - global.context.__fbBatchedBridge[name] = undefined; - delete global.context.__fbBatchedBridge[name]; + for (const name in global.bridge.context.__fbBatchedBridge) { + global.bridge.context.__fbBatchedBridge[name] = undefined; + delete global.bridge.context.__fbBatchedBridge[name]; } - for (const name in global.context.__fbGenNativeModule) { - global.context.__fbGenNativeModule[name] = undefined; - delete global.context.__fbGenNativeModule[name]; + for (const name in global.bridge.context.__fbGenNativeModule) { + global.bridge.context.__fbGenNativeModule[name] = undefined; + delete global.bridge.context.__fbGenNativeModule[name]; } - for (const name in global.context.__fbBatchedBridgeConfig) { - global.context.__fbBatchedBridgeConfig[name] = undefined; - delete global.context.__fbBatchedBridgeConfig[name]; + for (const name in global.bridge.context.__fbBatchedBridgeConfig) { + global.bridge.context.__fbBatchedBridgeConfig[name] = undefined; + delete global.bridge.context.__fbBatchedBridgeConfig[name]; } - for (const name in global.context) { - global.context[name] = undefined; - delete global.context[name]; + for (const name in global.bridge.context) { + global.bridge.context[name] = undefined; + delete global.bridge.context[name]; } } catch (e) { console.error(e); } } - global.context = undefined; - global.context = createContext({ + global.bridge.context = undefined; + global.bridge.context = createContext({ console: consoleShim(), __bridgeNode: { ready() { @@ -184,12 +189,6 @@ process.on('ws-message', request => { global.bridge.root = rootComponent; }, }, - get __coverage__() { - return global.__coverage__; - }, - set __coverage__(val) { - return (global.__coverage__ = val); - }, }); sendResult(request.id); return; @@ -210,19 +209,19 @@ process.on('ws-message', request => { return; } - if (global.context == null) { + if (global.bridge.context == null) { sendError('JS runtime not prepared'); return; } if (request.inject) { for (const name in request.inject) { - global.context[name] = JSON.parse(request.inject[name]); + global.bridge.context[name] = JSON.parse(request.inject[name]); } } try { - script.runInContext(global.context, TEMP_BUNDLE_PATH); + script.runInContext(global.bridge.context, TEMP_BUNDLE_PATH); } catch (e) { sendError(e); } @@ -235,13 +234,12 @@ process.on('ws-message', request => { let returnValue = [[], [], [], 0]; try { if ( - global.context != null && - typeof global.context.__fbBatchedBridge === 'object' + global.bridge.context != null && + typeof global.bridge.context.__fbBatchedBridge === 'object' ) { - returnValue = global.context.__fbBatchedBridge[request.method].apply( - null, - request.arguments - ); + returnValue = global.bridge.context.__fbBatchedBridge[ + request.method + ].apply(null, request.arguments); } } catch (e) { if (request.method !== '$disconnected') { diff --git a/tests-new/bridge/env/rn.js b/tests-new/bridge/env/rn.js index e92599ca..acd02518 100644 --- a/tests-new/bridge/env/rn.js +++ b/tests-new/bridge/env/rn.js @@ -14,12 +14,21 @@ if (bridgeNode) { } export default { + /** + * Makes the main module to be tested accessible to nodejs + * @param moduleExports + */ provideModule(moduleExports) { if (bridgeNode) { bridgeNode.provideModule(moduleExports); bridgeNode.ready(); } }, + + /** + * Makes the root component accessible to nodejs - e.g. bridge.root.setState({ ... }); + * @param rootComponent + */ provideRoot(rootComponent) { if (bridgeNode) { bridgeNode.provideRoot(rootComponent); diff --git a/tests-new/package-lock.json b/tests-new/package-lock.json index a8b2ecd2..7fe5e53a 100644 --- a/tests-new/package-lock.json +++ b/tests-new/package-lock.json @@ -2330,6 +2330,11 @@ "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, + "deeps": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/deeps/-/deeps-1.4.4.tgz", + "integrity": "sha1-CRJrycesX2DIJ+EciQYa6bVyqWA=" + }, "define-properties": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.2.tgz", diff --git a/tests-new/package.json b/tests-new/package.json index f06c6fc5..ad88d3c0 100755 --- a/tests-new/package.json +++ b/tests-new/package.json @@ -15,6 +15,7 @@ "dependencies": { "babel-preset-es2015-mod": "^6.6.0", "babel-preset-es3": "^1.0.1", + "deeps": "^1.4.4", "detox": "^7.2.0", "mocha": "^4.0.1", "react": "^16.2.0",