@depup/supertest 7.2.2-depup.0 → 7.3.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -459
- package/changes.json +10 -0
- package/index.js +6 -1
- package/lib/cookies/assertion.js +4 -1
- package/lib/test.js +106 -39
- package/package.json +25 -4
package/README.md
CHANGED
|
@@ -1,471 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @depup/supertest
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
[](https://codecov.io/gh/ladjs/supertest)
|
|
5
|
-
[](https://github.com/sindresorhus/xo)
|
|
6
|
-
[](https://github.com/prettier/prettier)
|
|
7
|
-
[](https://lass.js.org)
|
|
8
|
-
[](LICENSE)
|
|
3
|
+
> Dependency-bumped version of [supertest](https://www.npmjs.com/package/supertest)
|
|
9
4
|
|
|
10
|
-
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
11
7
|
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
The motivation with this module is to provide a high-level abstraction for testing
|
|
15
|
-
HTTP, while still allowing you to drop down to the [lower-level API](https://forwardemail.github.io/superagent/) provided by superagent.
|
|
16
|
-
|
|
17
|
-
## Getting Started
|
|
18
|
-
|
|
19
|
-
Install supertest as an npm module and save it to your package.json file as a development dependency:
|
|
8
|
+
## Installation
|
|
20
9
|
|
|
21
10
|
```bash
|
|
22
|
-
npm install supertest
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Once installed it can now be referenced by simply calling ```require('supertest');```
|
|
26
|
-
|
|
27
|
-
## Example
|
|
28
|
-
|
|
29
|
-
You may pass an `http.Server`, or a `Function` to `request()` - if the server is not
|
|
30
|
-
already listening for connections then it is bound to an ephemeral port for you so
|
|
31
|
-
there is no need to keep track of ports.
|
|
32
|
-
|
|
33
|
-
supertest works with any test framework, here is an example without using any
|
|
34
|
-
test framework at all:
|
|
35
|
-
|
|
36
|
-
```js
|
|
37
|
-
const request = require('supertest');
|
|
38
|
-
const express = require('express');
|
|
39
|
-
|
|
40
|
-
const app = express();
|
|
41
|
-
|
|
42
|
-
app.get('/user', function(req, res) {
|
|
43
|
-
res.status(200).json({ name: 'john' });
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
request(app)
|
|
47
|
-
.get('/user')
|
|
48
|
-
.expect('Content-Type', /json/)
|
|
49
|
-
.expect('Content-Length', '15')
|
|
50
|
-
.expect(200)
|
|
51
|
-
.end(function(err, res) {
|
|
52
|
-
if (err) throw err;
|
|
53
|
-
});
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
To enable http2 protocol, simply append an options to `request` or `request.agent`:
|
|
57
|
-
|
|
58
|
-
```js
|
|
59
|
-
const request = require('supertest');
|
|
60
|
-
const express = require('express');
|
|
61
|
-
|
|
62
|
-
const app = express();
|
|
63
|
-
|
|
64
|
-
app.get('/user', function(req, res) {
|
|
65
|
-
res.status(200).json({ name: 'john' });
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
request(app, { http2: true })
|
|
69
|
-
.get('/user')
|
|
70
|
-
.expect('Content-Type', /json/)
|
|
71
|
-
.expect('Content-Length', '15')
|
|
72
|
-
.expect(200)
|
|
73
|
-
.end(function(err, res) {
|
|
74
|
-
if (err) throw err;
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
request.agent(app, { http2: true })
|
|
78
|
-
.get('/user')
|
|
79
|
-
.expect('Content-Type', /json/)
|
|
80
|
-
.expect('Content-Length', '15')
|
|
81
|
-
.expect(200)
|
|
82
|
-
.end(function(err, res) {
|
|
83
|
-
if (err) throw err;
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Here's an example with mocha, note how you can pass `done` straight to any of the `.expect()` calls:
|
|
88
|
-
|
|
89
|
-
```js
|
|
90
|
-
describe('GET /user', function() {
|
|
91
|
-
it('responds with json', function(done) {
|
|
92
|
-
request(app)
|
|
93
|
-
.get('/user')
|
|
94
|
-
.set('Accept', 'application/json')
|
|
95
|
-
.expect('Content-Type', /json/)
|
|
96
|
-
.expect(200, done);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
You can use `auth` method to pass HTTP username and password in the same way as in the [superagent](https://forwardemail.github.io/superagent/#authentication):
|
|
102
|
-
|
|
103
|
-
```js
|
|
104
|
-
describe('GET /user', function() {
|
|
105
|
-
it('responds with json', function(done) {
|
|
106
|
-
request(app)
|
|
107
|
-
.get('/user')
|
|
108
|
-
.auth('username', 'password')
|
|
109
|
-
.set('Accept', 'application/json')
|
|
110
|
-
.expect('Content-Type', /json/)
|
|
111
|
-
.expect(200, done);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
One thing to note with the above statement is that superagent now sends any HTTP
|
|
117
|
-
error (anything other than a 2XX response code) to the callback as the first argument if
|
|
118
|
-
you do not add a status code expect (i.e. `.expect(302)`).
|
|
119
|
-
|
|
120
|
-
If you are using the `.end()` method `.expect()` assertions that fail will
|
|
121
|
-
not throw - they will return the assertion as an error to the `.end()` callback. In
|
|
122
|
-
order to fail the test case, you will need to rethrow or pass `err` to `done()`, as follows:
|
|
123
|
-
|
|
124
|
-
```js
|
|
125
|
-
describe('POST /users', function() {
|
|
126
|
-
it('responds with json', function(done) {
|
|
127
|
-
request(app)
|
|
128
|
-
.post('/users')
|
|
129
|
-
.send({name: 'john'})
|
|
130
|
-
.set('Accept', 'application/json')
|
|
131
|
-
.expect('Content-Type', /json/)
|
|
132
|
-
.expect(200)
|
|
133
|
-
.end(function(err, res) {
|
|
134
|
-
if (err) return done(err);
|
|
135
|
-
return done();
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
You can also use promises:
|
|
142
|
-
|
|
143
|
-
```js
|
|
144
|
-
describe('GET /users', function() {
|
|
145
|
-
it('responds with json', function() {
|
|
146
|
-
return request(app)
|
|
147
|
-
.get('/users')
|
|
148
|
-
.set('Accept', 'application/json')
|
|
149
|
-
.expect('Content-Type', /json/)
|
|
150
|
-
.expect(200)
|
|
151
|
-
.then(response => {
|
|
152
|
-
expect(response.body.email).toEqual('foo@bar.com');
|
|
153
|
-
})
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
Or async/await syntax:
|
|
159
|
-
|
|
160
|
-
```js
|
|
161
|
-
describe('GET /users', function() {
|
|
162
|
-
it('responds with json', async function() {
|
|
163
|
-
const response = await request(app)
|
|
164
|
-
.get('/users')
|
|
165
|
-
.set('Accept', 'application/json')
|
|
166
|
-
expect(response.headers["content-type"]).toMatch(/json/);
|
|
167
|
-
expect(response.status).toEqual(200);
|
|
168
|
-
expect(response.body.email).toEqual('foo@bar.com');
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
Expectations are run in the order of definition. This characteristic can be used
|
|
174
|
-
to modify the response body or headers before executing an assertion.
|
|
175
|
-
|
|
176
|
-
```js
|
|
177
|
-
describe('POST /user', function() {
|
|
178
|
-
it('user.name should be an case-insensitive match for "john"', function(done) {
|
|
179
|
-
request(app)
|
|
180
|
-
.post('/user')
|
|
181
|
-
.send('name=john') // x-www-form-urlencoded upload
|
|
182
|
-
.set('Accept', 'application/json')
|
|
183
|
-
.expect(function(res) {
|
|
184
|
-
res.body.id = 'some fixed id';
|
|
185
|
-
res.body.name = res.body.name.toLowerCase();
|
|
186
|
-
})
|
|
187
|
-
.expect(200, {
|
|
188
|
-
id: 'some fixed id',
|
|
189
|
-
name: 'john'
|
|
190
|
-
}, done);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
Anything you can do with superagent, you can do with supertest - for example multipart file uploads!
|
|
196
|
-
|
|
197
|
-
```js
|
|
198
|
-
request(app)
|
|
199
|
-
.post('/')
|
|
200
|
-
.field('name', 'my awesome avatar')
|
|
201
|
-
.field('complex_object', '{"attribute": "value"}', {contentType: 'application/json'})
|
|
202
|
-
.attach('avatar', 'test/fixtures/avatar.jpg')
|
|
203
|
-
...
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
Passing the app or url each time is not necessary, if you're testing
|
|
207
|
-
the same host you may simply re-assign the request variable with the
|
|
208
|
-
initialization app or url, a new `Test` is created per `request.VERB()` call.
|
|
209
|
-
|
|
210
|
-
```js
|
|
211
|
-
request = request('http://localhost:5555');
|
|
212
|
-
|
|
213
|
-
request.get('/').expect(200, function(err){
|
|
214
|
-
console.log(err);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
request.get('/').expect('heya', function(err){
|
|
218
|
-
console.log(err);
|
|
219
|
-
});
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
Here's an example with mocha that shows how to persist a request and its cookies:
|
|
223
|
-
|
|
224
|
-
```js
|
|
225
|
-
const request = require('supertest');
|
|
226
|
-
const should = require('should');
|
|
227
|
-
const express = require('express');
|
|
228
|
-
const cookieParser = require('cookie-parser');
|
|
229
|
-
|
|
230
|
-
describe('request.agent(app)', function() {
|
|
231
|
-
const app = express();
|
|
232
|
-
app.use(cookieParser());
|
|
233
|
-
|
|
234
|
-
app.get('/', function(req, res) {
|
|
235
|
-
res.cookie('cookie', 'hey');
|
|
236
|
-
res.send();
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
app.get('/return', function(req, res) {
|
|
240
|
-
if (req.cookies.cookie) res.send(req.cookies.cookie);
|
|
241
|
-
else res.send(':(')
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
const agent = request.agent(app);
|
|
245
|
-
|
|
246
|
-
it('should save cookies', function(done) {
|
|
247
|
-
agent
|
|
248
|
-
.get('/')
|
|
249
|
-
.expect('set-cookie', 'cookie=hey; Path=/', done);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('should send cookies', function(done) {
|
|
253
|
-
agent
|
|
254
|
-
.get('/return')
|
|
255
|
-
.expect('hey', done);
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
There is another example that is introduced by the file [agency.js](https://github.com/ladjs/superagent/blob/master/test/node/agency.js)
|
|
261
|
-
|
|
262
|
-
Here is an example where 2 cookies are set on the request.
|
|
263
|
-
|
|
264
|
-
```js
|
|
265
|
-
agent(app)
|
|
266
|
-
.get('/api/content')
|
|
267
|
-
.set('Cookie', ['nameOne=valueOne;nameTwo=valueTwo'])
|
|
268
|
-
.send()
|
|
269
|
-
.expect(200)
|
|
270
|
-
.end((err, res) => {
|
|
271
|
-
if (err) {
|
|
272
|
-
return done(err);
|
|
273
|
-
}
|
|
274
|
-
expect(res.text).to.be.equal('hey');
|
|
275
|
-
return done();
|
|
276
|
-
});
|
|
11
|
+
npm install @depup/supertest
|
|
277
12
|
```
|
|
278
13
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
### .expect(status[, fn])
|
|
286
|
-
|
|
287
|
-
Assert response `status` code.
|
|
288
|
-
|
|
289
|
-
### .expect(status, body[, fn])
|
|
290
|
-
|
|
291
|
-
Assert response `status` code and `body`.
|
|
292
|
-
|
|
293
|
-
### .expect(body[, fn])
|
|
294
|
-
|
|
295
|
-
Assert response `body` text with a string, regular expression, or
|
|
296
|
-
parsed body object.
|
|
297
|
-
|
|
298
|
-
### .expect(field, value[, fn])
|
|
299
|
-
|
|
300
|
-
Assert header `field` `value` with a string or regular expression.
|
|
301
|
-
|
|
302
|
-
### .expect(function(res) {})
|
|
303
|
-
|
|
304
|
-
Pass a custom assertion function. It'll be given the response object to check. If the check fails, throw an error.
|
|
305
|
-
|
|
306
|
-
```js
|
|
307
|
-
request(app)
|
|
308
|
-
.get('/')
|
|
309
|
-
.expect(hasPreviousAndNextKeys)
|
|
310
|
-
.end(done);
|
|
311
|
-
|
|
312
|
-
function hasPreviousAndNextKeys(res) {
|
|
313
|
-
if (!('next' in res.body)) throw new Error("missing next key");
|
|
314
|
-
if (!('prev' in res.body)) throw new Error("missing prev key");
|
|
315
|
-
}
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
### .end(fn)
|
|
319
|
-
|
|
320
|
-
Perform the request and invoke `fn(err, res)`.
|
|
321
|
-
|
|
322
|
-
## Cookies
|
|
323
|
-
|
|
324
|
-
Here is an example of using the `set` and `not` cookie assertions:
|
|
325
|
-
|
|
326
|
-
```js
|
|
327
|
-
// setup super-test
|
|
328
|
-
const request = require('supertest');
|
|
329
|
-
const express = require('express');
|
|
330
|
-
const cookies = request.cookies;
|
|
331
|
-
|
|
332
|
-
// setup express test service
|
|
333
|
-
const app = express();
|
|
334
|
-
|
|
335
|
-
app.get('/users', function(req, res) {
|
|
336
|
-
res.cookie('alpha', 'one', { domain: 'domain.com', path: '/', httpOnly: true });
|
|
337
|
-
res.send(200, { name: 'tobi' });
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
// test request to service
|
|
341
|
-
request(app)
|
|
342
|
-
.get('/users')
|
|
343
|
-
.expect('Content-Type', /json/)
|
|
344
|
-
.expect('Content-Length', '15')
|
|
345
|
-
.expect(200)
|
|
346
|
-
// assert 'alpha' cookie is set with domain, path, and httpOnly options
|
|
347
|
-
.expect(cookies.set({ name: 'alpha', options: ['domain', 'path', 'httponly'] }))
|
|
348
|
-
// assert 'bravo' cookie is NOT set
|
|
349
|
-
.expect(cookies.not('set', { name: 'bravo' }))
|
|
350
|
-
.end(function(err, res) {
|
|
351
|
-
if (err) {
|
|
352
|
-
throw err;
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
It is also possible to chain assertions:
|
|
358
|
-
|
|
359
|
-
```js
|
|
360
|
-
cookies.set({/* ... */}).not('set', {/* ... */})
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
### Cookie assertions
|
|
364
|
-
|
|
365
|
-
Functions and methods are chainable.
|
|
366
|
-
|
|
367
|
-
#### cookies([secret], [asserts])
|
|
368
|
-
|
|
369
|
-
Get assertion function for [super-test](https://github.com/visionmedia/supertest) `.expect()` method.
|
|
370
|
-
|
|
371
|
-
*Arguments*
|
|
372
|
-
|
|
373
|
-
- `secret` - String or array of strings. Cookie signature secrets.
|
|
374
|
-
- `asserts(req, res)` - Function or array of functions. Failed custom assertions should throw.
|
|
375
|
-
|
|
376
|
-
#### .set(expects, [assert])
|
|
377
|
-
|
|
378
|
-
Assert that cookie and options are set.
|
|
379
|
-
|
|
380
|
-
*Arguments*
|
|
381
|
-
|
|
382
|
-
- `expects` - Object or array of objects.
|
|
383
|
-
- `name` - String name of cookie.
|
|
384
|
-
- `options` - *Optional* array of options.
|
|
385
|
-
- `assert` - *Optional* boolean "assert true" modifier. Default: `true`.
|
|
386
|
-
|
|
387
|
-
#### .reset(expects, [assert])
|
|
388
|
-
|
|
389
|
-
Assert that cookie is set and was already set (in request headers).
|
|
390
|
-
|
|
391
|
-
*Arguments*
|
|
392
|
-
|
|
393
|
-
- `expects` - Object or array of objects.
|
|
394
|
-
- `name` - String name of cookie.
|
|
395
|
-
- `assert` - *Optional* boolean "assert true" modifier. Default: `true`.
|
|
396
|
-
|
|
397
|
-
#### .new(expects, [assert])
|
|
398
|
-
|
|
399
|
-
Assert that cookie is set and was NOT already set (NOT in request headers).
|
|
400
|
-
|
|
401
|
-
*Arguments*
|
|
402
|
-
|
|
403
|
-
- `expects` - Object or array of objects.
|
|
404
|
-
- `name` - String name of cookie.
|
|
405
|
-
- `assert` - *Optional* boolean "assert true" modifier. Default: `true`.
|
|
406
|
-
|
|
407
|
-
#### .renew(expects, [assert])
|
|
408
|
-
|
|
409
|
-
Assert that cookie is set with a strictly greater `expires` or `max-age` than the given value.
|
|
410
|
-
|
|
411
|
-
*Arguments*
|
|
412
|
-
|
|
413
|
-
- `expects` - Object or array of objects.
|
|
414
|
-
- `name` - String name of cookie.
|
|
415
|
-
- `options` - Object of options. `use one of two options below`
|
|
416
|
-
- `options`.`expires` - String UTC expiration for original cookie (in request headers).
|
|
417
|
-
- `options`.`max-age` - Integer ttl in seconds for original cookie (in request headers).
|
|
418
|
-
- `assert` - *Optional* boolean "assert true" modifier. Default: `true`.
|
|
419
|
-
|
|
420
|
-
#### .contain(expects, [assert])
|
|
421
|
-
|
|
422
|
-
Assert that cookie is set with value and contains options.
|
|
423
|
-
|
|
424
|
-
Requires `cookies(secret)` initialization if cookie is signed.
|
|
425
|
-
|
|
426
|
-
*Arguments*
|
|
427
|
-
|
|
428
|
-
- `expects` - Object or array of objects.
|
|
429
|
-
- `name` - String name of cookie.
|
|
430
|
-
- `value` - *Optional* string unsigned value of cookie.
|
|
431
|
-
- `options` - *Optional* object of options.
|
|
432
|
-
- `options`.`domain` - *Optional* string domain.
|
|
433
|
-
- `options`.`path` - *Optional* string path.
|
|
434
|
-
- `options`.`expires` - *Optional* string UTC expiration.
|
|
435
|
-
- `options`.`max-age` - *Optional* integer ttl, in seconds.
|
|
436
|
-
- `options`.`secure` - *Optional* boolean secure flag.
|
|
437
|
-
- `options`.`httponly` - *Optional* boolean httpOnly flag.
|
|
438
|
-
- `assert` - *Optional* boolean "assert true" modifier. Default: `true`.
|
|
439
|
-
|
|
440
|
-
#### .not(method, expects)
|
|
441
|
-
|
|
442
|
-
Call any cookies assertion method with "assert true" modifier set to `false`.
|
|
443
|
-
|
|
444
|
-
Syntactic sugar.
|
|
445
|
-
|
|
446
|
-
*Arguments*
|
|
447
|
-
|
|
448
|
-
- `method` - String method name. Arguments of method name apply in `expects`.
|
|
449
|
-
- `expects` - Object or array of objects.
|
|
450
|
-
- `name` - String name of cookie.
|
|
451
|
-
- `value` - *Optional* string unsigned value of cookie.
|
|
452
|
-
- `options` - *Optional* object of options.
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [supertest](https://www.npmjs.com/package/supertest) @ 7.3.0 |
|
|
17
|
+
| Processed | 2026-09-27 |
|
|
18
|
+
| Smoke test | passed |
|
|
19
|
+
| Deps updated | 1 |
|
|
453
20
|
|
|
454
|
-
##
|
|
21
|
+
## Dependency Changes
|
|
455
22
|
|
|
456
|
-
|
|
23
|
+
| Dependency | From | To |
|
|
24
|
+
|------------|------|-----|
|
|
25
|
+
| superagent | ^10.3.0 | ^10.4.1 |
|
|
457
26
|
|
|
458
|
-
|
|
27
|
+
---
|
|
459
28
|
|
|
460
|
-
|
|
29
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/supertest
|
|
461
30
|
|
|
462
|
-
|
|
463
|
-
[coverage]: https://codecov.io/gh/ladjs/supertest
|
|
464
|
-
[travis-badge]: https://travis-ci.org/ladjs/supertest.svg?branch=master
|
|
465
|
-
[travis]: https://travis-ci.org/ladjs/supertest
|
|
466
|
-
[dependencies-badge]: https://david-dm.org/ladjs/supertest/status.svg
|
|
467
|
-
[dependencies]: https://david-dm.org/ladjs/supertest
|
|
468
|
-
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
|
|
469
|
-
[prs]: http://makeapullrequest.com
|
|
470
|
-
[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
|
|
471
|
-
[license]: https://github.com/ladjs/supertest/blob/master/LICENSE
|
|
31
|
+
License inherited from the original package.
|
package/changes.json
ADDED
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Module dependencies.
|
|
5
5
|
*/
|
|
6
6
|
const methods = require('methods');
|
|
7
|
+
const http = require('http');
|
|
7
8
|
let http2;
|
|
8
9
|
try {
|
|
9
10
|
http2 = require('http2'); // eslint-disable-line global-require
|
|
@@ -24,6 +25,7 @@ const cookies = require('./lib/cookies');
|
|
|
24
25
|
*/
|
|
25
26
|
module.exports = function(app, options = {}) {
|
|
26
27
|
const obj = {};
|
|
28
|
+
let target = app;
|
|
27
29
|
|
|
28
30
|
if (typeof app === 'function') {
|
|
29
31
|
if (options.http2) {
|
|
@@ -32,12 +34,15 @@ module.exports = function(app, options = {}) {
|
|
|
32
34
|
'supertest: this version of Node.js does not support http2'
|
|
33
35
|
);
|
|
34
36
|
}
|
|
37
|
+
target = http2.createServer(app);
|
|
38
|
+
} else {
|
|
39
|
+
target = http.createServer(app);
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
methods.forEach(function(method) {
|
|
39
44
|
obj[method] = function(url) {
|
|
40
|
-
var test = new Test(
|
|
45
|
+
var test = new Test(target, method, url, options.http2);
|
|
41
46
|
if (options.http2) {
|
|
42
47
|
test.http2();
|
|
43
48
|
}
|
package/lib/cookies/assertion.js
CHANGED
|
@@ -212,7 +212,10 @@ module.exports = function (secret, asserts) {
|
|
|
212
212
|
return;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
const
|
|
215
|
+
const rawKey = part.substr(0, equalsIndex).trim();
|
|
216
|
+
// Cookie names are case-sensitive, while Set-Cookie attribute names are
|
|
217
|
+
// case-insensitive.
|
|
218
|
+
const key = i === 0 ? rawKey : rawKey.toLowerCase();
|
|
216
219
|
// only assign once
|
|
217
220
|
if (typeof cookie[key] !== 'undefined') return;
|
|
218
221
|
|
package/lib/test.js
CHANGED
|
@@ -19,6 +19,10 @@ try {
|
|
|
19
19
|
|
|
20
20
|
/** @typedef {import('superagent').Response} Response */
|
|
21
21
|
|
|
22
|
+
// Tracks only servers started by SuperTest. WeakMap keeps the bookkeeping
|
|
23
|
+
// private and lets user-owned servers remain untouched.
|
|
24
|
+
const serverStates = new WeakMap();
|
|
25
|
+
|
|
22
26
|
class Test extends Request {
|
|
23
27
|
/**
|
|
24
28
|
* Initialize a new `Test` with the given `app`,
|
|
@@ -58,15 +62,53 @@ class Test extends Request {
|
|
|
58
62
|
* @api private
|
|
59
63
|
*/
|
|
60
64
|
serverAddress(app, path) {
|
|
61
|
-
|
|
65
|
+
let addr = app.address();
|
|
66
|
+
let state = serverStates.get(app);
|
|
67
|
+
|
|
68
|
+
if (!addr) {
|
|
69
|
+
if (!state) {
|
|
70
|
+
state = {
|
|
71
|
+
pending: 0,
|
|
72
|
+
starting: true,
|
|
73
|
+
closing: false,
|
|
74
|
+
startError: null
|
|
75
|
+
};
|
|
76
|
+
serverStates.set(app, state);
|
|
77
|
+
|
|
78
|
+
const onListening = function () {
|
|
79
|
+
state.starting = false;
|
|
80
|
+
app.removeListener('error', onError);
|
|
81
|
+
};
|
|
82
|
+
const onError = function (err) {
|
|
83
|
+
state.starting = false;
|
|
84
|
+
state.startError = err;
|
|
85
|
+
app.removeListener('listening', onListening);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
app.once('listening', onListening);
|
|
89
|
+
app.once('error', onError);
|
|
90
|
+
app.listen(0);
|
|
91
|
+
}
|
|
92
|
+
addr = app.address();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// A previously started SuperTest server is shared by every request created
|
|
96
|
+
// from the same request factory and closes after the final request settles.
|
|
97
|
+
if (state) {
|
|
98
|
+
this._server = app;
|
|
99
|
+
}
|
|
62
100
|
|
|
63
|
-
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
101
|
+
// A SuperTest-created IPv6 wildcard is dual-stack by default. Prefer IPv4
|
|
102
|
+
// for that wildcard so SuperAgent does not construct an IPv6 loopback URL;
|
|
103
|
+
// explicit IPv6-only servers retain their own address family below.
|
|
104
|
+
let host = addr.address;
|
|
105
|
+
if (host === '::') host = '127.0.0.1';
|
|
106
|
+
else if (host === '0.0.0.0') host = '127.0.0.1';
|
|
107
|
+
if (host.includes(':')) host = `[${host}]`;
|
|
108
|
+
|
|
109
|
+
const port = addr.port;
|
|
68
110
|
const protocol = app instanceof Server ? 'https' : 'http';
|
|
69
|
-
return protocol + '://
|
|
111
|
+
return protocol + '://' + host + ':' + port + path;
|
|
70
112
|
}
|
|
71
113
|
|
|
72
114
|
/**
|
|
@@ -132,29 +174,66 @@ class Test extends Request {
|
|
|
132
174
|
*/
|
|
133
175
|
end(fn) {
|
|
134
176
|
const server = this._server;
|
|
177
|
+
const state = server && serverStates.get(server);
|
|
178
|
+
let complete = false;
|
|
179
|
+
let dispatch;
|
|
180
|
+
let onListening;
|
|
181
|
+
let onStartError;
|
|
182
|
+
let onClose;
|
|
183
|
+
|
|
184
|
+
const removeStartListeners = () => {
|
|
185
|
+
if (!server) return;
|
|
186
|
+
if (onListening) server.removeListener('listening', onListening);
|
|
187
|
+
if (onStartError) server.removeListener('error', onStartError);
|
|
188
|
+
if (onClose) server.removeListener('close', onClose);
|
|
189
|
+
};
|
|
135
190
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
localAssert();
|
|
153
|
-
});
|
|
191
|
+
const finish = (err, res) => {
|
|
192
|
+
if (complete) return;
|
|
193
|
+
complete = true;
|
|
194
|
+
removeStartListeners();
|
|
195
|
+
|
|
196
|
+
const localAssert = () => this.assert(err, res, fn);
|
|
197
|
+
if (state) {
|
|
198
|
+
state.pending -= 1;
|
|
199
|
+
if (state.pending === 0 && !state.closing && server._handle) {
|
|
200
|
+
state.closing = true;
|
|
201
|
+
return server.close(function () {
|
|
202
|
+
serverStates.delete(server);
|
|
203
|
+
localAssert();
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (state.pending === 0 && !server._handle) serverStates.delete(server);
|
|
154
207
|
}
|
|
155
208
|
|
|
156
209
|
localAssert();
|
|
157
|
-
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
dispatch = () => {
|
|
213
|
+
removeStartListeners();
|
|
214
|
+
try {
|
|
215
|
+
super.end(finish);
|
|
216
|
+
} catch (err) {
|
|
217
|
+
finish(err);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
if (state) state.pending += 1;
|
|
222
|
+
|
|
223
|
+
if (state && state.startError) {
|
|
224
|
+
finish(state.startError);
|
|
225
|
+
} else if (state && state.starting) {
|
|
226
|
+
onListening = dispatch;
|
|
227
|
+
onStartError = finish;
|
|
228
|
+
onClose = function () {
|
|
229
|
+
finish(new Error('SuperTest server closed before listening'));
|
|
230
|
+
};
|
|
231
|
+
server.once('listening', onListening);
|
|
232
|
+
server.once('error', onStartError);
|
|
233
|
+
server.once('close', onClose);
|
|
234
|
+
} else {
|
|
235
|
+
dispatch();
|
|
236
|
+
}
|
|
158
237
|
|
|
159
238
|
return this;
|
|
160
239
|
}
|
|
@@ -217,18 +296,6 @@ class Test extends Request {
|
|
|
217
296
|
return this;
|
|
218
297
|
}
|
|
219
298
|
|
|
220
|
-
/*
|
|
221
|
-
* Adds a set Authorization Bearer
|
|
222
|
-
*
|
|
223
|
-
* @param {Bearer} Bearer Token
|
|
224
|
-
* Shortcut for .set('Authorization', `Bearer ${token}`)
|
|
225
|
-
*/
|
|
226
|
-
|
|
227
|
-
bearer(token) {
|
|
228
|
-
this.set('Authorization', `Bearer ${token}`);
|
|
229
|
-
return this;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
299
|
/**
|
|
233
300
|
* Perform assertions on a response body and return an Error upon failure.
|
|
234
301
|
*
|
|
@@ -275,7 +342,7 @@ class Test extends Request {
|
|
|
275
342
|
*/// eslint-disable-next-line class-methods-use-this
|
|
276
343
|
_assertHeader(header, res) {
|
|
277
344
|
const field = header.name;
|
|
278
|
-
const actual = res.
|
|
345
|
+
const actual = res.headers[field.toLowerCase()];
|
|
279
346
|
const fieldExpected = header.value;
|
|
280
347
|
|
|
281
348
|
if (typeof actual === 'undefined') return new Error('expected "' + field + '" header field');
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@depup/supertest",
|
|
3
|
-
"description": "SuperAgent driven library for testing HTTP servers",
|
|
4
|
-
"version": "7.
|
|
3
|
+
"description": "SuperAgent driven library for testing HTTP servers (with updated dependencies)",
|
|
4
|
+
"version": "7.3.0-depup.0",
|
|
5
5
|
"author": "TJ Holowaychuk",
|
|
6
6
|
"contributors": [],
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"methods": "^1.1.2",
|
|
9
|
-
"superagent": "^10.
|
|
9
|
+
"superagent": "^10.4.1",
|
|
10
10
|
"cookie-signature": "^1.2.2"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
@@ -30,9 +30,17 @@
|
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"index.js",
|
|
33
|
-
"lib"
|
|
33
|
+
"lib",
|
|
34
|
+
"changes.json",
|
|
35
|
+
"README.md"
|
|
34
36
|
],
|
|
35
37
|
"keywords": [
|
|
38
|
+
"supertest",
|
|
39
|
+
"depup",
|
|
40
|
+
"updated-dependencies",
|
|
41
|
+
"security",
|
|
42
|
+
"latest",
|
|
43
|
+
"patched",
|
|
36
44
|
"bdd",
|
|
37
45
|
"http",
|
|
38
46
|
"request",
|
|
@@ -53,5 +61,18 @@
|
|
|
53
61
|
"lint:fix": "eslint --fix lib/**/*.js test/**/*.js index.js",
|
|
54
62
|
"pretest": "npm run lint --if-present",
|
|
55
63
|
"test": "nyc --reporter=html --reporter=text mocha --exit --require should --reporter spec --check-leaks"
|
|
64
|
+
},
|
|
65
|
+
"depup": {
|
|
66
|
+
"changes": {
|
|
67
|
+
"superagent": {
|
|
68
|
+
"from": "^10.3.0",
|
|
69
|
+
"to": "^10.4.1"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"depsUpdated": 1,
|
|
73
|
+
"originalPackage": "supertest",
|
|
74
|
+
"originalVersion": "7.3.0",
|
|
75
|
+
"processedAt": "2026-09-27T01:04:28.860Z",
|
|
76
|
+
"smokeTest": "passed"
|
|
56
77
|
}
|
|
57
78
|
}
|