Sha256: b3bbf1ccc65441da3c51fda4ee6d109c91c4724d070b0438da946d0544ce79f2

Contents?: true

Size: 1.91 KB

Versions: 46

Compression:

Stored size: 1.91 KB

Contents

const { chdirTestApp, chdirCwd } = require('../helpers')

chdirTestApp()

const getStyleRule = require('../get_style_rule')

describe('getStyleRule', () => {
  afterAll(chdirCwd)

  test('excludes modules by default', () => {
    const cssRule = getStyleRule(/\.(css)$/i)
    const expectation = {
      test: /\.(css)$/i,
      exclude: /\.module\.[a-z]+$/
    }

    expect(cssRule).toMatchObject(expectation)
  })

  test('includes modules if set to true', () => {
    const cssRule = getStyleRule(/\.(scss)$/i, true)
    const expectation = {
      test: /\.(scss)$/i,
      include: /\.module\.[a-z]+$/
    }

    expect(cssRule).toMatchObject(expectation)
  })

  test('adds extra preprocessors if supplied', () => {
    const expectation = [{ foo: 'bar' }]
    const cssRule = getStyleRule(/\.(css)$/i, true, expectation)

    expect(cssRule.use).toMatchObject(expect.arrayContaining(expectation))
  })

  test('adds mini-css-extract-plugin when extract_css is true', () => {
    const MiniCssExtractPlugin = require('mini-css-extract-plugin')
    const expectation = [MiniCssExtractPlugin.loader]

    require('../../config').extract_css = true
    const cssRule = getStyleRule(/\.(css)$/i)

    expect(cssRule.use).toMatchObject(expect.arrayContaining(expectation))
  })

  test('adds style-loader when extract_css is true', () => {
    const expectation = [{loader: 'style-loader'}]

    require('../../config').extract_css = false
    const cssRule = getStyleRule(/\.(css)$/i)

    expect(cssRule.use).toMatchObject(expect.objectContaining(expectation))
  })

  test(`doesn't add mini-css-extract-plugin when extract_css is false`, () => {
    const MiniCssExtractPlugin = require('mini-css-extract-plugin')
    const expectation = [MiniCssExtractPlugin.loader]

    require('../../config').extract_css = false
    const cssRule = getStyleRule(/\.(css)$/i)

    expect(cssRule.use).toMatchObject(expect.not.arrayContaining(expectation))
  })
})

Version data entries

46 entries across 45 versions & 9 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/package/utils/__tests__/get_style_rule.js
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/package/utils/__tests__/get_style_rule.js
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/package/utils/__tests__/get_style_rule.js
optimacms-0.1.61 spec/dummy/node_modules/@rails/webpacker/package/utils/__tests__/get_style_rule.js
jetpacker-0.7.0 package/utils/__tests__/get_style_rule.js
webpacker-5.4.4 package/utils/__tests__/get_style_rule.js
jetpacker-0.6.0 package/utils/__tests__/get_style_rule.js
disco_app-0.16.1 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/get_style_rule.js
disco_app-0.15.2 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/get_style_rule.js
disco_app-0.18.4 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/get_style_rule.js
disco_app-0.18.1 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/get_style_rule.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/get_style_rule.js
disco_app-0.14.0 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/get_style_rule.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@rails/webpacker/package/utils/__tests__/get_style_rule.js
webpacker-5.4.3 package/utils/__tests__/get_style_rule.js
webpacker-5.4.2 package/utils/__tests__/get_style_rule.js
webpacker-5.4.1 package/utils/__tests__/get_style_rule.js
webpacker-5.4.0 package/utils/__tests__/get_style_rule.js
webpacker-5.3.0 package/utils/__tests__/get_style_rule.js
webpacker-5.2.2 package/utils/__tests__/get_style_rule.js