forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtargetMode.test.js
More file actions
201 lines (189 loc) · 4.1 KB
/
targetMode.test.js
File metadata and controls
201 lines (189 loc) · 4.1 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import fs from 'fs'
import path from 'path'
import postcss from 'postcss'
import tailwind from '../src/index'
import config from '../stubs/defaultConfig.stub.js'
import processPlugins from '../src/util/processPlugins'
import runInTempDirectory from '../jest/runInTempDirectory'
function css(nodes) {
return postcss.root({ nodes }).toString()
}
it('generates the right CSS in IE11 mode', () => {
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)
const input = fs.readFileSync(inputPath, 'utf8')
return postcss([tailwind({ ...config, target: 'ie11' })])
.process(input, { from: inputPath })
.then(result => {
const expected = fs.readFileSync(
path.resolve(`${__dirname}/fixtures/tailwind-output-ie11.css`),
'utf8'
)
expect(result.css).toBe(expected)
})
})
test('plugins can request the target for a specific plugin key', () => {
const { utilities } = processPlugins(
[
function({ addUtilities, target }) {
addUtilities({
'.testA': {
target: target('testPluginA'),
},
})
},
function({ addUtilities, target }) {
addUtilities({
'.testB': {
target: target('testPluginB'),
},
})
},
function({ addUtilities, target }) {
addUtilities({
'.testC': {
target: target('testPluginC'),
},
})
},
],
{
...config,
target: [
'ie11',
{
testPluginA: 'modern',
testPluginB: 'relaxed',
},
],
}
)
expect(css(utilities)).toMatchCss(`
@layer utilities {
@variants {
.testA {
target: modern
}
}
}
@layer utilities {
@variants {
.testB {
target: relaxed
}
}
}
@layer utilities {
@variants {
.testC {
target: ie11
}
}
}
`)
})
test('browserslist target is translated to a target preset', () => {
return runInTempDirectory(() => {
fs.writeFileSync(
path.resolve('./.browserslistrc'),
`
last 2 versions
IE 11
`
)
const { utilities } = processPlugins(
[
function({ addUtilities, target }) {
addUtilities({
'.test': {
target: target('testPlugin'),
},
})
},
],
{
...config,
target: 'browserslist',
}
)
expect(css(utilities)).toMatchCss(`
@layer utilities {
@variants {
.test {
target: ie11
}
}
}
`)
return Promise.resolve()
})
})
test('browserslist target is translated to a target preset with overrides', () => {
return runInTempDirectory(() => {
fs.writeFileSync(
path.resolve('./.browserslistrc'),
`
last 2 versions
IE 11
`
)
const { utilities } = processPlugins(
[
function({ addUtilities, target }) {
addUtilities({
'.testA': {
target: target('testPluginA'),
},
})
},
function({ addUtilities, target }) {
addUtilities({
'.testB': {
target: target('testPluginB'),
},
})
},
function({ addUtilities, target }) {
addUtilities({
'.testC': {
target: target('testPluginC'),
},
})
},
],
{
...config,
target: [
'browserslist',
{
testPluginA: 'modern',
testPluginB: 'relaxed',
},
],
}
)
expect(css(utilities)).toMatchCss(`
@layer utilities {
@variants {
.testA {
target: modern
}
}
}
@layer utilities {
@variants {
.testB {
target: relaxed
}
}
}
@layer utilities {
@variants {
.testC {
target: ie11
}
}
}
`)
return Promise.resolve()
})
})