index.js 770 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Module dependencies.
  3. */
  4. var methods = require('methods');
  5. var Test = require('./lib/test');
  6. var http = require('http');
  7. /**
  8. * Test against the given `app`,
  9. * returning a new `Test`.
  10. *
  11. * @param {Function|Server} app
  12. * @return {Test}
  13. * @api public
  14. */
  15. module.exports = function(app) {
  16. var obj = {};
  17. if (typeof app === 'function') {
  18. app = http.createServer(app); // eslint-disable-line no-param-reassign
  19. }
  20. methods.forEach(function(method) {
  21. obj[method] = function(url) {
  22. return new Test(app, method, url);
  23. };
  24. });
  25. // Support previous use of del
  26. obj.del = obj.delete;
  27. return obj;
  28. };
  29. /**
  30. * Expose `Test`
  31. */
  32. module.exports.Test = Test;
  33. /**
  34. * Expose the agent function
  35. */
  36. module.exports.agent = require('./lib/agent');