Skip to content

Commit

Permalink
Merge pull request #749 from jimmywarting/misc
Browse files Browse the repository at this point in the history
Misc stuff
  • Loading branch information
niftylettuce committed Jan 5, 2022
2 parents 1d70492 + aae4d8e commit a70c1a0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
11 changes: 6 additions & 5 deletions index.js
Expand Up @@ -3,9 +3,10 @@
/**
* Module dependencies.
*/
var methods = require('methods');
var Test = require('./lib/test');
var http = require('http');
const methods = require('methods');
const http = require('http');
const Test = require('./lib/test.js');
const agent = require('./lib/agent.js');

/**
* Test against the given `app`,
Expand All @@ -16,7 +17,7 @@ var http = require('http');
* @api public
*/
module.exports = function(app) {
var obj = {};
const obj = {};

if (typeof app === 'function') {
app = http.createServer(app); // eslint-disable-line no-param-reassign
Expand All @@ -42,4 +43,4 @@ module.exports.Test = Test;
/**
* Expose the agent function
*/
module.exports.agent = require('./lib/agent');
module.exports.agent = agent;
22 changes: 11 additions & 11 deletions lib/agent.js
Expand Up @@ -4,16 +4,10 @@
* Module dependencies.
*/

var Agent = require('superagent').agent;
var methods = require('methods');
var http = require('http');
var Test = require('./test');

/**
* Expose `Agent`.
*/

module.exports = TestAgent;
const { agent: Agent } = require('superagent');
const methods = require('methods');
const http = require('http');
const Test = require('./test.js');

/**
* Initialize a new `TestAgent`.
Expand Down Expand Up @@ -50,7 +44,7 @@ TestAgent.prototype.host = function(host) {
// override HTTP verb methods
methods.forEach(function(method) {
TestAgent.prototype[method] = function(url, fn) { // eslint-disable-line no-unused-vars
var req = new Test(this.app, method.toUpperCase(), url, this._host);
const req = new Test(this.app, method.toUpperCase(), url, this._host);
req.ca(this._ca);
req.cert(this._cert);
req.key(this._key);
Expand All @@ -69,3 +63,9 @@ methods.forEach(function(method) {
});

TestAgent.prototype.del = TestAgent.prototype.delete;

/**
* Expose `Agent`.
*/

module.exports = TestAgent;
14 changes: 7 additions & 7 deletions lib/test.js
Expand Up @@ -10,6 +10,8 @@ const { Server } = require('https');
const { deepStrictEqual } = require('assert');
const { Request } = require('superagent');

/** @typedef {import('superagent').Response} Response */

class Test extends Request {
/**
* Initialize a new `Test` with the given `app`,
Expand Down Expand Up @@ -111,18 +113,16 @@ class Test extends Request {
* @api public
*/
end(fn) {
const self = this;
const server = this._server;
const end = Request.prototype.end;

end.call(this, function (err, res) {
super.end((err, res) => {
const localAssert = () => {
this.assert(err, res, fn);
};

if (server && server._handle) return server.close(localAssert);

localAssert();

function localAssert() {
self.assert(err, res, fn);
}
});

return this;
Expand Down
2 changes: 1 addition & 1 deletion test/supertest.js
@@ -1,6 +1,5 @@
'use strict';

const request = require('..');
const https = require('https');
const fs = require('fs');
const path = require('path');
Expand All @@ -9,6 +8,7 @@ const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const nock = require('nock');
const request = require('../index.js');

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

Expand Down

0 comments on commit a70c1a0

Please sign in to comment.