text: 'use strict'
  
  const t = require('tap')
  const Fastify = require('fastify')
  const From = require('..')
  const http = require('http')
  const get = require('simple-get').concat
  
  const instance = Fastify()
  
  t.plan(11)
  t.tearDown(instance.close.bind(instance))
  
  const target = http.createServer((req, res) => {
    t.pass('request proxied')
    t.equal(req.method, 'GET')
    t.equal(req.url, '/')
    res.statusCode = 205
    res.setHeader('Content-Type', 'text/plain')
    res.setHeader('x-my-header', 'hello!')
    res.end('hello world')
  })
  
  instance.get('/', async (request, reply) => {
    const p = reply.from()
    t.is(p, reply)
    return p
  })
  
  t.tearDown(target.close.bind(target))
  
  target.listen(0, (err) => {
    t.error(err)
  
    instance.register(From, {
      base: `http://localhost:${target.address().port}`
    })
  
    instance.listen(0, (err) => {
      t.error(err)
  
      get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
        t.error(err)
        t.equal(res.headers['content-type'], 'text/plain')
        t.equal(res.headers['x-my-header'], 'hello!')
        t.equal(res.statusCode, 205)
        t.equal(data.toString(), 'hello world')
      })
    })
  })
  