Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 38 additions and 27 deletions.
  1. +37 −26 lib/wrapper/wrapper.js
  2. +1 −1 package.json
View
63 lib/wrapper/wrapper.js
@@ -15,7 +15,14 @@ var waitTimer,
testTimer,
file = phantom.args[0],
timeout = parseInt(phantom.args[1], 10),
- timer;
+ timer,
+ debug = false,
+ log = function(a, b) {
+ b = (typeof b === 'undefined') ? '' : b;
+ if (debug) {
+ console.log(a, b);
+ }
+ };
var injectGetYUITest = function() {
window.TestResults = null;
@@ -44,15 +51,13 @@ var injectGetYUITest = function() {
json.coverage = window.__coverage__;
json = JSON.stringify(json);
}
- //console.log('Found YUITest, checking results');
- //console.log(json);
return json;
}
};
};
var startTest = function(page, cb) {
- //console.log('Checking for YUITest');
+ log('Checking for YUITest');
testTimer = setInterval(function() {
//console.log('Checking..');
var status = page.evaluate(function() {
@@ -66,7 +71,7 @@ var startTest = function(page, cb) {
}
return (t ? true : false);
});
- //console.log('Tester: ', status);
+ log('Tester: ', status);
if (status) {
clearInterval(testTimer);
cb(status);
@@ -96,13 +101,13 @@ var waitForResults = function(page, cb) {
waitTimer = setInterval(function() {
waitCounter++;
- //console.log('Waiting on Results', waitCounter);
+ log('Waiting on Results', waitCounter);
var status = page.evaluate(function() {
return window.getYUITestResults();
});
if (status) {
clearInterval(waitTimer);
- //console.log('Found Results');
+ log('Found Results');
cb(status);
return;
}
@@ -112,8 +117,9 @@ var waitForResults = function(page, cb) {
};
var executeTest = function(file, cb) {
-
- var page = require('webpage').create();
+ log('executing tests in ', file);
+ var page = require('webpage').create(),
+ opened = false;
page.settings.javascriptEnabled = true;
page.settings.localToRemoteUrlAccessEnabled = true;
@@ -132,27 +138,32 @@ var executeTest = function(file, cb) {
};
page.onError = function(msg, trace) {
throwError(msg, trace);
-
};
-
- //console.log('Opening File', file);
- page.open(file, function(status) {
- if (status === 'fail') {
- throwError('Phantom failed to load this page');
- }
- //console.log('Status: ', status);
- //console.log('Injecting getYUITest');
- page.evaluate(injectGetYUITest);
-
- startTest(page, function() {
- //console.log('YUITest Found..');
- waitForResults(page, function(results) {
- //console.log('YUITest Results Returned');
- cb(page, results);
+ if (!opened) {
+ log('Opening File', file, opened);
+ page.open(file, function(status) {
+ log('Opened File', file);
+ if (opened) {
+ return;
+ }
+ if (status === 'fail') {
+ throwError('Phantom failed to load this page');
+ }
+ log('Status: ', status);
+ log('Injecting getYUITest');
+ page.evaluate(injectGetYUITest);
+
+ startTest(page, function() {
+ log('YUITest Found..');
+ waitForResults(page, function(results) {
+ log('YUITest Results Returned');
+ cb(page, results);
+ });
});
+ opened = true;
});
- });
+ }
};
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "grover",
"description": "PhantomJS wrapper for YUITest",
- "version": "0.0.28",
+ "version": "0.0.29",
"engines": { "node": ">=0.4.0" },
"bin": {
"grover": "./bin/grover.js"

No commit comments for this range

Something went wrong with that request. Please try again.