Commit c959bbfe c959bbfeee8cfe6269d1a4ba0cf13a5c417219e8 by Nicolas Perriault

s/lib/modules

1 parent 301d6345
#!/usr/bin/env python
import os
import subprocess
import sys
def resolve(path):
if os.path.islink(path):
return resolve(os.readlink(path))
return path
CASPER_PATH = os.path.abspath(os.path.join(os.path.dirname(resolve(__file__)), '..'))
CASPER_ARGS = ['phantomjs', os.path.join(CASPER_PATH, 'casper.js'), '--casper-path=%s' % CASPER_PATH, '--cli']
CASPER_ARGS.extend(sys.argv[1:])
try:
subprocess.call(CASPER_ARGS)
except KeyboardInterrupt:
print '\nCasperJS interrupted, exiting.'
sys.exit()
......@@ -26,7 +26,8 @@
*
*/
var utils = require('./lib/utils');
var fs = require('fs');
var utils = require('utils');
exports.create = function(options) {
return new Casper(options);
......@@ -72,7 +73,7 @@ var Casper = function(options) {
// properties
this.checker = null;
this.cli = phantom.casperArgs;
this.colorizer = require('./lib/colorizer').create();
this.colorizer = require('colorizer').create();
this.currentUrl = 'about:blank';
this.currentHTTPStatus = 200;
this.defaultWaitTimeout = 5000;
......@@ -99,7 +100,7 @@ var Casper = function(options) {
this.started = false;
this.step = -1;
this.steps = [];
this.test = require('./lib/tester').create(this);
this.test = require('tester').create(this);
};
/**
......@@ -306,9 +307,9 @@ Casper.prototype = {
* @return Casper
*/
download: function(url, targetPath) {
var cu = require('./lib/clientutils').create();
var cu = require('clientutils').create();
try {
require('fs').write(targetPath, cu.decode(this.base64encode(url)), 'w');
fs.write(targetPath, cu.decode(this.base64encode(url)), 'w');
} catch (e) {
this.log("Error while downloading " + url + " to " + targetPath + ": " + e, "error");
}
......@@ -372,7 +373,7 @@ Casper.prototype = {
*/
evaluate: function(fn, context) {
context = utils.isType(context, "object") ? context : {};
var newFn = require('./lib/injector').create(fn).process(context);
var newFn = require('injector').create(fn).process(context);
return this.page.evaluate(newFn);
},
......@@ -1122,7 +1123,7 @@ function createPage(casper) {
}
}
if (casper.options.clientScripts) {
if (betterTypeOf(casper.options.clientScripts) !== "array") {
if (!utils.isType(casper.options.clientScripts, "array")) {
casper.log("The clientScripts option must be an array", "error");
} else {
for (var i = 0; i < casper.options.clientScripts.length; i++) {
......@@ -1136,14 +1137,7 @@ function createPage(casper) {
}
}
// Client-side utils injection
var injected = page.evaluate(replaceFunctionPlaceholders(function() {
eval("var ClientUtils = " + decodeURIComponent("%utils%"));
__utils__ = new ClientUtils();
return __utils__ instanceof ClientUtils;
}, {
utils: encodeURIComponent(require('./lib/clientutils').ClientUtils.toString())
}));
if (!injected) {
if (!casper.page.injectJs(fs.pathJoin(phantom.casperPath, 'lib', 'clientutils.js'))) {
casper.log("Failed to inject Casper client-side utilities!", "warning");
} else {
casper.log("Successfully injected Casper client-side utilities", "debug");
......
......@@ -34,7 +34,7 @@
/**
* Casper client-side helpers.
*/
var ClientUtils = function() {
exports.ClientUtils = function() {
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,
......@@ -442,4 +442,4 @@
return out;
};
};
})(exports || {});
})(exports || window || {});
......
......@@ -27,7 +27,7 @@
*/
var fs = require('fs');
var utils = require('./lib/utils');
var utils = require('utils');
exports.create = function(casper, options) {
return new Tester(casper, options);
......@@ -47,7 +47,7 @@ var Tester = function(casper, options) {
}
// locals
var exporter = require('./lib/xunit').create();
var exporter = require('xunit').create();
var PASS = this.options.PASS || "PASS";
var FAIL = this.options.FAIL || "FAIL";
......
......@@ -92,7 +92,7 @@ exports.fillBlanks = fillBlanks;
* @return Boolean
*/
function isCasperObject(value) {
return value instanceof require('./lib/casper').Casper;
return value instanceof require('casper').Casper;
}
exports.isCasperObject = isCasperObject;
......