-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.test.js
147 lines (130 loc) · 4.23 KB
/
index.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
142
143
144
145
146
147
import postcss from 'postcss'
import tailwind from 'tailwindcss'
import { expect, test } from 'vitest'
import plugin from './index.js'
const pluginOptions = {}
const commonConfig = {
theme: {
screens: { sm: '640px' },
opacity: {},
colors: {
// inherit: 'inherit',
// current: 'currentColor',
transparent: 'transparent',
black: '#000',
white: '#fff',
gray: {
'100': '#f5f5f5',
'200': '#eeeeee',
'300': '#e0e0e0',
'400': '#bdbdbd',
'500': '#9e9e9e',
'600': '#757575',
'700': '#616161',
'800': '#424242',
'900': '#212121',
},
},
},
plugins: [plugin],
corePlugins: false,
safelist: [
{ pattern: /.*/ },
],
}
test('generates default utilities', () => {
const testConfig = { ...commonConfig }
return postcss(tailwind(testConfig)).process('@tailwind utilities', { from: undefined })
.then((result) => expect(result.css).toMatchSnapshot())
})
test('utilities can be customized', () => {
const testConfig = {
...commonConfig,
theme: {
textFillColor: theme => ({
DEFAULT: '#38b2ac',
transparent: 'transparent',
black: '#000',
white: '#fff',
gray: '#9e9e9e',
}),
textStrokeColor: theme => ({
DEFAULT: '#38b2ac',
transparent: theme('colors.transparent'),
}),
textStrokeWidth: { DEFAULT: '1px', sm: '2px', md: '4px', lg: '8px' },
paintOrder: { stroke: 'stroke' }
},
safelist: [],
content: [
{ raw: String.raw`<div class="text-fill text-fill-transparent text-fill-black text-fill-white text-fill-gray"></div>` },
{ raw: String.raw`<div class="text-stroke text-stroke-transparent"></div>` },
{ raw: String.raw`<div class="text-stroke text-stroke-sm text-stroke-md text-stroke-lg"></div>` },
{ raw: String.raw`<div class="paint-stroke"></div>` },
],
}
return postcss(tailwind(testConfig)).process('@tailwind utilities;', { from: undefined })
.then((result) => expect(result.css).toMatchSnapshot())
})
test('variants can be customized', () => {
const testConfig = {
...commonConfig,
safelist: [],
content: [
{ raw: String.raw`<div class="text-fill-white text-stroke sm:text-stroke-2 text-stroke-black hover:text-fill-gray-300 focus:text-stroke-gray-900"></div>` },
],
}
return postcss(tailwind(testConfig)).process('@tailwind utilities;', { from: undefined })
.then((result) => expect(result.css).toMatchSnapshot())
})
test('utilities can use decimal values', () => {
const testConfig = {
...commonConfig,
theme: {
textStrokeWidth: { '0.5': '0.5px' },
},
safelist: [],
content: [
{ raw: String.raw`<div class="text-stroke-0.5"></div>` },
],
}
return postcss(tailwind(testConfig)).process('@tailwind utilities;', { from: undefined })
.then((result) => expect(result.css).toMatchSnapshot())
})
test('utilities can use negative values', () => {
const testConfig = {
...commonConfig,
theme: {
textStrokeWidth: { '-4': '-4px' },
},
safelist: [],
content: [
{ raw: String.raw`<div class="-text-stroke-4"></div>` },
],
}
return postcss(tailwind(testConfig)).process('@tailwind utilities;', { from: undefined })
.then((result) => expect(result.css).toMatchSnapshot())
})
test('utilities accept arbitrary values', () => {
const testConfig = {
...commonConfig,
safelist: [],
content: [
{ raw: String.raw`<div class="text-fill-[lime] text-stroke-[black] text-stroke-[0.25rem] paint-[stroke_fill_markers]"></div>` },
{ raw: String.raw`<div class="text-fill-[lime] text-stroke-[color:black] text-stroke-[length:0.25rem] paint-[stroke_fill_markers]"></div>` },
],
}
return postcss(tailwind(testConfig)).process('@tailwind utilities;', { from: undefined })
.then((result) => expect(result.css).toMatchSnapshot())
})
test('variants accept arbitrary values', () => {
const testConfig = {
...commonConfig,
safelist: [],
content: [
{ raw: String.raw`<div class="[&>*]:text-fill-[lime]"></div>` },
],
}
return postcss(tailwind(testConfig)).process('@tailwind utilities;', { from: undefined })
.then((result) => expect(result.css).toMatchSnapshot())
})