fastify.listen(3000, function (err) { if (err) { throw err } console.log(`server listening on ${fastify.server.address().port}`) })
test('shorthand - request delete params schema', t => { t.plan(4) sget({ method: 'DELETE', url: 'http://localhost:' + fastify.server.address().port + '/params/world/123' }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) t.strictEqual(response.headers['content-length'], '' + body.length) t.deepEqual(JSON.parse(body), { foo: 'world', test: 123 }) }) })
Object.keys(interfaces) .filter(name => name.substr(0, 2) === 'lo') .map(name => interfaces[name]) .reduce((list, set) => list.concat(set), []) .filter(info => info.family === 'IPv6') .map(info => info.address) .shift()
handleError(error) { if (error.code === 'ECONNREFUSED') { console.error( `Connection refused at ${error.address}${error.port ? `:${error.port}` : ''}. ` + 'Check these values in config.js and ensure that rTorrent is running.', ); } this.clearRequestQueue(); if (this.onCompleteFn) { this.onCompleteFn(null, error); } }
test('double listen errors', t => { t.plan(3) const fastify = Fastify() t.tearDown(fastify.close.bind(fastify)) fastify.listen(0, (err) => { t.error(err) fastify.listen(fastify.server.address().port, (err, address) => { t.is(address, null) t.ok(err) }) }) })
test('redirect to `/` - 1', t => { t.plan(1) http.get('http://localhost:' + fastify.server.address().port + '/redirect', function (response) { t.strictEqual(response.statusCode, 302) }) })
test('shorthand - send a falsy boolean', t => { t.plan(3) sget({ method: 'GET', url: 'http://localhost:' + fastify.server.address().port + '/boolean' }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) t.deepEqual(body.toString(), 'false') }) })
test('listen without port without callback with (address)', t => { t.plan(1) const fastify = Fastify() t.tearDown(fastify.close.bind(fastify)) fastify.listen() .then(address => { t.is(address, 'http://127.0.0.1:' + fastify.server.address().port) }) })
fastify.listen(8000, function (err) { if (err) { throw err } console.log(`server listening on ${fastify.server.address().port}`) })
test('shorthand - request delete querystring schema', t => { t.plan(4) sget({ method: 'DELETE', url: 'http://localhost:' + fastify.server.address().port + '/query?hello=123' }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) t.strictEqual(response.headers['content-length'], '' + body.length) t.deepEqual(JSON.parse(body), { hello: 123 }) }) })
test('shorthand - request delete missing schema', t => { t.plan(4) sget({ method: 'DELETE', url: 'http://localhost:' + fastify.server.address().port + '/missing' }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) t.strictEqual(response.headers['content-length'], '' + body.length) t.deepEqual(JSON.parse(body), { hello: 'world' }) }) })
test('shorthand - request get querystring schema', t => { t.plan(4) sget({ method: 'GET', url: 'http://localhost:' + fastify.server.address().port + '/query?hello=123' }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) t.strictEqual(response.headers['content-length'], '' + body.length) t.deepEqual(JSON.parse(body), { hello: 123 }) }) })
test('shorthand - custom serializer', t => { t.plan(4) sget({ method: 'GET', url: 'http://localhost:' + fastify.server.address().port + '/custom-serializer' }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) t.strictEqual(response.headers['content-length'], '' + body.length) t.deepEqual(JSON.parse(body), { hello: 'world' }) }) })