Repository: fastify/fastify
File: test/skip-reply-send.test.js (JavaScript)

Code before:
        })
        app.get('/', (req, reply) => t.fail('Handler should not be called'))
      }

      nextHooks.forEach(h => app.addHook(h, async (req, reply) => t.fail(`${h} should not be called`)))

      app.listen({ port: 0 }, err => {
        t.error(err)
        const client = net.createConnection({ port: (app.server.address()).port }, () => {
          client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')

          let chunks = ''
          client.setEncoding('utf8')
          client.on('data', data => {
            chunks += data
          })

          client.on('end', function () {
            t.match(chunks, new RegExp(`hello from ${hookOrHandler}`, 'i'))
            t.end()
          })
        })
      })
    })

    test('Throwing an error doesn\'t trigger any hooks', t => {
      const stream = split(JSON.parse)
      const app = Fastify({
        logger: {
          stream
        }
      })
      t.teardown(() => app.close())

      let errorSeen = false
      stream.on('data', (line) => {
        if (hookOrHandler === 'handler') {
          if (line.level === 40) {
            errorSeen = true
            t.equal(line.err.code, 'FST_ERR_REP_ALREADY_SENT')
          }
        } else {
          t.not(line.level, 40) // there are no errors
          t.not(line.level, 50) // there are no errors
        }
      })

      previousHooks.forEach(h => app.addHook(h, async (req, reply) => t.pass(`${h} should be called`)))

      if (hookOrHandler === 'handler') {
        app.get('/', (req, reply) => {

Review comment (suggestion):
```suggestion
    test('Throwing an error does not trigger any hooks', t => {
```

Code after:
        })
        app.get('/', (req, reply) => t.fail('Handler should not be called'))
      }

      nextHooks.forEach(h => app.addHook(h, async (req, reply) => t.fail(`${h} should not be called`)))

      app.listen({ port: 0 }, err => {
        t.error(err)
        const client = net.createConnection({ port: (app.server.address()).port }, () => {
          client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')

          let chunks = ''
          client.setEncoding('utf8')
          client.on('data', data => {
            chunks += data
          })

          client.on('end', function () {
            t.match(chunks, new RegExp(`hello from ${hookOrHandler}`, 'i'))
            t.end()
          })
        })
      })
    })

    test('Throwing an error does not trigger any hooks', t => {
      const stream = split(JSON.parse)
      const app = Fastify({
        logger: {
          stream
        }
      })
      t.teardown(() => app.close())

      let errorSeen = false
      stream.on('data', (line) => {
        if (hookOrHandler === 'handler') {
          if (line.level === 40) {
            errorSeen = true
            t.equal(line.err.code, 'FST_ERR_REP_ALREADY_SENT')
          }
        } else {
          t.not(line.level, 40) // there are no errors
          t.not(line.level, 50) // there are no errors
        }
      })

      previousHooks.forEach(h => app.addHook(h, async (req, reply) => t.pass(`${h} should be called`)))

      if (hookOrHandler === 'handler') {
        app.get('/', (req, reply) => {