Commit 80a61c09 80a61c09fdd22518e07712eb7ee83cc0ac5b2112 by Nicolas Perriault

generalized callback contextualization

1 parent 79eae894
...@@ -282,7 +282,7 @@ ...@@ -282,7 +282,7 @@
282 message = isType(message, "string") && message.length > 0 ? message : DEFAULT_DIE_MESSAGE; 282 message = isType(message, "string") && message.length > 0 ? message : DEFAULT_DIE_MESSAGE;
283 this.log(message, "error"); 283 this.log(message, "error");
284 if (isType(this.options.onDie, "function")) { 284 if (isType(this.options.onDie, "function")) {
285 this.options.onDie(this, message, status); 285 this.options.onDie.call(this, this, message, status);
286 } 286 }
287 return this.exit(Number(status) > 0 ? Number(status) : 1); 287 return this.exit(Number(status) > 0 ? Number(status) : 1);
288 }, 288 },
...@@ -542,7 +542,7 @@ ...@@ -542,7 +542,7 @@
542 level = level && this.logLevels.indexOf(level) > -1 ? level : "debug"; 542 level = level && this.logLevels.indexOf(level) > -1 ? level : "debug";
543 space = space ? space : "phantom"; 543 space = space ? space : "phantom";
544 if (level === "error" && isType(this.options.onError, "function")) { 544 if (level === "error" && isType(this.options.onError, "function")) {
545 this.options.onError(this, message, space); 545 this.options.onError.call(this, this, message, space);
546 } 546 }
547 if (this.logLevels.indexOf(level) < this.logLevels.indexOf(this.options.logLevel)) { 547 if (this.logLevels.indexOf(level) < this.logLevels.indexOf(this.options.logLevel)) {
548 return this; // skip logging 548 return this; // skip logging
...@@ -624,7 +624,7 @@ ...@@ -624,7 +624,7 @@
624 if (new Date().getTime() - start > self.options.stepTimeout) { 624 if (new Date().getTime() - start > self.options.stepTimeout) {
625 if (self.step == stepNum + 1) { 625 if (self.step == stepNum + 1) {
626 if (isType(self.options.onStepTimeout, "function")) { 626 if (isType(self.options.onStepTimeout, "function")) {
627 self.options.onStepTimeout(self); 627 self.options.onStepTimeout.call(self, self);
628 } else { 628 } else {
629 self.die("Maximum step execution timeout exceeded for step " + stepNum, "error"); 629 self.die("Maximum step execution timeout exceeded for step " + stepNum, "error");
630 } 630 }
...@@ -643,7 +643,7 @@ ...@@ -643,7 +643,7 @@
643 } 643 }
644 } 644 }
645 if (isType(this.options.onStepComplete, "function")) { 645 if (isType(this.options.onStepComplete, "function")) {
646 this.options.onStepComplete(this, stepResult); 646 this.options.onStepComplete.call(this, this, stepResult);
647 } 647 }
648 if (!skipLog) { 648 if (!skipLog) {
649 this.log(stepInfo + ": done in " + (new Date().getTime() - this.startTime) + "ms.", "info"); 649 this.log(stepInfo + ": done in " + (new Date().getTime() - this.startTime) + "ms.", "info");
...@@ -691,7 +691,7 @@ ...@@ -691,7 +691,7 @@
691 this.log("Execution timeout set to " + this.options.timeout + 'ms', "info"); 691 this.log("Execution timeout set to " + this.options.timeout + 'ms', "info");
692 setTimeout(function(self) { 692 setTimeout(function(self) {
693 if (isType(self.options.onTimeout, "function")) { 693 if (isType(self.options.onTimeout, "function")) {
694 self.options.onTimeout(self); 694 self.options.onTimeout.call(self, self);
695 } else { 695 } else {
696 self.die("Timeout of " + self.options.timeout + "ms exceeded, exiting."); 696 self.die("Timeout of " + self.options.timeout + "ms exceeded, exiting.");
697 } 697 }
...@@ -699,7 +699,7 @@ ...@@ -699,7 +699,7 @@
699 } 699 }
700 if (isType(this.options.onPageInitialized, "function")) { 700 if (isType(this.options.onPageInitialized, "function")) {
701 this.log("Post-configuring WebPage instance", "debug"); 701 this.log("Post-configuring WebPage instance", "debug");
702 this.options.onPageInitialized(this.page); 702 this.options.onPageInitialized.call(this, this.page);
703 } 703 }
704 if (isType(location, "string") && location.length > 0) { 704 if (isType(location, "string") && location.length > 0) {
705 if (isType(then, "function")) { 705 if (isType(then, "function")) {
...@@ -871,7 +871,7 @@ ...@@ -871,7 +871,7 @@
871 if (!condition) { 871 if (!condition) {
872 self.log("Casper.waitFor() timeout", "warning"); 872 self.log("Casper.waitFor() timeout", "warning");
873 if (isType(onTimeout, "function")) { 873 if (isType(onTimeout, "function")) {
874 onTimeout(self); 874 onTimeout.call(self, self);
875 } else { 875 } else {
876 self.die("Expired timeout, exiting.", "error"); 876 self.die("Expired timeout, exiting.", "error");
877 } 877 }
...@@ -1681,7 +1681,7 @@ ...@@ -1681,7 +1681,7 @@
1681 message += ': ' + casper.requestUrl; 1681 message += ': ' + casper.requestUrl;
1682 casper.log(message, "warning"); 1682 casper.log(message, "warning");
1683 if (isType(casper.options.onLoadError, "function")) { 1683 if (isType(casper.options.onLoadError, "function")) {
1684 casper.options.onLoadError(casper, casper.requestUrl, status); 1684 casper.options.onLoadError.call(casper, casper, casper.requestUrl, status);
1685 } 1685 }
1686 } 1686 }
1687 if (casper.options.clientScripts) { 1687 if (casper.options.clientScripts) {
...@@ -1717,7 +1717,7 @@ ...@@ -1717,7 +1717,7 @@
1717 }; 1717 };
1718 page.onResourceReceived = function(resource) { 1718 page.onResourceReceived = function(resource) {
1719 if (isType(casper.options.onResourceReceived, "function")) { 1719 if (isType(casper.options.onResourceReceived, "function")) {
1720 casper.options.onResourceReceived(casper, resource); 1720 casper.options.onResourceReceived.call(casper, casper, resource);
1721 } 1721 }
1722 if (resource.url === casper.requestUrl && resource.stage === "start") { 1722 if (resource.url === casper.requestUrl && resource.stage === "start") {
1723 casper.currentHTTPStatus = resource.status; 1723 casper.currentHTTPStatus = resource.status;
...@@ -1729,7 +1729,7 @@ ...@@ -1729,7 +1729,7 @@
1729 }; 1729 };
1730 page.onResourceRequested = function(request) { 1730 page.onResourceRequested = function(request) {
1731 if (isType(casper.options.onResourceRequested, "function")) { 1731 if (isType(casper.options.onResourceRequested, "function")) {
1732 casper.options.onResourceRequested(casper, request); 1732 casper.options.onResourceRequested.call(casper, casper, request);
1733 } 1733 }
1734 }; 1734 };
1735 return page; 1735 return page;
......
1 # a small subset of the run.js written in coffeescript 1 # A small subset of the run.js written in coffeescript
2 2
3 phantom.injectJs "casper.js" 3 phantom.injectJs "casper.js"
4 casper = new phantom.Casper( 4
5 casper = new phantom.Casper
5 faultTolerant: false 6 faultTolerant: false
6 verbose: true 7 verbose: true
7 ) 8 onStepComplete: -> @test.comment "step completed"
8 9
9 casper.start "tests/site/index.html", -> 10 casper.start "tests/site/index.html", ->
10 @test.assertTitle "CasperJS test index", "Casper.start() casper can start itself an open an url" 11 @test.assertTitle "CasperJS test index", "Casper.start() casper can start itself an open an url"
......