Comparing version 0.3.1 to 0.4.0
0.4.0 / 2012-10-18 | ||
================== | ||
* add url support [vesln] | ||
0.3.1 / 2012-10-01 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -40,7 +40,5 @@ | ||
this._fields = {}; | ||
var addr = app.address(); | ||
var portno = addr ? addr.port : port++; | ||
if (!addr) app.listen(portno); | ||
var protocol = app instanceof https.Server ? 'https' : 'http'; | ||
this.url = protocol + '://127.0.0.1:' + portno + path; | ||
this.url = 'string' == typeof app | ||
? app + path | ||
: this.serverAddress(app, path); | ||
} | ||
@@ -55,2 +53,19 @@ | ||
/** | ||
* Returns a URL, extracted from a server. | ||
* | ||
* @param {Server} app | ||
* @param {String} path | ||
* @returns {String} URL address | ||
* @api private | ||
*/ | ||
Test.prototype.serverAddress = function(app, path){ | ||
var addr = app.address(); | ||
var portno = addr ? addr.port : port++; | ||
if (!addr) app.listen(portno); | ||
var protocol = app instanceof https.Server ? 'https' : 'http'; | ||
return protocol + '://127.0.0.1:' + portno + path; | ||
}; | ||
/** | ||
* Expectations: | ||
@@ -57,0 +72,0 @@ * |
{ | ||
"name": "supertest", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Super-agent driven library for testing HTTP servers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -53,2 +53,21 @@ # SuperTest | ||
If you are using the `.end()` method `.expect()` assertions that fail will | ||
not throw - they will return the assertion as an error to the `.end()` callback. In | ||
order to fail the test case, you will need to rethrow or pass `err` to `done()`, as follows: | ||
```js | ||
describe('GET /users', function(){ | ||
it('respond with json', function(done){ | ||
request(app) | ||
.get('/user') | ||
.set('Accept', 'application/json') | ||
.expect(200) | ||
.end(function(err, res){ | ||
if (err) return done(err); | ||
done() | ||
}); | ||
}) | ||
}) | ||
``` | ||
Anything you can do with superagent, you can do with supertest - for example multipart file uploads! | ||
@@ -59,3 +78,3 @@ | ||
.post('/') | ||
.attach('test/fixtures/homeboy.jpg', 'avatar') | ||
.attach('avatar', 'test/fixtures/homeboy.jpg') | ||
... | ||
@@ -62,0 +81,0 @@ ``` |
@@ -43,2 +43,20 @@ | ||
it('should work with remote server', function(done){ | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
res.send('hey'); | ||
}); | ||
var server = app.listen(4001, function(){ | ||
request('http://localhost:4001') | ||
.get('/') | ||
.end(function(err, res){ | ||
res.should.have.status(200); | ||
res.text.should.equal('hey'); | ||
done(); | ||
}); | ||
}); | ||
}) | ||
it('should work with a https server', function(done){ | ||
@@ -45,0 +63,0 @@ var app = express(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17808
445
114