1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const assert = require('assert'); 8const http2 = require('http2'); 9 10const server = http2.createServer(); 11server.on('stream', (stream) => { 12 stream.respond(); 13 stream.end('ok'); 14}); 15 16const types = { 17 boolean: true, 18 function: () => {}, 19 number: 1, 20 object: {}, 21 array: [], 22 null: null, 23 symbol: Symbol('test') 24}; 25 26server.listen(0, common.mustCall(() => { 27 const client = http2.connect(`http://localhost:${server.address().port}`); 28 29 client.on('connect', () => { 30 const outOfRangeNum = 2 ** 32; 31 assert.throws( 32 () => client.setNextStreamID(outOfRangeNum), 33 { 34 name: 'RangeError', 35 code: 'ERR_OUT_OF_RANGE', 36 message: 'The value of "id" is out of range.' + 37 ' It must be > 0 and <= 4294967295. Received ' + outOfRangeNum 38 } 39 ); 40 41 // Should throw if something other than number is passed to setNextStreamID 42 Object.entries(types).forEach(([type, value]) => { 43 if (type === 'number') { 44 return; 45 } 46 47 assert.throws( 48 () => client.setNextStreamID(value), 49 { 50 name: 'TypeError', 51 code: 'ERR_INVALID_ARG_TYPE', 52 message: 'The "id" argument must be of type number.' + 53 common.invalidArgTypeHelper(value) 54 } 55 ); 56 }); 57 58 server.close(); 59 client.close(); 60 }); 61})); 62