From 8fe36526e3743e4c3184e8cdaef96ff87f037b30 Mon Sep 17 00:00:00 2001 From: "Qian (Stanley) Xu" Date: Sun, 31 Mar 2024 15:42:18 +0800 Subject: [PATCH] Polish test case for PR: replace `into-stream` to `Readable.from` (#291) --- package.json | 4 ++-- test/{ => regression}/issue-288.test.js | 29 ++++++++++--------------- 2 files changed, 13 insertions(+), 20 deletions(-) rename test/{ => regression}/issue-288.test.js (52%) diff --git a/package.json b/package.json index 7d78ba4..464f429 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/issue-288.test.js b/test/regression/issue-288.test.js similarity index 52% rename from test/issue-288.test.js rename to test/regression/issue-288.test.js index 8c53ea5..a4e4725 100644 --- a/test/issue-288.test.js +++ b/test/regression/issue-288.test.js @@ -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 @@ -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) })