test('Syntax Error', () => {
    const config = {
      loader: {
        test: /\.css$/,
        options: {
          parser: 'sugarss'
        }
      }
    }

    return webpack('css/index.js', config).then((stats) => {
      const { source } = stats.toJson().modules[1]

      // eslint-disable-next-line
      const error = () => eval(source)

      expect(error).toThrow()

      try {
        error()
      } catch (err) {
        const message = err.message
          .split('\n')
          .slice(1)
          .join('\n')

        expect(message).toMatchSnapshot()
      }
    })
  })
  test('JSS - {String}', () => {
    const config = {
      loader: {
        options: {
          parser: 'postcss-js'
        }
      }
    }

    return webpack('jss/index.js', config).then((stats) => {
      const { source } = stats.toJson().modules[1]

      expect(source).toMatchSnapshot()
    })
  })
  test('Config - {Object}', () => {
    const config = {
      loader: {
        test: /\.css$/
      }
    }

    return webpack('css/index.js', config).then((stats) => {
      const { source } = stats.toJson().modules[1]

      expect(source).toEqual(
        'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
      )

      expect(source).toMatchSnapshot()
    })
  })
  test('Config - Path - {String}', () => {
    const config = {
      loader: {
        test: /\.css$/,
        options: {
          config: { path: 'test/fixtures/config/postcss.config.js' }
        }
      }
    }

    return webpack('css/index.js', config).then((stats) => {
      const { source } = stats.toJson().modules[1]

      expect(source).toEqual('module.exports = "a { color: black }\\n"')
      expect(source).toMatchSnapshot()
    })
  })
  test('Exec - {Boolean}', () => {
    const config = {
      loader: {
        test: /style\.(exec\.js|js)$/,
        options: {
          exec: true
        }
      }
    }

    return webpack('jss/exec/index.js', config).then((stats) => {
      const { source } = stats.toJson().modules[1]

      expect(source).toEqual(
        'module.exports = "a {\\n    color: green\\n}"'
      )

      expect(source).toMatchSnapshot()
    })
  })
  test('Config – Context – Loader {Object}', () => {
    const config = {
      loader: {
        test: /\.css$/,
        options: {
          config: {
            path: 'test/fixtures/config/context/postcss.config.js'
          }
        }
      }
    }

    return webpack('css/index.js', config).then((stats) => {
      const { assets } = stats.compilation

      const asset = 'asset.txt'

      expect(asset in assets).toBeTruthy()
      expect(assets[asset].source()).toBe('123')
    })
  })
  test('Plugins - {Function} - {Object}', () => {
    const config = {
      loader: {
        test: /\.css$/,
        options: {
          ident: 'postcss',
          plugins: () => require('../fixtures/config/plugin')()
        }
      }
    }

    return webpack('css/index.js', config).then((stats) => {
      const { source } = stats.toJson().modules[1]

      expect(source).toEqual(
        'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
      )

      expect(source).toMatchSnapshot()
    })
  })
  test('Config - Context - {Object}', () => {
    const config = {
      loader: {
        test: /\.css$/,
        options: {
          config: {
            path: 'test/fixtures/config/postcss.config.js',
            ctx: { plugin: true }
          }
        }
      }
    }

    return webpack('css/index.js', config).then((stats) => {
      const { source } = stats.toJson().modules[1]

      expect(source).toEqual(
        'module.exports = "a { color: rgba(255, 0, 0, 1.0) }\\n"'
      )

      expect(source).toMatchSnapshot()
    })
  })