Skip to content

Commit

Permalink
refactor: remove node-fetch dev dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
climba03003 committed Apr 1, 2024
1 parent 8fe3652 commit 74f3afb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"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",
Expand Down
31 changes: 26 additions & 5 deletions test/regression/issue-288.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@
const { test } = require('tap')
const Fastify = require('fastify')
const fastifyCompress = require('../..')
const fetch = require('node-fetch')
const { request } = require('node:http')

function fetch (url) {
return new Promise(function (resolve, reject) {
request(url, function (response) {
// we need to use Buffer.concat to prevent wrong utf8 handling
let body = Buffer.from('')
response.on('data', function (chunk) {
body = Buffer.concat([body, Buffer.from(chunk, 'utf-8')])
})
response.once('error', reject)
response.once('end', function () {
resolve(body.toString())
})
})
.once('error', reject)
.end()
})
}

test('should not corrupt the file content', async (t) => {
t.plan(2)

// provide 2 byte unicode content
const twoByteUnicodeContent = new Array(5_000)
.fill('0')
Expand All @@ -32,10 +52,11 @@ test('should not corrupt the file content', async (t) => {

const address = await fastify.listen({ port: 0, host: '127.0.0.1' })

const response1 = await fetch(`${address}/compress`)
const response2 = await fetch(`${address}/no-compress`)
const body1 = await response1.text()
const body2 = await response2.text()
const [body1, body2] = await Promise.all([
fetch(`${address}/compress`),
fetch(`${address}/no-compress`)
])

t.equal(body1, body2)
t.equal(body1, twoByteUnicodeContent)
})

0 comments on commit 74f3afb

Please sign in to comment.