Repository: fastify/fastify
File: test/logger/options.test.js (JavaScript)

Code before:
    t.assert.deepEqual(typeof fastify.log.debug, 'function')
    t.assert.deepEqual(typeof fastify.log.trace, 'function')
    t.assert.deepEqual(typeof fastify.log.child, 'function')
  })

  await t.test('Should throw an error if logger instance is passed to `logger`', async (t) => {
    t.plan(2)
    const stream = split(JSON.parse)

    const logger = require('pino')(stream)

    try {
      Fastify({ logger })
    } catch (err) {
      t.assert.ok(err)
      t.assert.deepEqual(err.code, 'FST_ERR_LOG_INVALID_LOGGER_CONFIG')
    }
  })

  await t.test('Should throw an error if options are passed to `loggerInstance`', async (t) => {
    t.plan(2)
    try {
      Fastify({ loggerInstance: { level: 'log' } })
    } catch (err) {
      t.assert.ok(err)
      t.assert.deepEqual(err.code, 'FST_ERR_LOG_INVALID_LOGGER_INSTANCE')
    }
  })

  await t.test('If both `loggerInstance` and `logger` are provided, an error should be thrown', async (t) => {
    t.plan(2)
    const loggerInstanceStream = split(JSON.parse)
    const loggerInstance = pino({ level: 'error' }, loggerInstanceStream)
    const loggerStream = split(JSON.parse)
    try {
      Fastify({
        logger: {
          stream: loggerStream,
          level: 'info'
        },
        loggerInstance
      })
    } catch (err) {
      t.assert.ok(err)
      t.assert.deepEqual(err.code, 'FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED')
    }
  })

  await t.test('`logger` should take pino configuration and create a pino logger', async (t) => {
    const lines = ['hello', 'world']
    t.plan(2 * lines.length + 2)

Review comment (suggestion):
```suggestion
      t.assert.strictEqual(err.code, 'FST_ERR_LOG_INVALID_LOGGER_INSTANCE')
```

Code after:
    t.assert.deepEqual(typeof fastify.log.debug, 'function')
    t.assert.deepEqual(typeof fastify.log.trace, 'function')
    t.assert.deepEqual(typeof fastify.log.child, 'function')
  })

  await t.test('Should throw an error if logger instance is passed to `logger`', async (t) => {
    t.plan(2)
    const stream = split(JSON.parse)

    const logger = require('pino')(stream)

    try {
      Fastify({ logger })
    } catch (err) {
      t.assert.ok(err)
      t.assert.deepEqual(err.code, 'FST_ERR_LOG_INVALID_LOGGER_CONFIG')
    }
  })

  await t.test('Should throw an error if options are passed to `loggerInstance`', async (t) => {
    t.plan(2)
    try {
      Fastify({ loggerInstance: { level: 'log' } })
    } catch (err) {
      t.assert.ok(err)
      t.assert.strictEqual(err.code, 'FST_ERR_LOG_INVALID_LOGGER_INSTANCE')
    }
  })

  await t.test('If both `loggerInstance` and `logger` are provided, an error should be thrown', async (t) => {
    t.plan(2)
    const loggerInstanceStream = split(JSON.parse)
    const loggerInstance = pino({ level: 'error' }, loggerInstanceStream)
    const loggerStream = split(JSON.parse)
    try {
      Fastify({
        logger: {
          stream: loggerStream,
          level: 'info'
        },
        loggerInstance
      })
    } catch (err) {
      t.assert.ok(err)
      t.assert.deepEqual(err.code, 'FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED')
    }
  })

  await t.test('`logger` should take pino configuration and create a pino logger', async (t) => {
    const lines = ['hello', 'world']
    t.plan(2 * lines.length + 2)