-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: replace into-stream to Readable.from * test: regression test of issue 288 * fixup * feat: support more types * chore: fix deps * fixup * fixup * fixup * fixup * refactor: update checking condition * fixup * chore: apply suggestion Co-authored-by: Aras Abbasi <aras.abbasi@googlemail.com> Signed-off-by: KaKa <23028015+climba03003@users.noreply.github.com> * fixup * fixup --------- Signed-off-by: KaKa <23028015+climba03003@users.noreply.github.com> Co-authored-by: Aras Abbasi <aras.abbasi@googlemail.com>
- Loading branch information
1 parent
593e2d8
commit 848be9d
Showing
6 changed files
with
156 additions
and
17 deletions.
There are no files selected for viewing
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,48 @@ | ||
'use strict' | ||
|
||
const { test } = require('tap') | ||
const Fastify = require('fastify') | ||
const fastifyCompress = require('..') | ||
const { request, setGlobalDispatcher, Agent } = require('undici') | ||
|
||
setGlobalDispatcher(new Agent({ | ||
keepAliveTimeout: 10, | ||
keepAliveMaxTimeout: 10 | ||
})) | ||
|
||
test('should not corrupt the file content', async (t) => { | ||
// provide 2 byte unicode content | ||
const twoByteUnicodeContent = new Array(5_000) | ||
.fill('0') | ||
.map(() => { | ||
const random = new Array(10).fill('A').join('🍃') | ||
return random + '- FASTIFY COMPRESS,🍃 FASTIFY COMPRESS' | ||
}) | ||
.join('\n') | ||
const fastify = new Fastify() | ||
t.teardown(() => fastify.close()) | ||
|
||
fastify.register(async (instance, opts) => { | ||
await fastify.register(fastifyCompress) | ||
// compression | ||
instance.get('/issue', async (req, reply) => { | ||
return twoByteUnicodeContent | ||
}) | ||
}) | ||
|
||
// no compression | ||
fastify.get('/good', async (req, reply) => { | ||
return twoByteUnicodeContent | ||
}) | ||
|
||
await fastify.listen({ port: 0 }) | ||
|
||
const { port } = fastify.server.address() | ||
const url = `http://localhost:${port}` | ||
|
||
const response = await request(`${url}/issue`) | ||
const response2 = await request(`${url}/good`) | ||
const body = await response.body.text() | ||
const body2 = await response2.body.text() | ||
t.equal(body, body2) | ||
}) |
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