Skip to content

Commit 77894cb

Browse files
committed
test(node-fetch): add a test case for zstandard decompression support
1 parent 1e623e9 commit 77894cb

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

test/node-fetch/main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,21 @@ describe('node-fetch', () => {
670670
})
671671
})
672672

673+
it('should decompress zstandard response', function () {
674+
if (typeof zlib.createZstdDecompress !== 'function') {
675+
this.skip()
676+
}
677+
678+
const url = `${base}zstandard`
679+
return fetch(url).then(res => {
680+
assert.strictEqual(res.headers.get('content-type'), 'text/plain')
681+
return res.text().then(result => {
682+
assert.strictEqual(typeof result, 'string')
683+
assert.strictEqual(result, 'hello world')
684+
})
685+
})
686+
})
687+
673688
it('should handle no content response with brotli encoding', function () {
674689
if (typeof zlib.createBrotliDecompress !== 'function') {
675690
this.skip()

test/node-fetch/utils/server.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ module.exports = class TestServer {
164164
}
165165
}
166166

167+
if (p === '/zstandard') {
168+
res.statusCode = 200
169+
res.setHeader('Content-Type', 'text/plain')
170+
if (typeof zlib.createZstdDecompress === 'function') {
171+
res.setHeader('Content-Encoding', 'zstd')
172+
zlib.zstdCompress('hello world', (err, buffer) => {
173+
if (err) {
174+
throw err
175+
}
176+
res.end(buffer)
177+
})
178+
}
179+
}
180+
167181
if (p === '/multiunsupported') {
168182
res.statusCode = 200
169183
res.setHeader('Content-Type', 'text/plain')

0 commit comments

Comments
 (0)