kasmir
Version:
Amazing multi-browser automation tool
1,201 lines (972 loc) • 35.5 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 13);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.unserialize = exports.serialize = undefined;
var _serializeJavascript = __webpack_require__(2);
var serializer = _interopRequireWildcard(_serializeJavascript);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
var serialize = exports.serialize = function serialize(obj) {
return serializer.default(obj);
};
var unserialize = exports.unserialize = function unserialize(obj) {
return eval('(' + obj + ')');
};
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = require("path");
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = require("serialize-javascript");
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = require("events");
/***/ }),
/* 4 */,
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Runner = undefined;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _path = __webpack_require__(1);
var path = _interopRequireWildcard(_path);
var _serialize = __webpack_require__(0);
var _events = __webpack_require__(3);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// Currently there exists no reliable solution to collect coverage
// reports from the runner instance when spawning with child_process.
// But our integration tests in fact cover almost all of the lines here
// so it shouldn't be a problem
// istanbul ignore next
var Runner = function () {
function Runner(nwClient) {
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, Runner);
this.emitter = new _events.EventEmitter();
this.emitter.setMaxListeners(0);
this.instance = 0;
this.client = nwClient;
this.browser = nwClient.api;
this.config = config;
this.returns = [];
this.values = {};
this.started = false;
this.paused = false;
this.halted = false;
this.done = false;
this.reset();
this.clean();
}
// Reset runner state
_createClass(Runner, [{
key: 'reset',
value: function reset() {
this.actions = null;
this.currentAction = 0;
this.currentTask = 0;
this.currentId = null;
this.halted = false;
}
// Clean reports
}, {
key: 'clean',
value: function clean() {
this.reports = null;
this.reports = {
actions: [],
actionSummary: [],
tasks: [],
taskSummary: [],
errors: []
};
}
// Start client
}, {
key: 'start',
value: function start() {
if (this.started === false) {
this.client.start();
}
}
// Run these actions
}, {
key: 'run',
value: function run() {
var _this = this;
var actions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
// Get actions from first param
if (!this.actions) {
this.actions = actions;
}
// Reset paused status
this.paused = false;
return new Promise(function (resolve, reject) {
// Resolve immediately if actions not provided
if (_this.actions.length === 0) {
_this.done = true;
_this.message('No actions provided; run(actions=[]) is empty.', 2);
resolve(_this.reports);
}
var actionName = _this.getNextAction();
// Action function, halt
if (typeof actionName === 'function') {
_this.halted = true;
_this.browser.pause();
_this.emitter.emit('function', _this.currentAction);
_this.actionMessage('waiting for action function to finish', 'action_func');
_this.waitToContinue().then(function () {
_this.currentAction++;
_this.run(actions).then(resolve).catch(reject);
});
}
// Done with actions, pause running and resolve
else if (!actionName) {
_this.done = true;
_this.pauseRunning();
_this.reset();
_this.message('Done running actions.', 2);
resolve(_this.reports);
}
// Continue running actions
else {
var action = _this.config.actions[actionName];
// If action is not found in action templates, resolve immediately
if (!action) {
_this.actionMessage('not defined in any <config.actionsPath>/*.js', actionName);
resolve(_this.reports);
} else {
var tasks = action.tasks;
var actionReport = _this.makeActionReport(actionName);
_this.actionMessage('Start...', actionName);
// Run the current action tasks
_this.runActionTasks(actionName, tasks).then(
// Action succeeded
function () {
_this.collectAction(actionReport, 'success');
_this.actionMessage('completed SUCCESS', actionName);
_this.currentAction++;
},
// Action failed
function () {
_this.collectAction(actionReport, 'fail');
_this.actionMessage('FAILED', actionName);
_this.currentAction++;
// Resolve immediately if priority is higher than 0
if (typeof action.priority === 'number' && action.priority > 0) {
_this.currentAction = -1;
}
})
// After all tasks, zero current task and run next or fail
.then(function () {
_this.currentTask = 0;
_this.run(actions).then(resolve).catch(reject);
});
}
}
});
}
// Run all tasks in current action sequentially
}, {
key: 'runActionTasks',
value: function runActionTasks(actionName) {
var _this2 = this;
var tasks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
return new Promise(function (resolve, reject) {
// Resolve immediately if actions not provided
if (!tasks || Array.isArray(tasks) && tasks.length === 0) {
_this2.actionMessage('No tasks.', actionName);
resolve();
}
// Clone task from action tasklist by current index
var task = (0, _serialize.unserialize)((0, _serialize.serialize)(tasks[_this2.currentTask]));
// Previous task failed
if (_this2.currentTask < 0) {
_this2.actionMessage('Priority task FAILED', actionName, 3);
reject();
}
// Done with task, resolve
if (!task) {
_this2.actionMessage('DONE running tasks', actionName, 3);
resolve();
} else {
// Run the current action tasks
_this2.runTask(task, actionName).then(
// Task succeeded
function () {
_this2.taskMessage('completed SUCCESS', task.name);
_this2.currentTask++;
},
// Task failed
function () {
_this2.taskMessage('FAILED', task.name);
// Resolve immediately if priority is higher than 0
if (typeof task.priority === 'number' && task.priority > 0) {
_this2.currentTask = -1;
}
// Continue if priority is lower
else {
_this2.currentTask++;
}
})
// After all tasks, zero current task and run next or fail
.then(function () {
_this2.emitter.emit('status', _this2.reports);
_this2.runActionTasks(actionName, tasks).then(resolve, reject);
});
}
});
}
// Run a single task in action
}, {
key: 'runTask',
value: function runTask() {
var _this3 = this;
var task = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var actionName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
return new Promise(function (resolve, reject) {
// Resolve immediately if task not given
if (!task) {
resolve();
}
_this3.taskMessage('Start...', task.name);
task.startTime = _this3.getTimeMs();
task.args = _this3.getTaskArgs(task);
task.id = _this3.getRandomString();
task.action = actionName;
_this3.currentId = task.id;
// Start task handler
try {
if (typeof _this3[task.handler] === 'function') {
_this3[task.handler].apply(_this3, _toConsumableArray(task.args).concat([function (result) {
_this3.expect(task.expect, function (returnValue) {
// If we returned value from expect, we update the result
if (typeof returnValue !== 'undefined') {
result.value = returnValue;
}
_this3.collectResult(task, result, resolve, reject);
});
}]));
} else {
_this3.command(task.handler, task.args, function (result) {
_this3.collectResult(task, result, resolve, reject);
});
}
}
// Catch error when running task fails completely
catch (e) {
_this3.collectResult(task, {
state: 'fail',
error: e.message
}, resolve, reject);
}
});
}
// Collect task result
}, {
key: 'collectResult',
value: function collectResult(task, result, resolve, reject) {
var _this4 = this;
// If we return from doExecute, result.value will hold our custom success state
if (result && result.value && _typeof(result.value) === "object" && result.value.state) {
result = result.value;
}
// Add timing results to task to pass to collectTask
task.endTime = this.getTimeMs();
// Not all nightwatch actions return result for callback
this.collectTask(task, result || { state: "success" },
// Success
function () {
if (task.pause) {
_this4.browser.pause(Number(task.pause) + _this4.config.runner.timeouts.pauseAfter);
}
setTimeout(function () {
resolve();
}, Number(task.pause) || 1);
},
// Fail
function () {
// Priority tasks must not fail
if (typeof task.priority === 'number' && task.priority >= 1) {
reject();
} else {
resolve();
}
});
}
// Collect task
}, {
key: 'collectTask',
value: function collectTask(task, result, success, fail) {
// If we don't want to log reports, skip this
if (this.config.report === false) {
return result.state === 'success' ? success() : fail();
}
var report = this.makeTaskReport(result, task);
// Collect errors, returns error reason if in Selenium output
var errorReason = this.collectErrors(report, task, result);
// Collect screenshots from task
this.collectScreenshots(report, task);
// Push to tasks report
this.reports.tasks.push(report);
// Collect summaries if task failed
if (result.state !== 'success') {
this.collectTaskSummary(report, errorReason);
fail();
} else {
success();
}
}
// Collect report to actions and tasks
}, {
key: 'collectAction',
value: function collectAction(report, state) {
// If we don't want to log reports, skip this
if (this.config.report === false) {
return;
}
report.endTime = this.getTimeMs();
report.runTime = this.getTotalTime(report);
report.state = state;
// Push to actions report
this.reports.actions.push(report);
if (report.state !== 'success') {
this.reports.actionSummary.push(report);
}
}
// Collect summary report (summary of failed tasks)
}, {
key: 'collectTaskSummary',
value: function collectTaskSummary(report) {
var errorReason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
// If we got a error reason from selenium, show that in summary
if (errorReason) {
// Error might be in JSON format if returned directly from selenium;
// parse and get errorMessage
try {
errorReason = JSON.parse(errorReason).errorMessage;
} catch (e) {}
// pass silently
// Clone report to prevent modifying the original
var _report = JSON.parse(JSON.stringify(report));
_report.errorReason = errorReason;
this.reports.taskSummary.push(_report);
} else {
report.errorReason = null;
this.reports.taskSummary.push(report);
}
}
// Collect errors (extended error information)
}, {
key: 'collectErrors',
value: function collectErrors(report, task, result) {
// Short selenium error
var errorReason = null;
// If we returned an error with message (like from Selenium) we push to
// error summary and nullify report value
if (result.value && result.value.message) {
this.reports.errors.push({
id: report.id,
name: task.name,
message: result.value ? result.value.message || '' : ''
});
try {
errorReason = result.value.message.split('\n')[0];
} catch (e) {}
// Pass silently
// Don't show extended error messages in reports
report.value = null;
}
return errorReason;
}
// Collect screenshot images
}, {
key: 'collectScreenshots',
value: function collectScreenshots(report, task) {
// For screenshot handlers the default return value is the base64 embedded image
// config.result_settings.images === false tells us not to return the embed,
// so we default to path
if (task.handler === 'screenshot' && this.config.runner.result_settings.images === false) {
report.value = path.join(this.getScreenshotPath(), task.args[0] || 'screenshot.jpg');
}
}
// Make action report
}, {
key: 'makeActionReport',
value: function makeActionReport(actionName) {
return {
id: this.getRandomString(),
name: actionName,
state: null,
startTime: this.getTimeMs(),
endTime: 0,
runTime: 0,
error: null,
value: null
};
}
// Make task report
}, {
key: 'makeTaskReport',
value: function makeTaskReport(result, task) {
// Get total run time of task, taking into account pauses
var runTime = this.getTotalTime(task);
// Format report
return {
id: task.id,
action: task.action,
name: task.name,
state: result.state || 'fail',
startTime: task.startTime,
endTime: task.endTime,
runTime: runTime < 0 ? 0 : runTime,
error: result.error || null,
value: result.value || null,
args: task.args
};
}
// Wait till for halt status
}, {
key: 'waitToContinue',
value: function waitToContinue() {
var _this5 = this;
return new Promise(function (resolve, reject) {
var haltWait = setInterval(function () {
if (_this5.halted === false) {
clearInterval(haltWait);
resolve();
}
}, 50);
});
}
// Pause running
}, {
key: 'pauseRunning',
value: function pauseRunning(ms) {
var _this6 = this;
this.paused = true;
var resolution = 50;
var pauseTime = ms;
var pauseWait = setInterval(function () {
if (_this6.paused === false || typeof pauseTime === 'number' && pauseTime < 0) {
clearInterval(pauseWait);
} else {
_this6.browser.pause(resolution);
}
if (typeof pauseTime === 'number') pauseTime -= resolution;
}, resolution);
}
// Open URL
}, {
key: 'open',
value: function open(url, callback) {
this.browser.url(url).waitForElementVisible("body", this.config.runner.timeouts.pageLoad, callback).pause(this.config.runner.timeouts.pauseAfter);
}
// Write keys to element based on selector
}, {
key: 'write',
value: function write(element) {
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var callback = arguments[2];
if (typeof this[value] === "function") value = this[value]();
this.browser.sendKeys(element, value, callback).pause(this.config.runner.timeouts.pauseAfter);
}
// Click element based on selector
}, {
key: 'click',
value: function click(element, callback) {
this.browser.click(element, callback).pause(this.config.runner.timeouts.pauseAfter);
}
// Execute arbitrary javascript in browser context
}, {
key: 'execute',
value: function execute(func, args, callback) {
this.browser.execute(func, args, callback).pause(this.config.runner.timeouts.pauseAfter);
}
// Expect result from execute
}, {
key: 'expect',
value: function expect(prop, callback) {
var _this7 = this;
if (typeof prop !== 'string') return callback();
this.browser.execute(function (expectProp) {
var items = expectProp.split('.');
if (items.length === 2) {
return {
defined: typeof window[items[0]][items[1]] !== 'undefined',
value: window[items[0]][items[1]]
};
} else {
return {
defined: typeof window[items[0]] !== 'undefined',
value: window[items[0]]
};
}
}, [prop], function (result) {
if (result.value.defined === true) {
return callback(result.value.value);
} else {
return setTimeout(function () {
_this7.expect(prop, callback);
}, 50);
}
}).pause(50);
}
// Execute any nightwatch supported function
}, {
key: 'command',
value: function command(name, args, callback) {
var _browser;
(_browser = this.browser)[name].apply(_browser, [].concat(_toConsumableArray(args), [callback])).pause(this.config.runner.timeouts.pauseAfter);
}
// Switch tab
}, {
key: 'switchTab',
value: function switchTab(tabId, callback) {
this.browser.windowHandles(function (result) {
this.switchWindow(result.value[tabId]);
callback();
}).pause(this.config.runner.timeouts.pauseAfter);
}
// Do nothing task (used to create waitFor with task.pause)
}, {
key: 'doNothing',
value: function doNothing(callback) {
callback();
}
// Wait for element to be visible
}, {
key: 'waitForElement',
value: function waitForElement(element) {
var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
this.browser.waitForElementPresent(element, timeout, callback).pause(this.config.runner.timeouts.pauseAfter);
}
// Select frame
}, {
key: 'frame',
value: function frame() {
var _frame = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var callback = arguments[1];
this.browser.frame(_frame, callback);
}
// Resize browser window
}, {
key: 'resize',
value: function resize(width, height, callback) {
this.browser.resizeWindow(width, height);
if (typeof callback === 'function') {
return callback();
}
}
// Position browser
}, {
key: 'position',
value: function position(x, y, callback) {
this.browser.setWindowPosition(x, y);
if (typeof callback === 'function') {
return callback();
}
}
// Close client (=browser)
}, {
key: 'close',
value: function close(callback) {
this.browser.end(callback);
}
// Take screenshot and save to path
}, {
key: 'screenshot',
value: function screenshot() {
var param = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'screenshot.jpg';
var callback = arguments[1];
if (typeof param === "function") {
callback = param;
param = 'screenshot.jpg';
}
this.browser.saveScreenshot(path.join(this.getScreenshotPath(), param), callback).pause(this.config.runner.timeouts.pauseAfter);
}
// Add new actions when parent yields them from action function
}, {
key: 'addNewActions',
value: function addNewActions(newActions) {
this.actions = [].concat(_toConsumableArray(this.actions.slice(0, this.currentAction + 1)), _toConsumableArray(newActions), _toConsumableArray(this.actions.slice(this.currentAction + 1)));
}
// Get screenshot path
}, {
key: 'getScreenshotPath',
value: function getScreenshotPath() {
var env = 'default';
if (_typeof(this.config.browsers) === 'object' && Array.isArray(this.config.browsers)) {
env = this.config.browsers[this.instance];
}
return this.config.runner.test_settings[env].screenshots.path;
}
// Get next action name
}, {
key: 'getNextAction',
value: function getNextAction() {
var actionName = this.actions[this.currentAction];
// Multi client
if (Array.isArray(actionName)) {
actionName = this.actions[this.currentAction][this.instance];
}
// If action is function, we want to halt and let the Kasmir
// run the function for us
if (typeof actionName === 'function') {
return actionName;
}
if (typeof actionName !== 'string' && typeof actionName !== 'undefined') {
this.currentAction++;
return this.getNextAction();
}
return actionName;
}
// Get task arguments
}, {
key: 'getTaskArgs',
value: function getTaskArgs(task) {
var args = [];
if (Array.isArray(task.args)) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = task.args[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var arg = _step.value;
if (typeof arg === 'string') {
// If task arg starts with '_result.<index>', we take the argument
// from this.results
var resultsMatch = arg.match(/^_results\.([0-9]*)/);
// If task arg starts with '_values.<label>', we take the argument
// from this.values
var valuesMatch = arg.match(/^_values\.(.*)/);
// Handle results match
if (resultsMatch !== null) {
if (isNaN(parseInt(resultsMatch[1], 10)) === false) {
arg = this.results[parseInt(resultsMatch[1], 10)].toString();
}
}
// Handle values match
else if (valuesMatch !== null) {
if (this.values[valuesMatch[1]]) {
arg = this.values[valuesMatch[1]];
}
}
}
args.push(arg);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
return args;
}
// Get full report
}, {
key: 'getReport',
value: function getReport() {
return this.reports;
}
// Get action summary
}, {
key: 'getActionReport',
value: function getActionReport() {
return this.reports.actions;
}
// Get action summary
}, {
key: 'getActionSummary',
value: function getActionSummary() {
return this.reports.actionSummary;
}
// Get task summary
}, {
key: 'getTaskReport',
value: function getTaskReport() {
return this.reports.tasks;
}
// Get summary report
}, {
key: 'getTaskSummary',
value: function getTaskSummary() {
return this.reports.taskSummary;
}
// Get extended errors
}, {
key: 'getErrors',
value: function getErrors() {
return this.reports.errors;
}
// Get elapsed time
}, {
key: 'getTotalTime',
value: function getTotalTime(primitive) {
var t = primitive.endTime - primitive.startTime;
// Substract pause time if specified in task
if (typeof primitive.pause === 'number') return t - primitive.pause;
// Substract resolve wait time default 1ms
return t - 1;
}
// Get current unix timestamp in milliseconds
}, {
key: 'getTimeMs',
value: function getTimeMs() {
return new Date().getTime();
}
// Get time difference of now and unix ms timestamp
}, {
key: 'getTimeDiff',
value: function getTimeDiff(time) {
return this.getTimeMs() - time;
}
// Return a random string; for testing purposes
}, {
key: 'getRandomString',
value: function getRandomString() {
return Math.random().toString(36).substring(7);
}
// Return date string in format m:s:ms
}, {
key: 'getTimeDate',
value: function getTimeDate() {
var date = new Date();
var result = this.getZeroPadded(date.getHours(), 2) + ':';
result += this.getZeroPadded(date.getMinutes(), 2) + ':';
result += this.getZeroPadded(date.getSeconds(), 2) + ':';
result += '' + this.getZeroPadded(date.getMilliseconds(), 3);
return result;
}
// Pad number with leading zeros
}, {
key: 'getZeroPadded',
value: function getZeroPadded(number, size) {
var s = String(number);
while (s.length < (size || 2)) {
s = "0" + s;
}
return s;
}
// Output action message
}, {
key: 'actionMessage',
value: function actionMessage() {
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
var actionName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
var minVerbosity = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
this.message('ACTION: \'' + actionName + '\' ' + text, minVerbosity);
}
// Output task message
}, {
key: 'taskMessage',
value: function taskMessage() {
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
var taskName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
var minVerbosity = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3;
this.message('- task \'' + taskName + '\' => ' + text, minVerbosity);
}
// Output a message
}, {
key: 'message',
value: function message() {
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
var minVerbosity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
// Check verbosity level and that text is not empty
if (this.config.verbosity < minVerbosity || !text) {
return;
}
// Add some padding for uniform line lengths
var pad = " ".repeat(text.length > 60 ? 0 : 60 - text.length);
// Output with colors
if (this.config.runner.colors) {
text = text.replace("ACTION:", "\x1b[1;37mACTION:\x1b[0m");
text = text.replace("- task", "\x1b[0;33m- task\x1b[0m");
text = text.replace("SUCCESS", pad + '\x1B[0;42m SUCCESS \x1B[0m');
text = text.replace("FAILED", pad + '\x1B[0;45m FAILED \x1B[0m');
}
console.log('<' + this.instance + '-' + this.getTimeDate() + '> ' + text);
}
}]);
return Runner;
}();
exports.Runner = Runner;
/***/ }),
/* 6 */,
/* 7 */,
/* 8 */
/***/ (function(module, exports) {
module.exports = require("nightwatch");
/***/ }),
/* 9 */,
/* 10 */,
/* 11 */,
/* 12 */
/***/ (function(module, exports) {
module.exports = require("yargs");
/***/ }),
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _nightwatch = __webpack_require__(8);
var Nightwatch = _interopRequireWildcard(_nightwatch);
var _events = __webpack_require__(3);
var _yargs = __webpack_require__(12);
var _serialize = __webpack_require__(0);
var _runner = __webpack_require__(5);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
var instance = parseInt(_yargs.argv.id, 10); // node childrunner.js --id=<number> --settings=<object>
var settings = (0, _serialize.unserialize)(_yargs.argv.settings);
var client = Nightwatch.client(settings);
var runner;
// Event emitter
var emitter = new _events.EventEmitter();
emitter.setMaxListeners(0);
// Send ipc to parent process
var sendToParent = function sendToParent(message, value) {
process.send({ id: instance, message: message, value: (0, _serialize.serialize)(value) });
};
// Event loop error
client.on('error', function (error) {
sendToParent('error', (0, _serialize.serialize)(error));
});
// Setup command api
process.on('message', function (data) {
var values = void 0;
// Message handling
switch (data.message) {
// Receive config from parent
case 'configure':
runner = new _runner.Runner(client, (0, _serialize.unserialize)(data.value));
runner.instance = instance;
runner.emitter.on('status', function (status) {
sendToParent('status', status);
});
runner.emitter.on('function', function (currentAction) {
sendToParent('function', currentAction);
});
sendToParent('ready', true);
break;
// Continue after halt
case 'createvalue':
values = (0, _serialize.unserialize)(data.value);
runner.values[values.name] = values.value;
break;
// Continue after halt
case 'continue':
runner.halted = false;
runner.returns = (0, _serialize.unserialize)(data.value);
break;
// Cleanup reports
case 'clear':
runner.clean();
sendToParent('clear_done', true);
break;
// New actions are yielded
case 'yield':
runner.addNewActions((0, _serialize.unserialize)(data.value));
break;
// Run actions and tasks
case 'run':
runner.done = false;
runner.start();
runner.run((0, _serialize.unserialize)(data.value)).then(function (result) {
sendToParent('complete', result);
}).catch(function (error) {
sendToParent('complete', error);
});
break;
}
});
/***/ })
/******/ ]);