Skip to content
Myr

utils.js

This file

Path

test/support/utils.js

86 lines · 2.0 KiB · JavaScript

Last changed by

landed by oscabriela419aa7

History of this file

Take it

The walk stopped after 200 commits: lines older than 2027b87 point at it.

fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87

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

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

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

chore: enforce explicit Buffer import and add lint rule (#6525)Shivam Sharmabefore adoption98c85eb

line 8why, one step back
8const { Buffer } = require('node:buffer');

fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87

lines 9–79why, one step back
9
10/**11 * Module exports.12 * @public13 */1415exports.shouldHaveBody = shouldHaveBody16exports.shouldHaveHeader = shouldHaveHeader17exports.shouldNotHaveBody = shouldNotHaveBody18exports.shouldNotHaveHeader = shouldNotHaveHeader;19exports.shouldSkipQuery = shouldSkipQuery2021/**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'))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)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}6263/**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}7475function getMajorVersion(versionString) {76 return versionString.split('.')[0];77}7879function shouldSkipQuery(versionString) {

chore: wider range for query test skip (#6512)Jon Churchbefore adoption9f4dbe3

lines 80–81why, one step back
80 // Skipping HTTP QUERY tests below Node 22, QUERY wasn't fully supported by Node until 22
81 // we could update this implementation to run on supported versions of 21 once they exist

fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87

lines 82–83why, one step back
82 // upstream tracking https://github.com/nodejs/node/issues/51562
83 // express tracking issue: https://github.com/expressjs/express/issues/5615

chore: wider range for query test skip (#6512)Jon Churchbefore adoption9f4dbe3

line 84why, one step back
84 return Number(getMajorVersion(versionString)) < 22

fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87

lines 85–86why, one step back
85}
86