File tree 3 files changed +34
-6
lines changed
3 files changed +34
-6
lines changed Original file line number Diff line number Diff line change 4
4
* Module dependencies.
5
5
*/
6
6
const methods = require ( 'methods' ) ;
7
- const http = require ( 'http' ) ;
8
7
let http2 ;
9
8
try {
10
9
http2 = require ( 'http2' ) ; // eslint-disable-line global-require
@@ -32,15 +31,12 @@ module.exports = function(app, options = {}) {
32
31
'supertest: this version of Node.js does not support http2'
33
32
) ;
34
33
}
35
- app = http2 . createServer ( app ) ; // eslint-disable-line no-param-reassign
36
- } else {
37
- app = http . createServer ( app ) ; // eslint-disable-line no-param-reassign
38
34
}
39
35
}
40
36
41
37
methods . forEach ( function ( method ) {
42
38
obj [ method ] = function ( url ) {
43
- var test = new Test ( app , method , url ) ;
39
+ var test = new Test ( app , method , url , options . http2 ) ;
44
40
if ( options . http2 ) {
45
41
test . http2 ( ) ;
46
42
}
Original file line number Diff line number Diff line change 5
5
*/
6
6
7
7
const { inspect } = require ( 'util' ) ;
8
+ const http = require ( 'http' ) ;
8
9
const { STATUS_CODES } = require ( 'http' ) ;
9
10
const { Server } = require ( 'tls' ) ;
10
11
const { deepStrictEqual } = require ( 'assert' ) ;
11
12
const { Request } = require ( 'superagent' ) ;
13
+ let http2 ;
14
+ try {
15
+ http2 = require ( 'http2' ) ; // eslint-disable-line global-require
16
+ } catch ( _ ) {
17
+ // eslint-disable-line no-empty
18
+ }
12
19
13
20
/** @typedef {import('superagent').Response } Response */
14
21
@@ -22,9 +29,17 @@ class Test extends Request {
22
29
* @param {String } path
23
30
* @api public
24
31
*/
25
- constructor ( app , method , path ) {
32
+ constructor ( app , method , path , optHttp2 ) {
26
33
super ( method . toUpperCase ( ) , path ) ;
27
34
35
+ if ( typeof app === 'function' ) {
36
+ if ( optHttp2 ) {
37
+ app = http2 . createServer ( app ) ; // eslint-disable-line no-param-reassign
38
+ } else {
39
+ app = http . createServer ( app ) ; // eslint-disable-line no-param-reassign
40
+ }
41
+ }
42
+
28
43
this . redirects ( 0 ) ;
29
44
this . buffer ( ) ;
30
45
this . app = app ;
Original file line number Diff line number Diff line change @@ -79,6 +79,23 @@ describe('request(app)', function () {
79
79
} ) ;
80
80
} ) ;
81
81
82
+ it ( 'should not ECONNRESET on multiple simultaneous tests' , function ( done ) {
83
+ const app = express ( ) ;
84
+
85
+ app . get ( '/' , function ( req , res ) {
86
+ res . send ( 'hey' ) ;
87
+ } ) ;
88
+
89
+ const test = request ( app ) ;
90
+
91
+ const requestCount = 10 ;
92
+
93
+ const requests = [ ] ;
94
+ for ( let i = 0 ; i < requestCount ; i += 1 ) requests . push ( test . get ( '/' ) ) ;
95
+
96
+ global . Promise . all ( requests ) . then ( ( ) => done ( ) , done ) ;
97
+ } ) ;
98
+
82
99
it ( 'should work with an active server' , function ( done ) {
83
100
const app = express ( ) ;
84
101
let server ;
You can’t perform that action at this time.
0 commit comments