utils.js
This file
Path
test/utils.js
83 lines · 2.5 KiB · JavaScript
Last changed by
chore: enforce explicit Buffer import and add lint rule (#6525)Shivam Sharmabefore adoption98c85eb
History of this fileTake it
The walk stopped after 200 commits: lines older than 8a387d3 point at it.
Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
line 1why, one step back1'use strict'deps: array-flatten@2.0.0Douglas Christopher Wilsonbefore adoption8a387d3
line 2why, one step back2fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 3why, one step back3var assert = require('node:assert');chore: enforce explicit Buffer import and add lint rule (#6525)Shivam Sharmabefore adoption98c85eb
line 4why, one step back4const { Buffer } = require('node:buffer');deps: array-flatten@2.0.0Douglas Christopher Wilsonbefore adoption8a387d3
lines 5–8why, one step back5var utils = require('../lib/utils');67describe('utils.etag(body, encoding)', function(){8 it('should support strings', function(){Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
lines 9–10why, one step back9 assert.strictEqual(utils.etag('express!'),10 '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')deps: array-flatten@2.0.0Douglas Christopher Wilsonbefore adoption8a387d3
lines 11–13why, one step back11 })1213 it('should support utf8 strings', function(){Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
lines 14–15why, one step back14 assert.strictEqual(utils.etag('express❤', 'utf8'),15 '"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')deps: array-flatten@2.0.0Douglas Christopher Wilsonbefore adoption8a387d3
lines 16–18why, one step back16 })1718 it('should support buffer', function(){Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
lines 19–20why, one step back19 assert.strictEqual(utils.etag(Buffer.from('express!')),20 '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')deps: array-flatten@2.0.0Douglas Christopher Wilsonbefore adoption8a387d3
lines 21–23why, one step back21 })2223 it('should support empty string', function(){Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
lines 24–25why, one step back24 assert.strictEqual(utils.etag(''),25 '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')deps: array-flatten@2.0.0Douglas Christopher Wilsonbefore adoption8a387d3
lines 26–28why, one step back26 })27})28increased code coverage of utils.js file (#6386)Ashish Sharmabefore adoption5da5a11
lines 29–40why, one step back29describe('utils.normalizeType acceptParams method', () => {30 it('should handle a type with a malformed parameter and break the loop in acceptParams', () => {31 const result = utils.normalizeType('text/plain;invalid');32 assert.deepEqual(result,{33 value: 'text/plain',34 quality: 1,35 params: {} // No parameters are added since "invalid" has no "="36 });37 });38});3940deps: array-flatten@2.0.0Douglas Christopher Wilsonbefore adoption8a387d3
lines 41–64why, one step back41describe('utils.setCharset(type, charset)', function () {42 it('should do anything without type', function () {43 assert.strictEqual(utils.setCharset(), undefined);44 });4546 it('should return type if not given charset', function () {47 assert.strictEqual(utils.setCharset('text/html'), 'text/html');48 });4950 it('should keep charset if not given charset', function () {51 assert.strictEqual(utils.setCharset('text/html; charset=utf-8'), 'text/html; charset=utf-8');52 });5354 it('should set charset', function () {55 assert.strictEqual(utils.setCharset('text/html', 'utf-8'), 'text/html; charset=utf-8');56 });5758 it('should override charset', function () {59 assert.strictEqual(utils.setCharset('text/html; charset=iso-8859-1', 'utf-8'), 'text/html; charset=utf-8');60 });61});6263describe('utils.wetag(body, encoding)', function(){64 it('should support strings', function(){Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
lines 65–66why, one step back65 assert.strictEqual(utils.wetag('express!'),66 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')deps: array-flatten@2.0.0Douglas Christopher Wilsonbefore adoption8a387d3
lines 67–69why, one step back67 })6869 it('should support utf8 strings', function(){Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
lines 70–71why, one step back70 assert.strictEqual(utils.wetag('express❤', 'utf8'),71 'W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')deps: array-flatten@2.0.0Douglas Christopher Wilsonbefore adoption8a387d3
lines 72–74why, one step back72 })7374 it('should support buffer', function(){Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
lines 75–76why, one step back75 assert.strictEqual(utils.wetag(Buffer.from('express!')),76 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')deps: array-flatten@2.0.0Douglas Christopher Wilsonbefore adoption8a387d3
lines 77–79why, one step back77 })7879 it('should support empty string', function(){Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
lines 80–81why, one step back80 assert.strictEqual(utils.wetag(''),81 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')deps: array-flatten@2.0.0Douglas Christopher Wilsonbefore adoption8a387d3
lines 82–83why, one step back82 })83})