-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from pactumjs/226-cannot-find-brotli-compress…
…ed-page feat: compression request option
- Loading branch information
Showing
8 changed files
with
100 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const pactum = require('../../src/index'); | ||
const expect = require('chai').expect; | ||
|
||
describe('withCompression', () => { | ||
|
||
describe('should process', () => { | ||
|
||
it('with encoding as br', async () => { | ||
await pactum.spec() | ||
.useInteraction({ | ||
request: { | ||
method: 'GET', | ||
path: '/api/compression', | ||
}, | ||
response: { | ||
status: 200, | ||
headers: { | ||
'content-encoding': 'br' | ||
}, | ||
file: 'test/data/files/data.txt.br' | ||
} | ||
}) | ||
.get('http://localhost:9393/api/compression') | ||
.withCompression() | ||
.expectStatus(200); | ||
}); | ||
|
||
}); | ||
|
||
describe('should not process', () => { | ||
|
||
it('without a response body', async () => { | ||
let err; | ||
try { | ||
await pactum.spec() | ||
.useLogLevel('SILENT') | ||
.useInteraction({ | ||
request: { | ||
method: 'GET', | ||
path: '/api/compression', | ||
}, | ||
response: { | ||
status: 200, | ||
headers: { | ||
'content-encoding': 'br' | ||
} | ||
} | ||
}) | ||
.get('http://localhost:9393/api/compression') | ||
.withCompression() | ||
|
||
.expectStatus(200); | ||
} catch (error) { | ||
err = error; | ||
} | ||
expect(err.message).contains('unexpected end of file'); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const fs = require('fs'); | ||
const zlib = require('zlib'); | ||
|
||
const READ_FILE_NAME = 'data.txt'; | ||
const WRITE_FILE_NAME = 'data.txt.br'; | ||
|
||
const read_stream = fs.createReadStream(READ_FILE_NAME); | ||
const write_stream = fs.createWriteStream(WRITE_FILE_NAME); | ||
|
||
const compress = zlib.createBrotliCompress(); | ||
|
||
|
||
read_stream.pipe(compress).pipe(write_stream); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
��Hello World! |