Hi!
Here's a patch that fixes __phantom_writefile and eliminates some unnecessary code for newer phantomjs builds that support passing arguments to .evaluate():
https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#wiki-webpage-evaluate
From 50bd3c059e112d3e9e3fb430077e5ef82c9bb328 Mon Sep 17 00:00:00 2001
From: unknown [email protected]
Date: Mon, 17 Feb 2014 11:04:29 -0600
Subject: [PATCH] phatnomjs-testrunner.js patched for newer phantomjs builds
test/phantomjs-testrunner.js | 73 ++++++++++++--------------------------------
1 file changed, 19 insertions(+), 54 deletions(-)
diff --git a/test/phantomjs-testrunner.js b/test/phantomjs-testrunner.js
index 75ad24e..9c211fd 100644
--- a/test/phantomjs-testrunner.js
+++ b/test/phantomjs-testrunner.js
@@ -1,3 +1,4 @@
+// Initially copied from jasmine-reporters project: https://github.com/larrymyers/jasmine-reporters.git
// Verify arguments
if (phantom.args.length === 0) {
console.log("Simple JasmineBDD test runner for phantom.js");
@@ -16,7 +17,7 @@ else {
var setupPageFn = function(p, k) {
return function() {
-
-
//overloadPageEvaluate(p);
setupWriteFileFunction(p, k, fs.separator);
};
};
@@ -57,74 +58,35 @@ else {
}, 100);
}
-// Thanks to hoisting, these helpers are still available when needed above
+
/**
- Logs a message. Does not add a line-break for single characters '.' and 'F' or lines ending in ' ...'
*
- @param msg
*/
function logAndWorkAroundDefaultLineBreaking(msg) {
- var interpretAsWithoutNewline = /(^(\033[\d+m).F$)|( ...$)/;
- if (navigator.userAgent.indexOf("Windows") < 0 && interpretAsWithoutNewline.test(msg)) {
-
-
var system = require('system');
-
system.stdout.write(msg);
-
-
-
fs.write('/dev/stdout', msg, 'w');
-
- } else {
-
- }
- console.log( msg );
}
-/**
- * Stringifies the function, replacing any %placeholders% with mapped values.
-
- * @param {function} fn The function to replace occurrences within.
- * @param {object} replacements Key => Value object of string replacements.
- */
-function replaceFunctionPlaceholders(fn, replacements) {
- if (replacements && typeof replacements === "object") {
-
-
for (var p in replacements) {
-
if (replacements.hasOwnProperty(p)) {
-
var match = new RegExp("%" + p + "%", "g");
-
-
fn = fn.replace(match, replacements[p]);
-
} while(fn.indexOf(match) !== -1);
-
-
- }
- return fn;
-}
-/**
- * Replaces the "evaluate" method with one we can easily do substitution with.
-
- * @param {phantomjs.WebPage} page The WebPage object to overload
- */
-function overloadPageEvaluate(page) {
- page._evaluate = page.evaluate;
- page.evaluate = function(fn, replacements) { return page._evaluate(replaceFunctionPlaceholders(fn, replacements)); };
- return page;
-}
-/* Stubs a fake writeFile function into the test runner.
+/*
- * Stubs a fake writeFile function into the test runner.
*
- @param {phantomjs.WebPage} page The WebPage object to inject functions into.
- @param {string} key The name of the global object in which file data should
-
be stored for later retrieval.
*/
-// TODO: not bothering with error checking for now (closed environment)
function setupWriteFileFunction(page, key, path_separator) {
- page.evaluate(function(){
-
window["%resultsObj%"] = {};
-
window.fs_path_separator = "%fs_path_separator%";
- page.evaluate(function(key, path_separator){
-
-
window.fs_path_separator = path_separator;
-
console.log( "Registering __phantom_writeFile function with phantomjs runtime for " + key );
window.__phantom_writeFile = function(filename, text) {
-
window["%resultsObj%"][filename] = text;
-
console.log( "__phantom_writeFile stashing data to " + key + "/" + filename );
-
window[key][filename] = text;
};
- }, {resultsObj: key, fs_path_separator: path_separator});
- }, key, path_separator );
}
/**
@@ -135,9 +97,9 @@ function setupWriteFileFunction(page, key, path_separator) {
-
be the same key provided to setupWriteFileFunction.
*/
function getXmlResults(page, key) {
- return page.evaluate(function(){
-
return window["%resultsObj%"] || {};
- }, {resultsObj: key});
- return page.evaluate(function(key){
-
return window[key] || {};
- }, key );
}
/**
@@ -178,12 +140,15 @@ function processPage(status, page, resultsKey) {
};
var ival = setInterval(function(){
if (isFinished()) {
-
console.log( "PhantomJS test finished! Looking for results at " + resultsKey + "..." );
// get the results that need to be written to disk
var fs = require("fs"),
xml_results = getXmlResults(page, resultsKey),
output;
-
console.log( "Got Jasmine Junit-format results for " + resultsKey );
for (var filename in xml_results) {
if (xml_results.hasOwnProperty(filename) && (output = xml_results[filename]) && typeof(output) === "string") {
-
console.log( "Writing XML results to: " + filename );
fs.write(filename, output, "w");
}
}
--
1.8.5.2.msysgit.0