Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added callback support for queued commands

  • Loading branch information...
commit b8b8f20616ae73ed1df274abf5f9d595f57c06e7 1 parent 87d22bc
@tj tj authored
Showing with 22 additions and 4 deletions.
  1. +5 −2 examples/google.js
  2. +17 −2 lib/soda/client.js
View
7 examples/google.js
@@ -3,7 +3,8 @@
* Module dependencies.
*/
-var soda = require('../index');
+var soda = require('../index')
+ , assert = require('assert');
var browser = soda.createClient({
host: 'localhost',
@@ -18,7 +19,9 @@ browser
.open('/')
.type('q', 'Hello World')
.clickAndWait('btnG')
- .assertTitle('Hello World - Google Search')
+ .getTitle(function(title){
+ assert.ok(~title.indexOf('Hello World'))
+ })
.testComplete()
.done(function(err, body, res){
if (err) throw err;
View
19 lib/soda/client.js
@@ -161,10 +161,25 @@ Client.prototype.done = function(fn){
*/
Client.prototype.enqueue = function(cmd, args, fn){
- var self = this;
+ var self = this
+ , len = args.length;
+
+ // Indirect callback support
+ if (typeof args[len - 1] === 'function') {
+ fn = args.pop();
+ }
+
this.queue.push(function(){
self.command(cmd, args, function(err, body, res){
- if (!err && fn) fn(body, res);
+ // Callback support
+ if (!err && fn) {
+ try {
+ fn(body, res);
+ } catch (err) {
+ return self.done(err, body, res);
+ }
+ }
+
if (err) {
self.done(err, body, res);
} else if (self.queue.length) {
Please sign in to comment.
Something went wrong with that request. Please try again.