-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
get_style_rule.js
56 lines (41 loc) · 1.63 KB
/
get_style_rule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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(`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))
})
})