Commits

Sean Wilkinson  committed f2227ba

Fully automated the tests to demonstrate that PhantomJS can be used to power QMachine, too

  • Participants
  • Parent commits f0f1496

Comments (0)

Files changed (1)

File tests/tests.js

 
  // Declarations
 
-    var exit, mothership, n, queue, register_test, run_test;
+    var exit, mothership, n, queue, register_test, submit, volunteer;
 
  // Definitions
 
         return;
     };
 
-    run_test = function (y, f) {
+    submit = function (y, f) {
      // This function needs documentation.
         if (n === undefined) {
-            console.log('Running ' + queue.length + ' tests ...');
+            console.log('Submitting ' + queue.length + ' tests ...');
             n = queue.length;
         }
         var homepage = require('webpage').create();
         };
         homepage.onError = function (message) {
          // This function needs documentation.
-            console.error('Error:', JSON.stringify(message, undefined, 4));
+            var y = JSON.stringify(message, undefined, 4);
+            console.error('Submitter Error:', y);
             return exit(1);
         };
         homepage.onResourceReceived = function () {
         return;
     };
 
+    volunteer = function (f) {
+     // This function needs documentation.
+        var homepage = require('webpage').create();
+        homepage.onConsoleMessage = function (message) {
+         // This function needs documentation.
+            console.log(message);
+            return;
+        };
+        homepage.onError = function (message) {
+         // This function needs documentation.
+            var y = JSON.stringify(message, undefined, 4);
+            console.error('Volunteer Error:', y);
+            return;
+        };
+        homepage.onResourceReceived = function () {
+         // This function needs documentation.
+            return;
+        };
+        homepage.onResourceRequested = function () {
+         // This function needs documentation.
+            //console.log(request.method, request.url);
+            return;
+        };
+        homepage.open(mothership, function (status) {
+         // This function needs documentation.
+            if (status !== 'success') {
+                console.error('Something went wrong:', status);
+                return exit(1);
+            }
+            homepage.evaluate(f);
+            return;
+        });
+        return;
+    };
+
  // Test definitions
 
     console.log('NOTE: Remember to launch a worker for "sean"!');
  // Invocations
 
     (function () {
-
+     // This function configures a submitter.
         var i;
-
-        n = queue.length;
-
-        for (i = 0; i < n; i += 1) {
-            run_test(queue[i].y, queue[i].f);
+        for (i = 0, n = queue.length; i < n; i += 1) {
+            submit(queue[i].y, queue[i].f);
         }
-
         return;
+    }());
 
+    (function () {
+     // This function configures a volunteer.
+        volunteer(function f() {
+         // This function runs inside the volunteer context :-)
+            if (window.hasOwnProperty('jQuery') === false) {
+             // We will assume that jQuery will eventually load.
+                setTimeout(f, 100);
+                return;
+            }
+            if (window.hasOwnProperty('QM') === false) {
+             // We will also assume that QMachine will eventually load.
+                setTimeout(f, 100);
+                return;
+            }
+            window.QM.box = 'sean';
+            window.$('#QM-volunteer-input').click();
+            return;
+        });
+        return;
     }());
 
  // That's all, folks!