ti-appium
Version:
An Appium wrapper to test Titanium applications
201 lines (162 loc) • 6.29 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: src/output.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: src/output.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>'use strict';
// Colours to be used in the console logging
const
Red = '\x1b[31m',
Grey = '\x1b[37m',
Reset = '\x1b[0m',
Green = '\x1b[32m',
Yellow = '\x1b[33m';
/**
* @class Output_Helper
* @desc
* Helper for outputting information to the CLI in a uniform manner
*/
class Output_Helper {
/**
* Writes a message with a green info tag (note no new line is passed by
* default).
*
* @param {String} message - A string to be output after the info tag
*/
static step(message) {
message = `${Green}[INFO]${Reset} ${sanitise(message)}... `;
if (process.env.logging === 'debug') {
message = `${message}\n`;
}
process.stdout.write(message);
}
/**
* Writes a green done to the console and resolves the promise if passed.
*
* @param {Function} done - Promise callback passed from the function
* @param {Object} value - An object to be returned with resolve
*/
static finish(done, value) {
if (process.env.logging !== 'debug') {
process.stdout.write(`${Green}Done${Reset}\n`);
}
if (done) {
done(value);
}
}
/**
* Writes a yellow skip to the console and resolves the promise if passed.
*
* @param {Function} done - Promise callback passed from the function
* @param {Object} value - An object to be returned with resolve
*/
static skip(done, value) {
if (process.env.logging !== 'debug') {
process.stdout.write(`${Yellow}Skipping${Reset}\n`);
}
if (done) {
done(value);
}
}
/**
* Writes a message with a green info tag (note no new line is passed by
* default).
*
* @param {String} message - A string to be output after the info tag
*/
static info(message) {
message = `${Green}[INFO]${Reset} ${sanitise(message)}\n`;
process.stdout.write(message);
}
/**
* Writes a message with a yellow warning tag (note no new line is passed by
* default).
*
* @param {String} message - A string to be output after the warning tag
*/
static warn(message) {
message = `${Yellow}[WARN]${Reset} ${sanitise(message)}\n`;
process.stdout.write(message);
}
/**
* Outputs all of a string in red.
*
* @param {String} message - String to be output
*/
static error(message) {
message = `${Red}[ERROR] ${sanitise(message)}${Reset}\n`;
process.stdout.write(message);
}
/**
* Creates a banner and a green info tag around a message.
*
* @param {String} message - String to be enclosed by the banner
*/
static banner(message) {
process.stdout.write('\n-------------------------------------------------------\n');
process.stdout.write(`${Green}[INFO]${Reset} ${message}\n`);
process.stdout.write('-------------------------------------------------------\n');
}
/**
* Outputs a message when the debug flag is used.
*
* @param {String} message - String to be output
*/
static debug(message) {
message = `${Grey}[DEBUG] ${sanitise(message)}${Reset}\n`;
if (process.env.logging === 'debug') {
process.stdout.write(message);
}
}
}
/**
* Take the message, and make sure it is fit for use.
* @private
*
* @param {String} message - String to be output
*/
function sanitise(message) {
if (message instanceof Error) {
return message.toString('utf8');
} else if (message instanceof Object) {
if (message instanceof Buffer) {
return message.toString('utf8');
} else {
return JSON.stringify(message, null, 2);
}
} else {
while (message.endsWith('\n')) {
message = message.substring(0, message.length - 1);
}
return message;
}
}
module.exports = Output_Helper;
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="WebDriverCommands.html">WebDriverCommands</a></li></ul><h3>Classes</h3><ul><li><a href="Appc_Helper.html">Appc_Helper</a></li><li><a href="Appium_Helper.html">Appium_Helper</a></li><li><a href="Device_Helper.html">Device_Helper</a></li><li><a href="Mocha_Helper.html">Mocha_Helper</a></li><li><a href="Output_Helper.html">Output_Helper</a></li><li><a href="Webdriver_Helper.html">Webdriver_Helper</a></li></ul><h3>Global</h3><ul><li><a href="global.html#appcRun">appcRun</a></li><li><a href="global.html#appcSetup">appcSetup</a></li><li><a href="global.html#banner">banner</a></li><li><a href="global.html#buildApp">buildApp</a></li><li><a href="global.html#createAppPath">createAppPath</a></li><li><a href="global.html#debug">debug</a></li><li><a href="global.html#error">error</a></li><li><a href="global.html#finish">finish</a></li><li><a href="global.html#getCert">getCert</a></li><li><a href="global.html#getProfile">getProfile</a></li><li><a href="global.html#getSimState">getSimState</a></li><li><a href="global.html#info">info</a></li><li><a href="global.html#killEmulator">killEmulator</a></li><li><a href="global.html#killSimulator">killSimulator</a></li><li><a href="global.html#parseSDK">parseSDK</a></li><li><a href="global.html#skip">skip</a></li><li><a href="global.html#startAppium">startAppium</a></li><li><a href="global.html#startClient">startClient</a></li><li><a href="global.html#step">step</a></li><li><a href="global.html#stopAppium">stopAppium</a></li><li><a href="global.html#stopClient">stopClient</a></li><li><a href="global.html#test">test</a></li><li><a href="global.html#warn">warn</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Fri Aug 28 2020 10:09:07 GMT+0100 (British Summer Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>