4 const assert
= require('assert');
5 const common
= require('../../lib/common');
7 describe('common', function () {
9 describe('pick', function () {
10 it('picks', function () {
16 const result
= common
.pick(srcObj
, ['a', 'c', 'd']);
17 assert
.deepStrictEqual(result
, {
24 describe('logTruncate', function () {
25 it('returns short string', function () {
26 const str
= 'this is a short string';
27 const result
= common
.logTruncate(str
, 100);
28 assert
.strictEqual(result
, str
);
30 it('truncates long string', function () {
31 const str
= 'this is not really a very long string but it is long enough for this test';
32 const result
= common
.logTruncate(str
, 10);
33 assert(result
.length
< str
.length
);
37 describe('gotResponseLogData', function () {
38 it('covers', function () {
43 'Content-Type': 'text/plain',
53 body: 'Old Mother West Wind had stopped to talk with the Slender Fir Tree. "I\'ve just come across the Green Meadows," said Old Mother West Wind, “and there I saw the Best Thing in the World.”',
60 'Content-Type': 'text/plain',
62 body: 'Old Mother West Wind had stopped to talk with the Slender Fir Tree. "I\'ve just come across the Green... (184 bytes)',
64 const result
= common
.gotResponseLogData(response
);
65 assert
.deepStrictEqual(result
, expected
);
67 it('covers no body', function () {
72 'Content-Type': 'text/plain',
85 'Content-Type': 'text/plain',
90 const result
= common
.gotResponseLogData(response
);
91 assert
.deepStrictEqual(result
, expected
);
93 it('covers json', function () {
98 'Content-Type': 'application/json',
108 redirectUrls: ['https://redirect.example.com/'],
114 'Content-Type': 'application/json',
120 redirectUrls: ['https://redirect.example.com/'],
122 const result
= common
.gotResponseLogData(response
);
123 assert
.deepStrictEqual(result
, expected
);
125 it('covers buffer', function () {
130 'Content-Type': 'text/plain',
137 body: Buffer
.from('ᘛ⁐̤ᕐᐷ'),
143 'Content-Type': 'text/plain',
146 body: '<Buffer 14 bytes>',
148 const result
= common
.gotResponseLogData(response
);
149 assert
.deepStrictEqual(result
, expected
);
151 }); // gotResponseLogData
153 describe('setSymmetricDifference', function () {
154 it('covers difference', function () {
155 const setA
= new Set([1, 2, 3]);
156 const setB
= new Set([2, 3, 4]);
157 const expected
= new Set([1, 4]);
158 const result
= common
.setSymmetricDifference(setA
, setB
);
160 assert
.deepStrictEqual(result
, expected
);
162 it('covers no difference', function () {
163 const setA
= new Set([1, 2, 3, 4]);
164 const setB
= new Set([1, 2, 3, 4]);
165 const expected
= new Set();
166 const result
= common
.setSymmetricDifference(setA
, setB
);
167 assert(!result
.size
);
168 assert
.deepStrictEqual(result
, expected
);
170 }); // setSymmetricDifference
172 describe('properURLComponentName', function () {
173 it('maps proper names', function () {
175 ['hash', 'fragment'],
176 ['protocol', 'scheme'],
178 ].forEach(([name
, expected
]) => {
179 const result
= common
.properURLComponentName(name
);
180 assert
.strictEqual(result
, expected
);
183 }); // properURLComponentName