Skip to content

Commit

Permalink
Polish test case for PR: replace into-stream to Readable.from (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyxu2005 committed Mar 31, 2024
1 parent 848be9d commit 8fe3652
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package.json
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
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)
})

0 comments on commit 8fe3652

Please sign in to comment.