Skip to content

Commit

Permalink
chore(sirv): add tests for "br" encoding;
Browse files Browse the repository at this point in the history
- Related: #65
  • Loading branch information
lukeed committed Jun 17, 2020
1 parent fa4f7db commit 7205446
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/sirv.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,20 +639,22 @@ brotli('should require "Accept-Encoding" match to do anything', async () => {
// the `matches` helper assumes wrong mime type
let res = await server.send('GET', '/data.js', { headers });
assert.is(res.headers['content-type'], 'application/javascript');
assert.is(res.headers['content-encoding'], 'br');
assert.is(res.data, 'brotli js file\n');
assert.is(res.statusCode, 200);
} finally {
server.close();
}
});

brotli('should serve prepared `.gz` file of any asset, if found', async () => {
brotli('should serve prepared `.br` file of any asset, if found', async () => {
let server = utils.http({ brotli: true });
let headers = { 'Accept-Encoding': 'br,gzip' };

try {
let res1 = await server.send('GET', '/', { headers });
assert.is(res1.headers['content-type'], 'text/html');
assert.is(res1.headers['content-encoding'], 'br');
assert.is(res1.data, 'brotli html\n');
assert.is(res1.statusCode, 200);

Expand All @@ -670,11 +672,13 @@ brotli('should be preferred when "Accept-Encoding" allows both', async () => {
try {
let res1 = await server.send('GET', '/', { headers });
assert.is(res1.headers['content-type'], 'text/html');
assert.is(res1.headers['content-encoding'], 'br');
assert.is(res1.data, 'brotli html\n');
assert.is(res1.statusCode, 200);

let res2 = await server.send('GET', '/data.js', { headers });
assert.is(res2.headers['content-type'], 'application/javascript');
assert.is(res2.headers['content-encoding'], 'br');
assert.is(res2.data, 'brotli js file\n');
assert.is(res2.statusCode, 200);
} finally {
Expand All @@ -700,6 +704,7 @@ gzip('should require "Accept-Encoding" match to do anything', async () => {
// the `matches` helper assumes wrong mime type
let res = await server.send('GET', '/data.js', { headers });
assert.is(res.headers['content-type'], 'application/javascript');
assert.is(res.headers['content-encoding'], 'gzip');
assert.is(res.data, 'gzip js file\n');
assert.is(res.statusCode, 200);
} finally {
Expand All @@ -714,6 +719,7 @@ gzip('should serve prepared `.gz` file of any asset, if found', async () => {
try {
let res1 = await server.send('GET', '/', { headers });
assert.is(res1.headers['content-type'], 'text/html');
assert.is(res1.headers['content-encoding'], 'gzip');
assert.is(res1.data, 'gzip html\n');
assert.is(res1.statusCode, 200);

Expand All @@ -731,11 +737,13 @@ gzip('should defer to brotli when "Accept-Encoding" allows both', async () => {
try {
let res1 = await server.send('GET', '/', { headers });
assert.is(res1.headers['content-type'], 'text/html');
assert.is(res1.headers['content-encoding'], 'br');
assert.is(res1.data, 'brotli html\n');
assert.is(res1.statusCode, 200);

let res2 = await server.send('GET', '/data.js', { headers });
assert.is(res2.headers['content-type'], 'application/javascript');
assert.is(res2.headers['content-encoding'], 'br');
assert.is(res2.data, 'brotli js file\n');
assert.is(res2.statusCode, 200);
} finally {
Expand Down

0 comments on commit 7205446

Please sign in to comment.