Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polish test case for PR: replace into-stream to Readable.from #291

Merged
merged 8 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"adm-zip": "^0.5.10",
"fastify": "^4.19.2",
"jsonstream": "^1.0.3",
"node-fetch": "^2",
"standard": "^17.1.0",
"tap": "^16.3.7",
"tsd": "^0.30.0",
"typescript": "^5.1.6",
"undici": "^5.28.3"
"typescript": "^5.1.6"
},
"scripts": {
"coverage": "npm run test:unit -- --coverage-report=html",
Expand Down
29 changes: 11 additions & 18 deletions test/issue-288.test.js → test/regression/issue-288.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

const { test } = require('tap')
const Fastify = require('fastify')
const fastifyCompress = require('..')
const { request, setGlobalDispatcher, Agent } = require('undici')

setGlobalDispatcher(new Agent({
keepAliveTimeout: 10,
keepAliveMaxTimeout: 10
}))
const fastifyCompress = require('../..')
const fetch = require('node-fetch')

test('should not corrupt the file content', async (t) => {
// provide 2 byte unicode content
Expand All @@ -25,24 +20,22 @@ test('should not corrupt the file content', async (t) => {
fastify.register(async (instance, opts) => {
await fastify.register(fastifyCompress)
// compression
instance.get('/issue', async (req, reply) => {
instance.get('/compress', async (req, reply) => {
return twoByteUnicodeContent
})
})

// no compression
fastify.get('/good', async (req, reply) => {
fastify.get('/no-compress', async (req, reply) => {
return twoByteUnicodeContent
})

await fastify.listen({ port: 0 })

const { port } = fastify.server.address()
const url = `http://localhost:${port}`
const address = await fastify.listen({ port: 0, host: '127.0.0.1' })

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)
const response1 = await fetch(`${address}/compress`)
const response2 = await fetch(`${address}/no-compress`)
const body1 = await response1.text()
const body2 = await response2.text()
t.equal(body1, body2)
t.equal(body1, twoByteUnicodeContent)
})