From a0a5d57cacdfd9966418598338d4efcbb8093121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Tue, 4 Jan 2022 22:34:22 +0100 Subject: [PATCH 1/8] more const --- lib/agent.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/agent.js b/lib/agent.js index c6ee7869..fc89ad0c 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -4,16 +4,15 @@ * 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'); /** * Initialize a new `TestAgent`. @@ -50,7 +49,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); From 17cf193c9e9984dc3920d0aeee413018928bdb76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Tue, 4 Jan 2022 22:35:16 +0100 Subject: [PATCH 2/8] move exports to the bottom --- lib/agent.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/agent.js b/lib/agent.js index fc89ad0c..694210d1 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -4,11 +4,6 @@ * Module dependencies. */ -/** - * Expose `Agent`. - */ - -module.exports = TestAgent; const { agent: Agent } = require('superagent'); const methods = require('methods'); const http = require('http'); @@ -68,3 +63,9 @@ methods.forEach(function(method) { }); TestAgent.prototype.del = TestAgent.prototype.delete; + +/** + * Expose `Agent`. + */ + +module.exports = TestAgent; From d2d96161f0d7dfc42fcebc8954f41b5345625cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Tue, 4 Jan 2022 22:35:57 +0100 Subject: [PATCH 3/8] user super and arrow fn --- lib/test.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/test.js b/lib/test.js index 58fa87c7..c0296b49 100644 --- a/lib/test.js +++ b/lib/test.js @@ -111,18 +111,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; From 1dc25a101ae87bcc3210afb49841ce71a66f5f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Tue, 4 Jan 2022 22:36:36 +0100 Subject: [PATCH 4/8] don't mixup superagent.Response \w fetch.Response --- lib/test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/test.js b/lib/test.js index c0296b49..d835fbde 100644 --- a/lib/test.js +++ b/lib/test.js @@ -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`, From 19dcd1ea9aa3132ea4314e302130eb5bbccae1a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Tue, 4 Jan 2022 22:47:10 +0100 Subject: [PATCH 5/8] only use require in the top of the file --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 8fd46dbc..68f87fe1 100644 --- a/index.js +++ b/index.js @@ -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`, @@ -42,4 +43,4 @@ module.exports.Test = Test; /** * Expose the agent function */ -module.exports.agent = require('./lib/agent'); +module.exports.agent = agent From cdb0ad9ebc0d8c22d8a2bea7ccc0195883037a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Tue, 4 Jan 2022 22:47:31 +0100 Subject: [PATCH 6/8] use explicit path --- lib/agent.js | 2 +- test/supertest.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/agent.js b/lib/agent.js index 694210d1..0afb7c77 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -7,7 +7,7 @@ const { agent: Agent } = require('superagent'); const methods = require('methods'); const http = require('http'); -const Test = require('./test'); +const Test = require('./test.js'); /** * Initialize a new `TestAgent`. diff --git a/test/supertest.js b/test/supertest.js index 0a77decf..7561d1f2 100644 --- a/test/supertest.js +++ b/test/supertest.js @@ -1,6 +1,5 @@ 'use strict'; -const request = require('..'); const https = require('https'); const fs = require('fs'); const path = require('path'); @@ -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'; From f17be2a7dfe92424b1fdb0647de853991097a893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Tue, 4 Jan 2022 22:48:57 +0100 Subject: [PATCH 7/8] add missing comma make lint happy --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 68f87fe1..2f718fef 100644 --- a/index.js +++ b/index.js @@ -43,4 +43,4 @@ module.exports.Test = Test; /** * Expose the agent function */ -module.exports.agent = agent +module.exports.agent = agent; From aae4d8ea88cafbd1a40d0c2c4881bc50b7001de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Tue, 4 Jan 2022 22:49:08 +0100 Subject: [PATCH 8/8] var to const --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2f718fef..dc206a49 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ const agent = require('./lib/agent.js'); * @api public */ module.exports = function(app) { - var obj = {}; + const obj = {}; if (typeof app === 'function') { app = http.createServer(app); // eslint-disable-line no-param-reassign