refactor app directory structure and add tests
This commit is contained in:
62
tests/node_modules/nightwatch/lib/util/keys.json
generated
vendored
Normal file
62
tests/node_modules/nightwatch/lib/util/keys.json
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"NULL" : "\uE000",
|
||||
"CANCEL" : "\uE001",
|
||||
"HELP" : "\uE002",
|
||||
"BACK_SPACE" : "\uE003",
|
||||
"TAB" : "\uE004",
|
||||
"CLEAR" : "\uE005",
|
||||
"RETURN" : "\uE006",
|
||||
"ENTER" : "\uE007",
|
||||
"SHIFT" : "\uE008",
|
||||
"CONTROL" : "\uE009",
|
||||
"ALT" : "\uE00A",
|
||||
"PAUSE" : "\uE00B",
|
||||
"ESCAPE" : "\uE00C",
|
||||
"SPACE" : "\uE00D",
|
||||
"PAGEUP" : "\uE00E",
|
||||
"PAGEDOWN" : "\uE00F",
|
||||
"END" : "\uE010",
|
||||
"HOME" : "\uE011",
|
||||
"LEFT_ARROW" : "\uE012",
|
||||
"UP_ARROW" : "\uE013",
|
||||
"RIGHT_ARROW" : "\uE014",
|
||||
"DOWN_ARROW" : "\uE015",
|
||||
"ARROW_LEFT" : "\uE012",
|
||||
"ARROW_UP" : "\uE013",
|
||||
"ARROW_RIGHT" : "\uE014",
|
||||
"ARROW_DOWN" : "\uE015",
|
||||
"INSERT" : "\uE016",
|
||||
"DELETE" : "\uE017",
|
||||
"SEMICOLON" : "\uE018",
|
||||
"EQUALS" : "\uE019",
|
||||
"NUMPAD0" : "\uE01A",
|
||||
"NUMPAD1" : "\uE01B",
|
||||
"NUMPAD2" : "\uE01C",
|
||||
"NUMPAD3" : "\uE01D",
|
||||
"NUMPAD4" : "\uE01E",
|
||||
"NUMPAD5" : "\uE01F",
|
||||
"NUMPAD6" : "\uE020",
|
||||
"NUMPAD7" : "\uE021",
|
||||
"NUMPAD8" : "\uE022",
|
||||
"NUMPAD9" : "\uE023",
|
||||
"MULTIPLY" : "\uE024",
|
||||
"ADD" : "\uE025",
|
||||
"SEPARATOR" : "\uE026",
|
||||
"SUBTRACT" : "\uE027",
|
||||
"DECIMAL" : "\uE028",
|
||||
"DIVIDE" : "\uE029",
|
||||
"F1" : "\uE031",
|
||||
"F2" : "\uE032",
|
||||
"F3" : "\uE033",
|
||||
"F4" : "\uE034",
|
||||
"F5" : "\uE035",
|
||||
"F6" : "\uE036",
|
||||
"F7" : "\uE037",
|
||||
"F8" : "\uE038",
|
||||
"F9" : "\uE039",
|
||||
"F10" : "\uE03A",
|
||||
"F11" : "\uE03B",
|
||||
"F12" : "\uE03C",
|
||||
"COMMAND" : "\uE03D",
|
||||
"META" : "\uE03D"
|
||||
}
|
197
tests/node_modules/nightwatch/lib/util/logger.js
generated
vendored
Normal file
197
tests/node_modules/nightwatch/lib/util/logger.js
generated
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
var util = require('util');
|
||||
var Settings = {
|
||||
log_timestamp : false,
|
||||
colors : true,
|
||||
enabled : true
|
||||
};
|
||||
|
||||
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
||||
'Oct', 'Nov', 'Dec'];
|
||||
|
||||
function getDate() {
|
||||
var now = new Date();
|
||||
return [now.toLocaleDateString(), now.toLocaleTimeString()].join(' ');
|
||||
}
|
||||
|
||||
function pad(n) {
|
||||
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
||||
}
|
||||
|
||||
// 26 Feb 16:19:34
|
||||
function timestamp() {
|
||||
var d = new Date();
|
||||
var time = [pad(d.getHours()),
|
||||
pad(d.getMinutes()),
|
||||
pad(d.getSeconds())].join(':');
|
||||
return [d.getDate(), months[d.getMonth()], time].join(' ');
|
||||
}
|
||||
|
||||
function getPrefix(tag, severity) {
|
||||
var levels = ['EMERG', 'ALERT', 'CRITICAL', 'ERROR', 'WARNING', 'NOTICE', 'INFO', 'DEBUG'];
|
||||
return tag + ' ' + levels[severity] +' - ';
|
||||
}
|
||||
|
||||
function ConsoleColor() {
|
||||
var self = this;
|
||||
var mappings = {
|
||||
blue : '0;34',
|
||||
light_blue : '1;34'
|
||||
};
|
||||
this.background = new Background();
|
||||
|
||||
this.foreground_colors = {};
|
||||
this.foreground_colors['black'] = '0;30';
|
||||
this.foreground_colors['dark_gray'] = '1;30';
|
||||
this.foreground_colors['blue'] = '0;34';
|
||||
this.foreground_colors['light_blue'] = '1;34';
|
||||
this.foreground_colors['green'] = '0;32';
|
||||
this.foreground_colors['light_green'] = '1;32';
|
||||
this.foreground_colors['cyan'] = '0;36';
|
||||
this.foreground_colors['light_cyan'] = '1;36';
|
||||
this.foreground_colors['red'] = '0;31';
|
||||
this.foreground_colors['light_red'] = '1;31';
|
||||
this.foreground_colors['purple'] = '0;35';
|
||||
this.foreground_colors['light_purple'] = '1;35';
|
||||
this.foreground_colors['brown'] = '0;33';
|
||||
this.foreground_colors['yellow'] = '1;33';
|
||||
this.foreground_colors['light_gray'] = '0;37';
|
||||
this.foreground_colors['white'] = '1;37';
|
||||
this.foreground_colors['stack_trace'] = '0;90';
|
||||
|
||||
this.background_colors = {};
|
||||
this.background_colors['black'] = '40';
|
||||
this.background_colors['red'] = '41';
|
||||
this.background_colors['green'] = '42';
|
||||
this.background_colors['yellow'] = '43';
|
||||
this.background_colors['blue'] = '44';
|
||||
this.background_colors['magenta'] = '45';
|
||||
this.background_colors['cyan'] = '46';
|
||||
this.background_colors['light_gray'] = '47';
|
||||
|
||||
Object.keys(this.foreground_colors).forEach(function(k) {
|
||||
ConsoleColor.prototype[k.toLowerCase()] = function Foreground(text, background) {
|
||||
var string = '\033[' + self.foreground_colors[k.toLowerCase()] + 'm';
|
||||
if (background !== undefined) {
|
||||
string += background();
|
||||
}
|
||||
|
||||
string += text + '\033[0m';
|
||||
return string;
|
||||
};
|
||||
});
|
||||
|
||||
Object.keys(this.background_colors).forEach(function(k) {
|
||||
Background.prototype[k.toLowerCase()] = function Background(text) {
|
||||
return '\033[' + self.background_colors[k.toLowerCase()] + 'm';
|
||||
};
|
||||
});
|
||||
return this;
|
||||
}
|
||||
function Background() { return this; }
|
||||
|
||||
var colors = new ConsoleColor();
|
||||
function logObject(obj) {
|
||||
console.log(util.inspect(obj, {
|
||||
showHidden : false,
|
||||
depth : 3,
|
||||
colors : Settings.colors
|
||||
}));
|
||||
}
|
||||
|
||||
function logTimestamp() {
|
||||
if (Settings.log_timestamp) {
|
||||
return colors.white(timestamp()) + ' ';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function logMessage(type, message, args) {
|
||||
if (!message || !Settings.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
var messageStr = '';
|
||||
var timestamp = logTimestamp();
|
||||
switch (type) {
|
||||
case 'ERROR':
|
||||
messageStr = colors.yellow(type, colors.background.dark_gray) +' '+
|
||||
timestamp + colors.light_green(message);
|
||||
break;
|
||||
case 'INFO':
|
||||
messageStr = colors.light_purple(type, colors.background.black) +' '+
|
||||
timestamp + colors.light_cyan(message);
|
||||
break;
|
||||
case 'LOG':
|
||||
messageStr = colors.white(type+' ', colors.background.black) +' '+
|
||||
timestamp + colors.white(message);
|
||||
break;
|
||||
case 'WARN':
|
||||
messageStr = colors.light_green(type, colors.background.black) +' '+
|
||||
timestamp + colors.light_green(message);
|
||||
break;
|
||||
}
|
||||
|
||||
process.stdout.write(messageStr);
|
||||
|
||||
if (args.length > 0) {
|
||||
var inlineArgs = [];
|
||||
args.forEach(function(item) {
|
||||
if (Object.prototype.toString.call(item) === '[object Object]' && Object.keys(item).length > 0) {
|
||||
if (inlineArgs.length) {
|
||||
console.log.apply(console, inlineArgs);
|
||||
inlineArgs = [];
|
||||
}
|
||||
logObject(item);
|
||||
} else {
|
||||
inlineArgs.push(item);
|
||||
}
|
||||
});
|
||||
if (inlineArgs.length) {
|
||||
process.stdout.write(' ');
|
||||
console.log.apply(console, inlineArgs);
|
||||
inlineArgs = [];
|
||||
}
|
||||
} else {
|
||||
process.stdout.write('\n');
|
||||
}
|
||||
}
|
||||
|
||||
exports.info = function(message) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
logMessage('INFO', message, args);
|
||||
};
|
||||
|
||||
exports.log = function(message) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
logMessage('LOG', message, args);
|
||||
};
|
||||
|
||||
exports.warn = function(message) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
logMessage('WARN', message, args);
|
||||
};
|
||||
|
||||
exports.error = function(message) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
logMessage('ERROR', message, args);
|
||||
};
|
||||
|
||||
exports.disableColors = function () {
|
||||
Settings.colors = false;
|
||||
Object.keys(ConsoleColor.prototype).forEach(function (color) {
|
||||
ConsoleColor.prototype[color] = function (text) {
|
||||
return text;
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
exports.disable = function() {
|
||||
Settings.enabled = false;
|
||||
};
|
||||
exports.enable = function() {
|
||||
Settings.enabled = true;
|
||||
};
|
||||
exports.isEnabled = function() {
|
||||
return Settings.enabled;
|
||||
};
|
||||
exports.colors = colors;
|
288
tests/node_modules/nightwatch/lib/util/utils.js
generated
vendored
Normal file
288
tests/node_modules/nightwatch/lib/util/utils.js
generated
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var Util = module.exports = {};
|
||||
var Logger = require('./logger.js');
|
||||
|
||||
var formatRegExp = /%[sdj%]/g;
|
||||
var testSuiteNameRegxp = /(_|-|\.)*([A-Z]*)/g;
|
||||
var nameSeparatorRegxp = /(\s|\/)/;
|
||||
|
||||
Util.formatElapsedTime = function(timeMs, includeMs) {
|
||||
var seconds = timeMs/1000;
|
||||
return (seconds < 1 && timeMs + 'ms') ||
|
||||
(seconds > 1 && seconds < 60 && (seconds + 's')) ||
|
||||
(Math.floor(seconds/60) + 'm' + ' ' + Math.floor(seconds%60) + 's' + (includeMs ? (' / ' + timeMs + 'ms') : ''));
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrap a synchronous function, turning it into an async fn with a callback as
|
||||
* the last argument if necessary. `asyncArgCount` is the expected argument
|
||||
* count if `fn` is already asynchronous.
|
||||
*
|
||||
* @param {number} asyncArgCount
|
||||
* @param {function} fn
|
||||
* @param {object} [context]
|
||||
*/
|
||||
Util.makeFnAsync = function (asyncArgCount, fn, context) {
|
||||
if (fn.length === asyncArgCount) {
|
||||
return fn;
|
||||
}
|
||||
|
||||
return function() {
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
var done = args.pop();
|
||||
context = context || null;
|
||||
fn.apply(context, args);
|
||||
done();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Waits a number of ms for a `done` callback to be invoked
|
||||
*
|
||||
* @param {function} done
|
||||
* @param {string} fnName
|
||||
* @param {number} timeMs
|
||||
* @param {function} [onCatch]
|
||||
* @param {function} [onTimerStarted]
|
||||
* @return {Function}
|
||||
*/
|
||||
Util.setCallbackTimeout = function(done, fnName, timeMs, onCatch, onTimerStarted) {
|
||||
var timeout = setTimeout(function() {
|
||||
if (onCatch) {
|
||||
var err = new Error('done() callback timeout of '+ timeMs +' ms was reached while executing "' + fnName + '".' +
|
||||
' Make sure to call the done() callback when the operation finishes.');
|
||||
onCatch(err, fnName, timeout);
|
||||
}
|
||||
|
||||
}, timeMs);
|
||||
|
||||
if (onTimerStarted) {
|
||||
onTimerStarted(timeout);
|
||||
}
|
||||
|
||||
return function(ex) {
|
||||
clearTimeout(timeout);
|
||||
done(ex, true);
|
||||
};
|
||||
};
|
||||
|
||||
Util.checkFunction = function(name, parent) {
|
||||
return parent && (typeof parent[name] == 'function') && parent[name] || false;
|
||||
};
|
||||
|
||||
Util.getTestSuiteName = function(moduleName) {
|
||||
var words;
|
||||
|
||||
moduleName = moduleName.replace(testSuiteNameRegxp, function(match, $0, $1, offset, string) {
|
||||
if (!match) {
|
||||
return '';
|
||||
}
|
||||
return (offset > 0 && (string.charAt(offset-1) !== ' ') ? ' ':'') + $1;
|
||||
});
|
||||
|
||||
words = moduleName.split(nameSeparatorRegxp).map(function(word, index, matches) {
|
||||
if (word == '/') {
|
||||
return ' / ';
|
||||
}
|
||||
return word.charAt(0).toUpperCase() + word.substr(1);
|
||||
});
|
||||
|
||||
return words.join('');
|
||||
};
|
||||
|
||||
/**
|
||||
* A smaller version of util.format that doesn't support json and
|
||||
* if a placeholder is missing, it is omitted instead of appended
|
||||
*
|
||||
* @param f
|
||||
* @returns {string}
|
||||
*/
|
||||
Util.format = function format(f) {
|
||||
var i = 1;
|
||||
var args = arguments;
|
||||
var len = args.length;
|
||||
return String(f).replace(formatRegExp, function(x) {
|
||||
if (x === '%%') {
|
||||
return '%';
|
||||
}
|
||||
if (i >= len) {
|
||||
return x;
|
||||
}
|
||||
switch (x) {
|
||||
case '%s':
|
||||
return String(args[i++]);
|
||||
case '%d':
|
||||
return Number(args[i++]);
|
||||
default:
|
||||
return x;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Util.getScreenshotFileName = function(currentTest, is_error, screenshots_path) {
|
||||
var prefix = currentTest.module + '/' + currentTest.name;
|
||||
prefix = prefix.replace(/\s/g, '-').replace(/"|'/g, '');
|
||||
prefix += is_error ? '_ERROR' : '_FAILED';
|
||||
|
||||
var d = new Date();
|
||||
var dateParts = d.toString().replace(/:/g,'').split(' ');
|
||||
dateParts.shift();
|
||||
dateParts.pop();
|
||||
var dateStamp = dateParts.join('-');
|
||||
|
||||
return path.resolve(path.join(screenshots_path, prefix + '_' + dateStamp + '.png'));
|
||||
};
|
||||
|
||||
Util.isObject = function(obj) {
|
||||
return (typeof obj == 'object') && (obj !== null);
|
||||
};
|
||||
|
||||
Util.processAsyncQueue = function(concurrency, files, cb) {
|
||||
var maxWorkers = Math.min(concurrency, files.length);
|
||||
var queue = [];
|
||||
var add = function(item) {
|
||||
queue.push(item);
|
||||
};
|
||||
|
||||
var workers = 0;
|
||||
var index = 0;
|
||||
var next = function() {
|
||||
workers -= 1;
|
||||
process();
|
||||
};
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
add(files[i]);
|
||||
}
|
||||
|
||||
var process = function() {
|
||||
while (workers < maxWorkers) {
|
||||
workers += 1;
|
||||
|
||||
if (queue.length) {
|
||||
var item = queue.shift();
|
||||
cb(item, index++, next);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
process();
|
||||
};
|
||||
|
||||
Util.getModuleKey = function(filePath, srcFolders, fullPaths) {
|
||||
var modulePathParts = filePath.split(path.sep);
|
||||
var diffInFolder = '';
|
||||
var folder = '';
|
||||
var parentFolder = '';
|
||||
var moduleName = modulePathParts.pop();
|
||||
filePath = modulePathParts.join(path.sep);
|
||||
|
||||
if (srcFolders) {
|
||||
for (var i = 0; i < srcFolders.length; i++) {
|
||||
folder = path.resolve(srcFolders[i]);
|
||||
if (fullPaths.length > 1) {
|
||||
parentFolder = folder.split(path.sep).pop();
|
||||
}
|
||||
if (filePath.indexOf(folder) === 0) {
|
||||
diffInFolder = filePath.substring(folder.length + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return path.join(parentFolder, diffInFolder, moduleName);
|
||||
};
|
||||
|
||||
Util.showStackTraceWithHeadline = function(headline, stack, isErr) {
|
||||
var logMethod = isErr ? 'error' : 'log';
|
||||
var stackTrace;
|
||||
console[logMethod](Logger.colors.red(headline));
|
||||
|
||||
if (Array.isArray(stack) && stack.length > 0) {
|
||||
stackTrace = Util.stackTraceFilter(stack);
|
||||
} else {
|
||||
stackTrace = stack;
|
||||
}
|
||||
|
||||
if (stack) {
|
||||
console[logMethod](Logger.colors.stack_trace(stackTrace));
|
||||
}
|
||||
};
|
||||
|
||||
Util.stackTraceFilter = function(parts) {
|
||||
var stack = parts.reduce(function(list, line) {
|
||||
if (contains(line, [
|
||||
'node_modules',
|
||||
'(node.js:',
|
||||
'(events.js:'
|
||||
])) {
|
||||
return list;
|
||||
}
|
||||
|
||||
list.push(line);
|
||||
return list;
|
||||
}, []);
|
||||
|
||||
return stack.join('\n');
|
||||
};
|
||||
|
||||
var indentRegex = /^/gm;
|
||||
Util.showStackTrace = function(stack) {
|
||||
var parts = stack.split('\n');
|
||||
var headline = parts.shift();
|
||||
|
||||
console.log(Logger.colors.red(headline.replace(indentRegex, ' ')));
|
||||
if (parts.length > 0) {
|
||||
var result = Util.stackTraceFilter(parts);
|
||||
console.log(Logger.colors.stack_trace(result.replace(indentRegex, ' ')));
|
||||
}
|
||||
};
|
||||
|
||||
Util.symbols = (function() {
|
||||
var ok = String.fromCharCode(10004);
|
||||
var fail = String.fromCharCode(10006);
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
ok = '\u221A';
|
||||
fail = '\u00D7';
|
||||
}
|
||||
|
||||
return {
|
||||
ok: ok,
|
||||
fail: fail
|
||||
};
|
||||
})();
|
||||
|
||||
Util.isErrorObject = function(err) {
|
||||
return err instanceof Error || Object.prototype.toString.call(err) === '[object Error]';
|
||||
};
|
||||
|
||||
// util to replace deprecated fs.existsSync
|
||||
Util.dirExistsSync = function (path) {
|
||||
try {
|
||||
return fs.statSync(path).isDirectory();
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Util.fileExistsSync = function (path) {
|
||||
try {
|
||||
return fs.statSync(path).isFile();
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
function contains(str, text) {
|
||||
if (Array.isArray(text)) {
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
if (contains(str, text[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return str.indexOf(text) > -1;
|
||||
}
|
Reference in New Issue
Block a user