utils.js
This file
Path
test/support/utils.js
85 lines · 2.0 KiB · JavaScript
Last changed by
fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
History of this fileTake it
Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
lines 1–5why, one step back12/**3 * Module dependencies.4 * @private5 */Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
line 6why, one step back6fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 7why, one step back7var assert = require('node:assert');Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
lines 8–12why, one step back89/**10 * Module exports.11 * @public12 */Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
lines 13–14why, one step back1314exports.shouldHaveBody = shouldHaveBodyMerge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
line 15why, one step back15exports.shouldHaveHeader = shouldHaveHeaderMerge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
line 16why, one step back16exports.shouldNotHaveBody = shouldNotHaveBodyMerge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
line 17why, one step back17exports.shouldNotHaveHeader = shouldNotHaveHeader;Merge branch 'master' into 5.0ctcpipbefore adoptionc96c690
line 18why, one step back18exports.shouldSkipQuery = shouldSkipQueryMerge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
lines 19–33why, one step back1920/**21 * Assert that a supertest response has a specific body.22 *23 * @param {Buffer} buf24 * @returns {function}25 */2627function shouldHaveBody (buf) {28 return function (res) {29 var body = !Buffer.isBuffer(res.body)30 ? Buffer.from(res.text)31 : res.body32 assert.ok(body, 'response has body')33 assert.strictEqual(body.toString('hex'), buf.toString('hex'))Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
lines 34–46why, one step back34 }35}3637/**38 * Assert that a supertest response does have a header.39 *40 * @param {string} header Header name to check41 * @returns {function}42 */4344function shouldHaveHeader (header) {45 return function (res) {46 assert.ok((header.toLowerCase() in res.headers), 'should have header ' + header)Merge tag '4.17.1'Douglas Christopher Wilsonbefore adoption121fe99
lines 47–60why, one step back47 }48}4950/**51 * Assert that a supertest response does not have a body.52 *53 * @returns {function}54 */5556function shouldNotHaveBody () {57 return function (res) {58 assert.ok(res.text === '' || res.text === undefined)59 }60}Merge tag '4.14.0'Douglas Christopher Wilsonbefore adoption1dbfee6
lines 61–72why, one step back6162/**63 * Assert that a supertest response does not have a header.64 *65 * @param {string} header Header name to check66 * @returns {function}67 */68function shouldNotHaveHeader(header) {69 return function (res) {70 assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);71 };72}Merge branch 'master' into 5.0ctcpipbefore adoptionc96c690
lines 73–85why, one step back7374function getMajorVersion(versionString) {75 return versionString.split('.')[0];76}7778function shouldSkipQuery(versionString) {79 // Skipping HTTP QUERY tests on Node 21, it is reported in http.METHODS on 21.7.2 but not supported80 // update this implementation to run on supported versions of 21 once they exist81 // upstream tracking https://github.com/nodejs/node/issues/5156282 // express tracking issue: https://github.com/expressjs/express/issues/561583 return Number(getMajorVersion(versionString)) === 2184}85