forked from mjackson/mach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgzip-spec.js
61 lines (50 loc) · 1.6 KB
/
gzip-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require('./helper');
var fs = require('fs');
var gzip = mach.gzip;
describe('gzip', function () {
var testFile = specFile('test.txt');
var content = fs.readFileSync(testFile);
var gzipContent = fs.readFileSync(testFile + '.gz');
describe('when the client accepts gzip encoding', function () {
var app = gzip(function (request) {
return {
headers: { 'Content-Type': 'text/plain' },
content: content
};
});
beforeEach(function () {
return callApp(app, {
headers: { 'Accept-Encoding': 'gzip' }
}, true);
});
it('sets the Content-Encoding header to "gzip"', function () {
expect(lastResponse.headers['Content-Encoding']).toEqual('gzip');
});
it('sets the Vary header to "Accept-Encoding"', function () {
expect(lastResponse.headers['Vary']).toEqual('Accept-Encoding');
});
it('gzip-encodes the response content', function () {
compareBuffers(lastResponse.buffer, gzipContent);
});
});
describe('when the client does not accept gzip encoding', function () {
it('does not encode the content');
});
describe('when the response is a text/event-stream', function () {
var app = gzip(function (request) {
return {
headers: { 'Content-Type': 'text/event-stream' },
content: content
};
});
beforeEach(function () {
return callApp(app, '/', true);
});
it('does not encode the content', function () {
compareBuffers(lastResponse.buffer, content);
});
});
});
function compareBuffers(one, two) {
expect(one).toEqual(two, 'buffers are not equal');
}