forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalize-config.test.js
141 lines (127 loc) · 3.76 KB
/
normalize-config.test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { normalizeConfig } from '../src/util/normalizeConfig'
import { run, css } from './util/run'
import resolveConfig from '../src/public/resolve-config'
it.each`
config
${{ purge: [{ raw: 'text-center' }] }}
${{ purge: { content: [{ raw: 'text-center' }] } }}
${{ content: { content: [{ raw: 'text-center' }] } }}
`('should normalize content $config', ({ config }) => {
return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
.text-center {
text-align: center;
}
`)
})
})
it.each`
config
${{ purge: { safelist: ['text-center'] } }}
${{ purge: { options: { safelist: ['text-center'] } } }}
${{ content: { safelist: ['text-center'] } }}
`('should normalize safelist $config', ({ config }) => {
return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
.text-center {
text-align: center;
}
`)
})
})
it.each`
config
${{ content: [{ raw: 'text-center' }], purge: { extract: () => ['font-bold'] } }}
${{ content: [{ raw: 'text-center' }], purge: { extract: { DEFAULT: () => ['font-bold'] } } }}
${{ content: [{ raw: 'text-center' }], purge: { options: { defaultExtractor: () => ['font-bold'] } } }}
${{ content: [{ raw: 'text-center' }], purge: { options: { extractors: [{ extractor: () => ['font-bold'], extensions: ['html'] }] } } }}
${{ content: [{ raw: 'text-center' }], purge: { extract: { html: () => ['font-bold'] } } }}
`('should normalize extractors $config', ({ config }) => {
return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
.font-bold {
font-weight: 700;
}
`)
})
})
it('should still be possible to use the "old" v2 config', () => {
let config = {
purge: {
content: [
{ raw: 'text-svelte', extension: 'svelte' },
{ raw: '# My Big Heading', extension: 'md' },
],
options: {
defaultExtractor(content) {
return content.split(' ').concat(['font-bold'])
},
},
extract: {
svelte(content) {
return content.replace('svelte', 'center').split(' ')
},
},
transform: {
md() {
return 'text-4xl'
},
},
},
theme: {
extends: {},
},
variants: {
extends: {},
},
}
return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
.text-center {
text-align: center;
}
.text-4xl {
font-size: 2.25rem;
line-height: 2.5rem;
}
.font-bold {
font-weight: 700;
}
`)
})
})
it('should keep content files with globs', () => {
let config = {
content: ['./example-folder/**/*.{html,js}'],
}
expect(normalizeConfig(resolveConfig(config)).content).toEqual({
files: ['./example-folder/**/*.{html,js}'],
extract: {},
transform: {},
})
})
it('should warn when we detect invalid globs with incorrect brace expansion', () => {
let log = require('../src/util/log')
let spy = jest.spyOn(log.default, 'warn')
let config = {
content: [
'./{example-folder}/**/*.{html,js}',
'./{example-folder}/**/*.{html}',
'./example-folder/**/*.{html}',
],
}
// No rewrite happens
expect(normalizeConfig(resolveConfig(config)).content).toEqual({
files: [
'./{example-folder}/**/*.{html,js}',
'./{example-folder}/**/*.{html}',
'./example-folder/**/*.{html}',
],
extract: {},
transform: {},
})
// But a warning should happen
expect(spy).toHaveBeenCalledTimes(2)
expect(spy.mock.calls.map((x) => x[0])).toEqual(['invalid-glob-braces', 'invalid-glob-braces'])
spy.mockClear()
})