Skip to content

Commit 8fe3652

Browse files
Polish test case for PR: replace into-stream to Readable.from (#291)
1 parent 848be9d commit 8fe3652

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
"adm-zip": "^0.5.10",
2424
"fastify": "^4.19.2",
2525
"jsonstream": "^1.0.3",
26+
"node-fetch": "^2",
2627
"standard": "^17.1.0",
2728
"tap": "^16.3.7",
2829
"tsd": "^0.30.0",
29-
"typescript": "^5.1.6",
30-
"undici": "^5.28.3"
30+
"typescript": "^5.1.6"
3131
},
3232
"scripts": {
3333
"coverage": "npm run test:unit -- --coverage-report=html",

test/issue-288.test.js renamed to test/regression/issue-288.test.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22

33
const { test } = require('tap')
44
const Fastify = require('fastify')
5-
const fastifyCompress = require('..')
6-
const { request, setGlobalDispatcher, Agent } = require('undici')
7-
8-
setGlobalDispatcher(new Agent({
9-
keepAliveTimeout: 10,
10-
keepAliveMaxTimeout: 10
11-
}))
5+
const fastifyCompress = require('../..')
6+
const fetch = require('node-fetch')
127

138
test('should not corrupt the file content', async (t) => {
149
// provide 2 byte unicode content
@@ -25,24 +20,22 @@ test('should not corrupt the file content', async (t) => {
2520
fastify.register(async (instance, opts) => {
2621
await fastify.register(fastifyCompress)
2722
// compression
28-
instance.get('/issue', async (req, reply) => {
23+
instance.get('/compress', async (req, reply) => {
2924
return twoByteUnicodeContent
3025
})
3126
})
3227

3328
// no compression
34-
fastify.get('/good', async (req, reply) => {
29+
fastify.get('/no-compress', async (req, reply) => {
3530
return twoByteUnicodeContent
3631
})
3732

38-
await fastify.listen({ port: 0 })
39-
40-
const { port } = fastify.server.address()
41-
const url = `http://localhost:${port}`
33+
const address = await fastify.listen({ port: 0, host: '127.0.0.1' })
4234

43-
const response = await request(`${url}/issue`)
44-
const response2 = await request(`${url}/good`)
45-
const body = await response.body.text()
46-
const body2 = await response2.body.text()
47-
t.equal(body, body2)
35+
const response1 = await fetch(`${address}/compress`)
36+
const response2 = await fetch(`${address}/no-compress`)
37+
const body1 = await response1.text()
38+
const body2 = await response2.text()
39+
t.equal(body1, body2)
40+
t.equal(body1, twoByteUnicodeContent)
4841
})

0 commit comments

Comments
 (0)