Commit a19f2978 a19f2978076a6a92352256979ef46f7d392adc9f by Nicolas Perriault

closes #97 - De-anonymize all functions

1 parent a7da3f0b
......@@ -37,24 +37,24 @@ var utils = require('utils');
* @param array phantomArgs phantom.args value
* @return Object
*/
exports.parse = function(phantomArgs) {
exports.parse = function parse(phantomArgs) {
var extract = {
args: [],
options: {},
drop: function(what) {
drop: function drop(what) {
if (utils.isNumber(what)) {
// deleting an arg by its position
this.args = this.args.filter(function(arg, index) {
this.args = this.args.filter(function _filter(arg, index) {
return index !== what;
});
} else if (utils.isString(what)) {
// deleting an arg by its value
this.args = this.args.filter(function(arg) {
this.args = this.args.filter(function _filter(arg) {
return arg !== what;
});
// deleting an option by its name (key)
var self = this;
Object.keys(this.options).forEach(function(option) {
Object.keys(this.options).forEach(function _forEach(option) {
if (option === what) {
delete self.options[what];
}
......@@ -63,7 +63,7 @@ exports.parse = function(phantomArgs) {
throw new CasperError("cannot drop argument of type " + typeof what);
}
},
has: function(what) {
has: function has(what) {
if (utils.isNumber(what)) {
return what in this.args;
} else if (utils.isString(what)) {
......@@ -72,7 +72,7 @@ exports.parse = function(phantomArgs) {
throw new CasperError("Unsupported cli arg tester " + typeof what);
}
},
get: function(what) {
get: function get(what) {
if (utils.isNumber(what)) {
return this.args[what];
} else if (utils.isString(what)) {
......@@ -82,7 +82,7 @@ exports.parse = function(phantomArgs) {
}
}
};
phantomArgs.forEach(function(arg) {
phantomArgs.forEach(function _forEach(arg) {
if (arg.indexOf('--') === 0) {
// named option
var optionMatch = arg.match(/^--(.*)=(.*)/i);
......
......@@ -28,14 +28,14 @@
*
*/
(function(exports) {
exports.create = function() {
exports.create = function create() {
return new ClientUtils();
};
/**
* Casper client-side helpers.
*/
ClientUtils = function() {
ClientUtils = function ClientUtils() {
var BASE64_ENCODE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var BASE64_DECODE_CHARS = new Array(
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
......@@ -54,7 +54,7 @@
* @param String selector A CSS3 selector to the element to click
* @return Boolean
*/
this.click = function(selector) {
this.click = function click(selector) {
var elem = this.findOne(selector);
if (!elem) {
this.log("click(): Couldn't find any element matching '" + selector + "' selector", "error");
......@@ -73,7 +73,7 @@
* @param String str The base64 encoded contents
* @return string
*/
this.decode = function(str) {
this.decode = function decode(str) {
var c1, c2, c3, c4, i = 0, len = str.length, out = "";
while (i < len) {
do {
......@@ -121,7 +121,7 @@
* @param String str The string content to encode
* @return string
*/
this.encode = function(str) {
this.encode = function encode(str) {
var out = "", i = 0, len = str.length, c1, c2, c3;
while (i < len) {
c1 = str.charCodeAt(i++) & 0xff;
......@@ -154,7 +154,7 @@
* @param String selector CSS3 selector
* @return Boolean
*/
this.exists = function(selector) {
this.exists = function exists(selector) {
try {
return document.querySelectorAll(selector).length > 0;
} catch (e) {
......@@ -169,10 +169,10 @@
* @param String selector A CSS3 selector
* @return String
*/
this.fetchText = function(selector) {
this.fetchText = function fetchText(selector) {
var text = '', elements = this.findAll(selector);
if (elements && elements.length) {
Array.prototype.forEach.call(elements, function(element) {
Array.prototype.forEach.call(elements, function _forEach(element) {
text += element.innerText;
});
}
......@@ -186,7 +186,7 @@
* @param Object vals Field values
* @return Object An object containing setting result for each field, including file uploads
*/
this.fill = function(form, vals) {
this.fill = function fill(form, vals) {
var out = {
errors: [],
fields: [],
......@@ -240,7 +240,7 @@
* @param String selector CSS3 selector
* @return NodeList|undefined
*/
this.findAll = function(selector) {
this.findAll = function findAll(selector) {
try {
return document.querySelectorAll(selector);
} catch (e) {
......@@ -254,7 +254,7 @@
* @param String selector CSS3 selector
* @return HTMLElement|undefined
*/
this.findOne = function(selector) {
this.findOne = function findOne(selector) {
try {
return document.querySelector(selector);
} catch (e) {
......@@ -271,7 +271,7 @@
* @param Object data The request data, optional
* @return String Base64 contents string
*/
this.getBase64 = function(url, method, data) {
this.getBase64 = function getBase64(url, method, data) {
return this.encode(this.getBinary(url, method, data));
};
......@@ -284,7 +284,7 @@
* @param Object data
* @return string
*/
this.getBinary = function(url, method, data) {
this.getBinary = function getBinary(url, method, data) {
try {
var xhr = new XMLHttpRequest(), dataString = "";
if (typeof method !== "string" || ["GET", "POST"].indexOf(method.toUpperCase()) === -1) {
......@@ -326,7 +326,7 @@
* @param String selector
* @return Object or null
*/
this.getElementBounds = function(selector) {
this.getElementBounds = function getElementBounds(selector) {
try {
var clipRect = document.querySelector(selector).getBoundingClientRect();
return {
......@@ -347,7 +347,7 @@
* @param String message The message to log
* @param String level The log level
*/
this.log = function(message, level) {
this.log = function log(message, level) {
console.log("[casper:" + (level || "debug") + "] " + message);
};
......@@ -358,7 +358,7 @@
* @param HTMLElement|NodeList field One or more element defining a field
* @param mixed value The field value to set
*/
this.setField = function(field, value) {
this.setField = function setField(field, value) {
var fields, out;
value = value || "";
if (field instanceof NodeList) {
......@@ -403,7 +403,7 @@
if (!Array.isArray(values)) {
values = [values];
}
Array.prototype.forEach.call(fields, function(f) {
Array.prototype.forEach.call(fields, function _forEach(f) {
f.checked = values.indexOf(f.value) !== -1 ? true : false;
});
} else {
......@@ -418,7 +418,7 @@
};
case "radio":
if (fields) {
Array.prototype.forEach.call(fields, function(e) {
Array.prototype.forEach.call(fields, function _forEach(e) {
e.checked = (e.value === value);
});
} else {
......@@ -452,7 +452,7 @@
* @param String selector CSS3 selector
* @return Boolean
*/
this.visible = function(selector) {
this.visible = function visible(selector) {
try {
var el = document.querySelector(selector);
return el && el.style.visibility !== 'hidden' && el.offsetHeight > 0 && el.offsetWidth > 0;
......
......@@ -41,7 +41,7 @@ exports.create = function create() {
*
* (c) Fabien Potencier, Symfony project, MIT license
*/
var Colorizer = function() {
var Colorizer = function Colorizer() {
var options = { bold: 1, underscore: 4, blink: 5, reverse: 7, conceal: 8 };
var foreground = { black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37 };
var background = { black: 40, red: 41, green: 42, yellow: 43, blue: 44, magenta: 45, cyan: 46, white: 47 };
......
......@@ -30,7 +30,7 @@
var utils = require('utils');
exports.create = function(fn) {
exports.create = function create(fn) {
return new FunctionArgsInjector(fn);
};
......@@ -39,18 +39,18 @@ exports.create = function(fn) {
*
* FIXME: use new Function() instead of eval()
*/
var FunctionArgsInjector = function(fn) {
var FunctionArgsInjector = function FunctionArgsInjector(fn) {
if (!utils.isFunction(fn)) {
throw new CasperError("FunctionArgsInjector() can only process functions");
}
this.fn = fn;
this.extract = function(fn) {
this.extract = function extract(fn) {
var match = /^function\s?(\w+)?\s?\((.*)\)\s?\{([\s\S]*)\}/i.exec(fn.toString().trim());
if (match && match.length > 1) {
var args = match[2].split(',').map(function(arg) {
var args = match[2].split(',').map(function _map(arg) {
return arg.replace(new RegExp(/\/\*+.*\*\//ig), "").trim();
}).filter(function(arg) {
}).filter(function _filter(arg) {
return arg;
}) || [];
return {
......@@ -61,7 +61,7 @@ var FunctionArgsInjector = function(fn) {
}
};
this.process = function(values) {
this.process = function process(values) {
var fnObj = this.extract(this.fn);
if (!utils.isObject(fnObj)) {
throw new CasperError("Unable to process function " + this.fn.toString());
......@@ -70,13 +70,13 @@ var FunctionArgsInjector = function(fn) {
return 'function ' + (fnObj.name || '') + '(){' + inject + fnObj.body + '}';
};
this.getArgsInjectionString = function(args, values) {
this.getArgsInjectionString = function getArgsInjectionString(args, values) {
values = typeof values === "object" ? values : {};
var jsonValues = escape(encodeURIComponent(JSON.stringify(values)));
var inject = [
'var __casper_params__ = JSON.parse(decodeURIComponent(unescape(\'' + jsonValues + '\')));'
];
args.forEach(function(arg) {
args.forEach(function _forEach(arg) {
if (arg in values) {
inject.push('var ' + arg + '=__casper_params__["' + arg + '"];');
}
......
......@@ -30,11 +30,11 @@
var utils = require('utils');
exports.create = function(casper) {
exports.create = function create(casper) {
return new Mouse(casper);
};
var Mouse = function(casper) {
var Mouse = function Mouse(casper) {
if (!utils.isCasperObject(casper)) {
throw new CasperError('Mouse() needs a Casper instance');
}
......
......@@ -33,7 +33,7 @@ var events = require('events');
var utils = require('utils');
var f = utils.format;
exports.create = function(casper, options) {
exports.create = function create(casper, options) {
return new Tester(casper, options);
};
......@@ -41,7 +41,7 @@ exports.create = function(casper, options) {
* Casper tester: makes assertions, stores test results and display then.
*
*/
var Tester = function(casper, options) {
var Tester = function Tester(casper, options) {
if (!utils.isCasperObject(casper)) {
throw new CasperError("Tester needs a Casper instance");
}
......@@ -64,16 +64,16 @@ var Tester = function(casper, options) {
};
// events
casper.on('step.error', function(e) {
casper.on('step.error', function onStepError(e) {
casper.test.fail(e);
casper.test.done();
});
this.on('success', function(success) {
this.on('success', function onSuccess(success) {
this.exporter.addSuccess(fs.absolute(success.file), success.message);
});
this.on('fail', function(failure) {
this.on('fail', function onFail(failure) {
this.exporter.addFailure(fs.absolute(failure.file), failure.message, failure.details || "test failed", failure.type || "unknown");
this.testResults.failures.push(failure);
});
......@@ -274,7 +274,7 @@ var Tester = function(casper, options) {
* @param String message Test description
*/
this.assertTextExists = function assertTextExists(text, message) {
return this.assert((casper.evaluate(function() {
return this.assert((casper.evaluate(function _evaluate() {
return document.body.innerText;
}).indexOf(text) != -1), message);
};
......@@ -367,7 +367,7 @@ var Tester = function(casper, options) {
new Function('casper', phantom.getScriptCode(file))(casper);
} catch (e) {
var self = this;
phantom.processScriptError(e, file, function(error) {
phantom.processScriptError(e, file, function onTestScriptError(error) {
// do not abort the whole suite, just fail fast displaying the
// caught error and process next suite
self.fail(e);
......@@ -395,17 +395,17 @@ var Tester = function(casper, options) {
if (!fs.isDirectory(dir)) {
return [];
}
var entries = fs.list(dir).filter(function(entry) {
var entries = fs.list(dir).filter(function _filter(entry) {
return entry !== '.' && entry !== '..';
}).map(function(entry) {
}).map(function _map(entry) {
return fs.absolute(fs.pathJoin(dir, entry));
});
entries.forEach(function(entry) {
entries.forEach(function _forEach(entry) {
if (fs.isDirectory(entry)) {
entries = entries.concat(self.findTestFiles(entry));
}
});
return entries.filter(function(entry) {
return entries.filter(function _filter(entry) {
return utils.isJsFile(fs.absolute(fs.pathJoin(dir, entry)));
}).sort();
};
......@@ -452,7 +452,7 @@ var Tester = function(casper, options) {
return;
}
casper.echo(f("\nDetails for the %d failed test%s:\n", failures.length, failures.length > 1 ? "s" : ""), "PARAMETER");
failures.forEach(function(failure) {
failures.forEach(function _forEach(failure) {
var message, line;
if (utils.isType(failure.message, "object") && failure.message.stack) {
line = failure.message.line ? failure.message.line : 0;
......@@ -516,7 +516,7 @@ var Tester = function(casper, options) {
if (arguments.length === 0) {
throw new CasperError("runSuites() needs at least one path argument");
}
Array.prototype.forEach.call(arguments, function(path) {
Array.prototype.forEach.call(arguments, function _forEach(path) {
if (!fs.exists(path)) {
self.bar(f("Path %s doesn't exist", path), "RED_BAR");
}
......@@ -531,7 +531,7 @@ var Tester = function(casper, options) {
casper.exit(1);
}
var current = 0;
var interval = setInterval(function(self) {
var interval = setInterval(function _check(self) {
if (self.running) {
return;
}
......
......@@ -104,7 +104,7 @@ function format(f) {
i = 1;
var args = arguments;
var len = args.length;
var str = String(f).replace(/%[sdj%]/g, function(x) {
var str = String(f).replace(/%[sdj%]/g, function _replace(x) {
if (i >= len) return x;
switch (x) {
case '%s':
......@@ -352,7 +352,7 @@ exports.node = node;
*/
function serialize(value) {
if (isArray(value)) {
value = value.map(function(prop) {
value = value.map(function _map(prop) {
return isFunction(prop) ? prop.toString().replace(/\s{2,}/, '') : prop;
});
}
......
......@@ -31,7 +31,7 @@
var utils = require('utils');
var fs = require('fs');
exports.create = function() {
exports.create = function create() {
return new XUnitExporter();
};
......@@ -39,9 +39,9 @@ exports.create = function() {
* JUnit XML (xUnit) exporter for test results.
*
*/
XUnitExporter = function() {
XUnitExporter = function XUnitExporter() {
this._xml = utils.node('testsuite');
this._xml.toString = function() {
this._xml.toString = function toString() {
return this.outerHTML; // ouch
};
};
......@@ -53,7 +53,7 @@ exports.XUnitExporter = XUnitExporter;
* @param String classname
* @param String name
*/
XUnitExporter.prototype.addSuccess = function(classname, name) {
XUnitExporter.prototype.addSuccess = function addSuccess(classname, name) {
this._xml.appendChild(utils.node('testcase', {
classname: generateClassName(classname),
name: name
......@@ -68,7 +68,7 @@ XUnitExporter.prototype.addSuccess = function(classname, name) {
* @param String message
* @param String type
*/
XUnitExporter.prototype.addFailure = function(classname, name, message, type) {
XUnitExporter.prototype.addFailure = function addFailure(classname, name, message, type) {
var fnode = utils.node('testcase', {
classname: generateClassName(classname),
name: name
......@@ -110,6 +110,6 @@ function generateClassName(classname) {
*
* @return HTMLElement
*/
XUnitExporter.prototype.getXML = function() {
XUnitExporter.prototype.getXML = function getXML() {
return this._xml;
};
......