Skip to content

Commit

Permalink
Test response body compresssion on HTTP error
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Apr 12, 2020
1 parent 442be0c commit bf0b0cd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/gzip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import zlib = require('zlib');
import test from 'ava';
import getStream = require('get-stream');
import withServer from './helpers/with-server';
import {HTTPError} from '../source';

const testContent = 'Compressible response content.\n';
const testContentUncompressed = 'Uncompressed response content.\n';
Expand All @@ -21,6 +22,18 @@ test('decompress content', withServer, async (t, server, got) => {
t.is((await got('')).body, testContent);
});

test('decompress content on error', withServer, async (t, server, got) => {
server.get('/', (_request, response) => {
response.setHeader('Content-Encoding', 'gzip');
response.status(404);
response.end(gzipData);
});

const error = await t.throwsAsync<HTTPError>(got(''));

t.is(error.response.body, testContent);
});

test('decompress content - stream', withServer, async (t, server, got) => {
server.get('/', (_request, response) => {
response.setHeader('Content-Encoding', 'gzip');
Expand Down

0 comments on commit bf0b0cd

Please sign in to comment.