utils.js
This file
Path
test/utils.js
103 lines · 3.0 KiB · JavaScript
Last changed by
tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05
History of this fileTake it
The walk stopped after 200 commits: lines older than c754c8a point at it.
tests: use strict modeDouglas Christopher Wilsonbefore adoptiona659137
line 1why, one step back1'use strict'build: support Node.js 11.xDouglas Christopher Wilsonbefore adoptionc754c8a
lines 2–8why, one step back23var assert = require('assert');4var Buffer = require('safe-buffer').Buffer5var utils = require('../lib/utils');67describe('utils.etag(body, encoding)', function(){8 it('should support strings', function(){tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
lines 9–10why, one step back9 assert.strictEqual(utils.etag('express!'),10 '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')build: support Node.js 11.xDouglas Christopher Wilsonbefore adoptionc754c8a
lines 11–13why, one step back11 })1213 it('should support utf8 strings', function(){tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
lines 14–15why, one step back14 assert.strictEqual(utils.etag('express❤', 'utf8'),15 '"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')build: support Node.js 11.xDouglas Christopher Wilsonbefore adoptionc754c8a
lines 16–18why, one step back16 })1718 it('should support buffer', function(){tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
lines 19–20why, one step back19 assert.strictEqual(utils.etag(Buffer.from('express!')),20 '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')build: support Node.js 11.xDouglas Christopher Wilsonbefore adoptionc754c8a
lines 21–23why, one step back21 })2223 it('should support empty string', function(){tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
lines 24–25why, one step back24 assert.strictEqual(utils.etag(''),25 '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')build: support Node.js 11.xDouglas Christopher Wilsonbefore adoptionc754c8a
lines 26–52why, one step back26 })27})2829describe('utils.setCharset(type, charset)', function () {30 it('should do anything without type', function () {31 assert.strictEqual(utils.setCharset(), undefined);32 });3334 it('should return type if not given charset', function () {35 assert.strictEqual(utils.setCharset('text/html'), 'text/html');36 });3738 it('should keep charset if not given charset', function () {39 assert.strictEqual(utils.setCharset('text/html; charset=utf-8'), 'text/html; charset=utf-8');40 });4142 it('should set charset', function () {43 assert.strictEqual(utils.setCharset('text/html', 'utf-8'), 'text/html; charset=utf-8');44 });4546 it('should override charset', function () {47 assert.strictEqual(utils.setCharset('text/html; charset=iso-8859-1', 'utf-8'), 'text/html; charset=utf-8');48 });49});5051describe('utils.wetag(body, encoding)', function(){52 it('should support strings', function(){tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
lines 53–54why, one step back53 assert.strictEqual(utils.wetag('express!'),54 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')build: support Node.js 11.xDouglas Christopher Wilsonbefore adoptionc754c8a
lines 55–57why, one step back55 })5657 it('should support utf8 strings', function(){tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
lines 58–59why, one step back58 assert.strictEqual(utils.wetag('express❤', 'utf8'),59 'W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')build: support Node.js 11.xDouglas Christopher Wilsonbefore adoptionc754c8a
lines 60–62why, one step back60 })6162 it('should support buffer', function(){tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
lines 63–64why, one step back63 assert.strictEqual(utils.wetag(Buffer.from('express!')),64 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')build: support Node.js 11.xDouglas Christopher Wilsonbefore adoptionc754c8a
lines 65–67why, one step back65 })6667 it('should support empty string', function(){tests: remove global dependency on shouldDouglas Christopher Wilsonbefore adoptionbd4fdfe
lines 68–69why, one step back68 assert.strictEqual(utils.wetag(''),69 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')build: support Node.js 11.xDouglas Christopher Wilsonbefore adoptionc754c8a
lines 70–92why, one step back70 })71})7273describe('utils.isAbsolute()', function(){74 it('should support windows', function(){75 assert(utils.isAbsolute('c:\\'));76 assert(utils.isAbsolute('c:/'));77 assert(!utils.isAbsolute(':\\'));78 })7980 it('should support windows unc', function(){81 assert(utils.isAbsolute('\\\\foo\\bar'))82 })8384 it('should support unices', function(){85 assert(utils.isAbsolute('/foo/bar'));86 assert(!utils.isAbsolute('foo/bar'));87 })88})8990describe('utils.flatten(arr)', function(){91 it('should flatten an array', function(){92 var arr = ['one', ['two', ['three', 'four'], 'five']];tests: remove usage of shouldDouglas Christopher Wilsonbefore adoptionbc5ca05
lines 93–101why, one step back93 var flat = utils.flatten(arr)9495 assert.strictEqual(flat.length, 5)96 assert.strictEqual(flat[0], 'one')97 assert.strictEqual(flat[1], 'two')98 assert.strictEqual(flat[2], 'three')99 assert.strictEqual(flat[3], 'four')100 assert.strictEqual(flat[4], 'five')101 assert.ok(flat.every(function (v) { return typeof v === 'string' }))build: support Node.js 11.xDouglas Christopher Wilsonbefore adoptionc754c8a
lines 102–103why, one step back102 })103})