dalekjs/dalek — pull request #35 by threez (2013-12-02 10:37:19+00:00)
Title: Added low level API to use node promises and functions

* Allow tests to use first/then to reuse javascript test code
* Adds node/promise to call regular node code

The first one enables one to write more reusable tests like this:

```javascript
var Frontend = require('../lib/frontend').Frontend;

module.exports = {
'customer can login and logout' : function(test){
test.first(Frontend.login)
.then(Frontend.logout)
.done();
},
'has a customer profile': function(test){
test.first(Frontend.login)
.then(Frontend.verifyCustomerProfile)
.then(Frontend.logout)
.done();
}
};
```

where the frontend library contains code that looks like this:

```javascript
module.exports = {
Frontend: {
login: function() {
return this.open('http://localhost:3000/login')
.type('#login-email', 'user')
.type('#login-password', 'secret')
.click('#login-submit')
.waitForElement('#logoutNavLink')
.assert.visible('#logoutNavLink')
.assert.attr('#logoutNavLink img', 'alt', 'Logout');
},
logout: function() {
// ...
},
verifyCustomerProfile: function() {
// ...
}
}
};
```

The second allows the test to execute node code like this:

```javascript
var db = require('db');

module.exports = {
'customer can login and logout' : function(test){
test.
first(Frontend.login)
.then(Frontend.logout)
.done();
},
'has a customer profile': function(test){
test.first(Frontend.login)
.then(Frontend.verifyCustomerProfile)
.then(Frontend.logout)
.done();
}
};
```