Skip to content
Myr

utils.js

This file

Path

test/support/utils.js

86 lines · 2.0 KiB · JavaScript

Last changed by

Merge branch 'master' into 5.0ctcpipbefore adoptionc96c690

History of this file

Take it

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

lines 1–5why, one step back
1
2/**3 * Module dependencies.4 * @private5 */

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

line 6why, one step back
6

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

line 7why, one step back
7var assert = require('assert');

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

line 8why, one step back
8var Buffer = require('safe-buffer').Buffer

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

lines 9–13why, one step back
9
10/**11 * Module exports.12 * @public13 */

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

lines 14–15why, one step back
14
15exports.shouldHaveBody = shouldHaveBody

Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae

line 16why, one step back
16exports.shouldHaveHeader = shouldHaveHeader

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

line 17why, one step back
17exports.shouldNotHaveBody = shouldNotHaveBody

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

line 18why, one step back
18exports.shouldNotHaveHeader = shouldNotHaveHeader;

Merge branch 'master' into 5.0ctcpipbefore adoptionc96c690

line 19why, one step back
19exports.shouldSkipQuery = shouldSkipQuery

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

lines 20–34why, one step back
20
21/**22 * Assert that a supertest response has a specific body.23 *24 * @param {Buffer} buf25 * @returns {function}26 */2728function shouldHaveBody (buf) {29 return function (res) {30 var body = !Buffer.isBuffer(res.body)31 ? Buffer.from(res.text)32 : res.body33 assert.ok(body, 'response has body')34 assert.strictEqual(body.toString('hex'), buf.toString('hex'))

Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae

lines 35–47why, one step back
35 }
36}3738/**39 * Assert that a supertest response does have a header.40 *41 * @param {string} header Header name to check42 * @returns {function}43 */4445function shouldHaveHeader (header) {46 return function (res) {47 assert.ok((header.toLowerCase() in res.headers), 'should have header ' + header)

Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99

lines 48–61why, one step back
48 }
49}5051/**52 * Assert that a supertest response does not have a body.53 *54 * @returns {function}55 */5657function shouldNotHaveBody () {58 return function (res) {59 assert.ok(res.text === '' || res.text === undefined)60 }61}

Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6

lines 62–73why, one step back
62
63/**64 * Assert that a supertest response does not have a header.65 *66 * @param {string} header Header name to check67 * @returns {function}68 */69function shouldNotHaveHeader(header) {70 return function (res) {71 assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);72 };73}

Merge branch 'master' into 5.0ctcpipbefore adoptionc96c690

lines 74–86why, one step back
74
75function getMajorVersion(versionString) {76 return versionString.split('.')[0];77}7879function shouldSkipQuery(versionString) {80 // Skipping HTTP QUERY tests on Node 21, it is reported in http.METHODS on 21.7.2 but not supported81 // update this implementation to run on supported versions of 21 once they exist82 // upstream tracking https://github.com/nodejs/node/issues/5156283 // express tracking issue: https://github.com/expressjs/express/issues/561584 return Number(getMajorVersion(versionString)) === 2185}86