Skip to content

Commit b00e4f6

Browse files
Moritz Petersmaritz
authored andcommitted
Conditionally run http2 tests if http2 is available
1 parent f4e4dfc commit b00e4f6

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

test/compression.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ var Buffer = require('safe-buffer').Buffer
44
var bytes = require('bytes')
55
var crypto = require('crypto')
66
var http = require('http')
7-
var http2 = require('http2')
87
var request = require('supertest')
98
var zlib = require('zlib')
109

10+
try {
11+
var http2 = require('http2')
12+
} catch (err) {
13+
if (err) {
14+
console.log('http2 tests disabled.')
15+
}
16+
}
17+
1118
var compression = require('..')
1219

1320
describe('compression()', function () {
@@ -302,23 +309,25 @@ describe('compression()', function () {
302309
.expect(200, done)
303310
})
304311

305-
it('should work with http2 server', function (done) {
306-
createHttp2Server({ threshold: 0 }, function (req, res) {
307-
res.setHeader('Content-Type', 'text/plain')
308-
res.end('hello, world')
309-
})
312+
if (http2) {
313+
it('should work with http2 server', function (done) {
314+
createHttp2Server({ threshold: 0 }, function (req, res) {
315+
res.setHeader('Content-Type', 'text/plain')
316+
res.end('hello, world')
317+
})
310318

311-
var client = createHttp2Client()
312-
var request = client.request({
313-
'Accept-Encoding': 'gzip'
314-
})
315-
request.on('response', function (headers) {
316-
assert.equal(headers['content-encoding'], 'gzip')
317-
client.destroy()
318-
done()
319+
var client = createHttp2Client()
320+
var request = client.request({
321+
'Accept-Encoding': 'gzip'
322+
})
323+
request.on('response', function (headers) {
324+
assert.equal(headers['content-encoding'], 'gzip')
325+
client.destroy()
326+
done()
327+
})
328+
request.end()
319329
})
320-
request.end()
321-
})
330+
}
322331

323332
describe('threshold', function () {
324333
it('should not compress responses below the threshold size', function (done) {

0 commit comments

Comments
 (0)