UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

59 lines (58 loc) 2.58 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var ChildEndPoint_js_1 = require("../channel/ipc/ChildEndPoint.js"); var NodeJsPageRpc_js_1 = require("./NodeJsPageRpc.js"); var RequireInContext_js_1 = require("../util/helper/RequireInContext.js"); var vm = require('vm'); //--------------------------------------------------------------------------------- var NodeJsPageChildEndPoint = /** @class */ (function (_super) { __extends(NodeJsPageChildEndPoint, _super); function NodeJsPageChildEndPoint(config) { var _this = _super.call(this, config) || this; Object.assign(_this, config); return _this; } NodeJsPageChildEndPoint.prototype.doConnect = function (channel) { // relative to CanRequireInContext file this.projectContext = RequireInContext_js_1.requireInContext('../../../../siesta-nodejs-all.js'); var res = _super.prototype.doConnect.call(this, channel); this.sendMessage(NodeJsPageRpc_js_1.NodeJsIpcClienState.Ready); return res; }; NodeJsPageChildEndPoint.prototype.doProcessRawChannelMessage = function (message, envelop) { }; NodeJsPageChildEndPoint.prototype.doDispatchEnvelop = function (envelop) { var payload = envelop.payload; if (payload.type === NodeJsPageRpc_js_1.NodeJsIpcRpc.FunctionCall) { var rpcData = payload; var code = ';(' + rpcData.func.toString() + ')();'; var result = void 0; var exception = void 0; try { result = vm.runInContext(code, this.projectContext); } catch (e) { exception = e; } if (exception) this.replyWith(envelop, exception, true); else this.replyWith(envelop, result); } }; return NodeJsPageChildEndPoint; }(ChildEndPoint_js_1.ChildEndPoint)); exports.NodeJsPageChildEndPoint = NodeJsPageChildEndPoint;