Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove response call.

  • Loading branch information...
commit 8148480ede719082db972a81e4f213061f8703cc 1 parent 631170d
@philjackson authored
Showing with 0 additions and 141 deletions.
  1. +0 −141 vendor/assert-extras.js
View
141 vendor/assert-extras.js
@@ -157,144 +157,3 @@ assert.isNotEnumerable = function (object, property, message) {
assert.fail(object, property, message, "isNotEnumerable", assert.isNotEnumerable);
}
}
-
-http = require( "http" );
-
-// for now...
-var port = 2000;
-
-assert.response = function(server, req, res, msg){
- // Check that the server is ready or defer
- if (!server.fd) {
- server.__deferred = server.__deferred || [];
- server.__deferred.push(arguments);
- server.listen(server.__port = port++, '127.0.0.1', function(){
- server.__listening = true;
- if (server.__deferred) {
- server.__deferred.forEach(function(args){
- assert.response.apply(assert, args);
- });
- server.__deferred = null;
- }
- });
- return;
- }
-
- // The socket was created but is not yet listening, so keep deferring
- if (!server.__listening) {
- server.__deferred.push(arguments);
- return;
- }
-
- // Callback as third or fourth arg
- var callback = typeof res === 'function'
- ? res
- : typeof msg === 'function'
- ? msg
- : function(){};
-
- // Default messate to test title
- if (typeof msg === 'function') msg = null;
- msg = msg || assert.testTitle;
- msg += '. ';
-
- // Pending responses
- server.__pending = server.__pending || 0;
- server.__pending++;
-
- // Create client
- if (!server.fd) {
- server.listen(server.__port = port++, '127.0.0.1', issue);
- } else {
- issue();
- }
-
- function issue(){
- if (!server.client)
- server.client = http.createClient(server.__port);
-
- // Issue request
- var timer,
- client = server.client,
- method = req.method || 'GET',
- status = res.status || res.statusCode,
- data = req.data || req.body,
- requestTimeout = req.timeout || 0;
-
- var request = client.request(method, req.url, req.headers);
-
- var check = function() {
- if (--server.__pending === 0) {
- server.close();
- server.__listening = false;
- }
- };
-
- // Timeout
- if (requestTimeout) {
- timer = setTimeout(function(){
- check();
- delete req.timeout;
- assert.fail(msg + 'Request timed out after ' + requestTimeout + 'ms.');
- }, requestTimeout);
- }
-
- if (data) request.write(data);
- request.on('response', function(response){
- response.body = '';
- response.setEncoding('utf8');
- response.on('data', function(chunk){ response.body += chunk; });
- response.on('end', function(){
- if (timer) clearTimeout(timer);
-
- // Assert response body
- if (res.body !== undefined) {
- var eql = res.body instanceof RegExp
- ? res.body.test(response.body)
- : res.body === response.body;
- assert.ok(
- eql,
- msg + 'Invalid response body (' + req.url + ').\n'
- + ' Expected: ' + sys.inspect(res.body) + '\n'
- + ' Got: ' + sys.inspect(response.body)
- );
- }
-
- // Assert response status
- if (typeof status === 'number') {
- assert.equal(
- response.statusCode,
- status,
- msg + 'Invalid response status code (' + req.url + ').\n'
- + ' Expected: {' + status + '}\n'
- + ' Got: {' + response.statusCode + '}'
- );
- }
-
- // Assert response headers
- if (res.headers) {
- var keys = Object.keys(res.headers);
- for (var i = 0, len = keys.length; i < len; ++i) {
- var name = keys[i],
- actual = response.headers[name.toLowerCase()],
- expected = res.headers[name],
- eql = expected instanceof RegExp
- ? expected.test(actual)
- : expected == actual;
- assert.ok(
- eql,
- msg + colorize('Invalid response header {' + name + '}.\n'
- + ' Expected: {' + expected + '}\n'
- + ' Got: {' + actual + '}')
- );
- }
- }
-
- // Callback
- callback(response);
- check();
- });
- });
- request.end();
- }
-};
Please sign in to comment.
Something went wrong with that request. Please try again.