var methods = require("methods")
  , Promise = require("bluebird")
  , supertest = require("supertest");

// Alias both .del() and .delete() to supertest's .del()
methods.push("del");
var methodAliases = {
  "delete": "del"
};

function then(onFulfilled, onRejected) {
  var end = Promise.promisify(this.end, this);
  return end().then(onFulfilled, onRejected);
}

// Creates a new object that wraps `factory`, where each HTTP method (`get`,
// `post`, etc.) is overriden to inject a `then` method into the returned `Test`
// instance.
function wrap(factory) {
  var out = {};

  methods.forEach(function (method) {
    out[method] = function () {
      var methodName = methodAliases[method] || method;
      var test = factory[methodName].apply(factory, arguments);
      test.then = then;
      return test;
    };
  });

  return out;
}

module.exports = function () {
  var request = supertest.apply(null, arguments);
  return wrap(request);
};

module.exports.agent = function () {
  var agent = supertest.agent.apply(null, arguments);
  return wrap(agent);
};

@@ -106,124 +106,83 @@
 %0A// 
-Alias both .del() and .delete() to supertest's .del()%0Amethods.push(%22del%22);%0Avar methodAliases = %7B%0A  %22delete%22: %22del%22%0A%7D
+Support SuperTest's historical %60del%60 alias for %60delete%60%0Amethods.push(%22del%22)
 ;%0A%0Af
@@ -604,64 +604,8 @@
 ) %7B%0A
-      var methodName = methodAliases%5Bmethod%5D %7C%7C method;%0A
     
@@ -635,12 +635,8 @@
 thod
-Name
 %5D.ap

support `del` by passing through to upstream's alias