ff250a4c43098e0be305ab523d2d396eb6defc8b
4 const assert
= require('assert');
5 const common
= require('../../lib/common');
7 describe('common', function () {
8 describe('fileScope', function () {
9 it('names a file path', function () {
10 const filename
= 'lib/foo/bar.js';
11 const result
= common
.fileScope(filename
)('baz');
12 assert(result
.endsWith(':bar:baz'));
14 it('names an index path', function () {
15 const filename
= 'lib/foo/index.js';
16 const result
= common
.fileScope(filename
)('baz');
17 assert(result
.endsWith(':foo:baz'));
21 describe('pick', function () {
22 it('picks', function () {
28 const result
= common
.pick(srcObj
, ['a', 'c', 'd']);
29 assert
.deepStrictEqual(result
, {
36 describe('logTruncate', function () {
37 it('returns short string', function () {
38 const str
= 'this is a short string';
39 const result
= common
.logTruncate(str
, 100);
40 assert
.strictEqual(result
, str
);
42 it('truncates long string', function () {
43 const str
= 'this is not really a very long string but it is long enough for this test';
44 const result
= common
.logTruncate(str
, 10);
45 assert(result
.length
< str
.length
);
49 describe('gotResponseLogData', function () {
50 it('covers', function () {
55 'Content-Type': 'text/plain',
65 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.”',
72 'Content-Type': 'text/plain',
74 body: 'Old Mother West Wind had stopped to talk with the Slender Fir Tree. "I\'ve just come across the Green... (184 bytes)',
76 const result
= common
.gotResponseLogData(response
);
77 assert
.deepStrictEqual(result
, expected
);
79 it('covers no body', function () {
84 'Content-Type': 'text/plain',
97 'Content-Type': 'text/plain',
102 const result
= common
.gotResponseLogData(response
);
103 assert
.deepStrictEqual(result
, expected
);
105 it('covers json', function () {
110 'Content-Type': 'application/json',
120 redirectUrls: ['https://redirect.example.com/'],
126 'Content-Type': 'application/json',
132 redirectUrls: ['https://redirect.example.com/'],
134 const result
= common
.gotResponseLogData(response
);
135 assert
.deepStrictEqual(result
, expected
);
137 it('covers buffer', function () {
142 'Content-Type': 'text/plain',
149 body: Buffer
.from('ᘛ⁐̤ᕐᐷ'),
155 'Content-Type': 'text/plain',
158 body: '<Buffer 14 bytes>',
160 const result
= common
.gotResponseLogData(response
);
161 assert
.deepStrictEqual(result
, expected
);
163 }); // gotResponseLogData
165 describe('setSymmetricDifference', function () {
166 it('covers difference', function () {
167 const setA
= new Set([1, 2, 3]);
168 const setB
= new Set([2, 3, 4]);
169 const expected
= new Set([1, 4]);
170 const result
= common
.setSymmetricDifference(setA
, setB
);
172 assert
.deepStrictEqual(result
, expected
);
174 it('covers no difference', function () {
175 const setA
= new Set([1, 2, 3, 4]);
176 const setB
= new Set([1, 2, 3, 4]);
177 const expected
= new Set();
178 const result
= common
.setSymmetricDifference(setA
, setB
);
179 assert(!result
.size
);
180 assert
.deepStrictEqual(result
, expected
);
182 }); // setSymmetricDifference
184 describe('properURLComponentName', function () {
185 it('maps proper names', function () {
187 ['hash', 'fragment'],
188 ['protocol', 'scheme'],
190 ].forEach(([name
, expected
]) => {
191 const result
= common
.properURLComponentName(name
);
192 assert
.strictEqual(result
, expected
);
195 }); // properURLComponentName