Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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