{"size": 2440, "ext": "js", "max_stars_repo_path": "test/options/config.test.js", "max_stars_repo_name": "yyx990803/postcss-loader", "max_stars_repo_stars_event_min_datetime": "2019-02-26T08:50:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T07:00:01.000Z", "max_issues_repo_path": "test/options/config.test.js", "max_issues_repo_name": "yyx990803/postcss-loader", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/options/config.test.js", "max_forks_repo_name": "yyx990803/postcss-loader", "max_forks_repo_forks_event_min_datetime": "2019-04-17T07:05:49.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-17T07:05:49.000Z"}
{"max_stars_count": 9, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 24.6464646465, "max_line_length": 88, "alphanum_fraction": 0.5131147541}
'use strict'

const webpack = require('../helpers/compiler')
const { loader } = require('../helpers/compilation')

describe('Options', () => {
  test('Config - {Object}', () => {
    const config = {
      loader: {}
    }

    return webpack('css/index.js', config).then((stats) => {
        const src = loader(stats).src

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

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

    return webpack('css/index.js', config).then((stats) => {
        const src = loader(stats).src

        expect(src).toEqual("module.exports = \"a { color: black }\\n\"")
        expect(src).toMatchSnapshot()
      })
  })

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

    return webpack('css/index.js', config).then((stats) => {
        const src = loader(stats).src

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


  test('Config - Context - {Object} - with ident', () => {
    const config = {
      loader: {
        options: {
          ident: 'postcss',
          config: {
            path: 'test/fixtures/config/postcss.config.js',
            ctx: { plugin: true }
          }
        }
      }
    }

    return webpack('css/index.js', config).then((stats) => {
        const src = loader(stats).src

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

  test('Pass loader object to config context', () => {
    const config = {
      loader: {
        options: {
          config: {
            path: 'test/fixtures/config/context/postcss.config.js'
          }
        }
      }
    }

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

      expect(expectedAssetName in assets).toBeTruthy();
      expect(assets[expectedAssetName].source()).toBe('123');
    })
  })
})
