Skip to content

Commit a70c1a0

Browse files
authoredJan 5, 2022
Merge pull request #749 from jimmywarting/misc
Misc stuff
2 parents 1d70492 + aae4d8e commit a70c1a0

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed
 

‎index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
/**
44
* Module dependencies.
55
*/
6-
var methods = require('methods');
7-
var Test = require('./lib/test');
8-
var http = require('http');
6+
const methods = require('methods');
7+
const http = require('http');
8+
const Test = require('./lib/test.js');
9+
const agent = require('./lib/agent.js');
910

1011
/**
1112
* Test against the given `app`,
@@ -16,7 +17,7 @@ var http = require('http');
1617
* @api public
1718
*/
1819
module.exports = function(app) {
19-
var obj = {};
20+
const obj = {};
2021

2122
if (typeof app === 'function') {
2223
app = http.createServer(app); // eslint-disable-line no-param-reassign
@@ -42,4 +43,4 @@ module.exports.Test = Test;
4243
/**
4344
* Expose the agent function
4445
*/
45-
module.exports.agent = require('./lib/agent');
46+
module.exports.agent = agent;

‎lib/agent.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@
44
* Module dependencies.
55
*/
66

7-
var Agent = require('superagent').agent;
8-
var methods = require('methods');
9-
var http = require('http');
10-
var Test = require('./test');
11-
12-
/**
13-
* Expose `Agent`.
14-
*/
15-
16-
module.exports = TestAgent;
7+
const { agent: Agent } = require('superagent');
8+
const methods = require('methods');
9+
const http = require('http');
10+
const Test = require('./test.js');
1711

1812
/**
1913
* Initialize a new `TestAgent`.
@@ -50,7 +44,7 @@ TestAgent.prototype.host = function(host) {
5044
// override HTTP verb methods
5145
methods.forEach(function(method) {
5246
TestAgent.prototype[method] = function(url, fn) { // eslint-disable-line no-unused-vars
53-
var req = new Test(this.app, method.toUpperCase(), url, this._host);
47+
const req = new Test(this.app, method.toUpperCase(), url, this._host);
5448
req.ca(this._ca);
5549
req.cert(this._cert);
5650
req.key(this._key);
@@ -69,3 +63,9 @@ methods.forEach(function(method) {
6963
});
7064

7165
TestAgent.prototype.del = TestAgent.prototype.delete;
66+
67+
/**
68+
* Expose `Agent`.
69+
*/
70+
71+
module.exports = TestAgent;

‎lib/test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const { Server } = require('https');
1010
const { deepStrictEqual } = require('assert');
1111
const { Request } = require('superagent');
1212

13+
/** @typedef {import('superagent').Response} Response */
14+
1315
class Test extends Request {
1416
/**
1517
* Initialize a new `Test` with the given `app`,
@@ -111,18 +113,16 @@ class Test extends Request {
111113
* @api public
112114
*/
113115
end(fn) {
114-
const self = this;
115116
const server = this._server;
116-
const end = Request.prototype.end;
117117

118-
end.call(this, function (err, res) {
118+
super.end((err, res) => {
119+
const localAssert = () => {
120+
this.assert(err, res, fn);
121+
};
122+
119123
if (server && server._handle) return server.close(localAssert);
120124

121125
localAssert();
122-
123-
function localAssert() {
124-
self.assert(err, res, fn);
125-
}
126126
});
127127

128128
return this;

‎test/supertest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const request = require('..');
43
const https = require('https');
54
const fs = require('fs');
65
const path = require('path');
@@ -9,6 +8,7 @@ const express = require('express');
98
const bodyParser = require('body-parser');
109
const cookieParser = require('cookie-parser');
1110
const nock = require('nock');
11+
const request = require('../index.js');
1212

1313
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
1414

0 commit comments

Comments
 (0)
Please sign in to comment.