This repository has been archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.js
146 lines (141 loc) · 2.95 KB
/
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
const _ = require('lodash');
const cssMatcher = require('jest-matcher-css');
const postcss = require('postcss');
const tailwindcss = require('tailwindcss');
const filtersPlugin = require('./index.js');
const generatePluginCss = (config) => {
return postcss(
tailwindcss(
_.merge({
theme: {
screens: {
'sm': '640px',
},
},
corePlugins: false,
plugins: [
filtersPlugin,
],
}, config)
)
)
.process('@tailwind utilities', {
from: undefined,
})
.then(result => {
return result.css;
});
};
expect.extend({
toMatchCss: cssMatcher,
});
test('there is no output by default', () => {
return generatePluginCss().then(css => {
expect(css).toMatchCss(`
@media (min-width: 640px) {
}
`);
});
});
test('utilities can be customized', () => {
return generatePluginCss({
theme: {
filter: {
'none': 'none',
'grayscale': 'grayscale(1)',
'invert': 'invert(1)',
'sepia': 'sepia(1)',
},
backdropFilter: {
'none': 'none',
'blur': 'blur(20px)',
},
},
}).then(css => {
expect(css).toMatchCss(`
.filter-none {
filter: none;
}
.filter-grayscale {
filter: grayscale(1);
}
.filter-invert {
filter: invert(1);
}
.filter-sepia {
filter: sepia(1);
}
.backdrop-none {
backdrop-filter: none;
}
.backdrop-blur {
backdrop-filter: blur(20px);
}
@media (min-width: 640px) {
.sm\\:filter-none {
filter: none;
}
.sm\\:filter-grayscale {
filter: grayscale(1);
}
.sm\\:filter-invert {
filter: invert(1);
}
.sm\\:filter-sepia {
filter: sepia(1);
}
.sm\\:backdrop-none {
backdrop-filter: none;
}
.sm\\:backdrop-blur {
backdrop-filter: blur(20px);
}
}
`);
});
});
test('variants can be customized', () => {
return generatePluginCss({
theme: {
filter: {
'none': 'none',
'grayscale': 'grayscale(1)',
},
backdropFilter: {
'none': 'none',
'blur': 'blur(20px)',
},
},
variants: {
filter: ['hover'],
backdropFilter: ['active'],
},
}).then(css => {
expect(css).toMatchCss(`
.filter-none {
filter: none;
}
.filter-grayscale {
filter: grayscale(1);
}
.hover\\:filter-none:hover {
filter: none;
}
.hover\\:filter-grayscale:hover {
filter: grayscale(1);
}
.backdrop-none {
backdrop-filter: none;
}
.backdrop-blur {
backdrop-filter: blur(20px);
}
.active\\:backdrop-none:active {
backdrop-filter: none;
}
.active\\:backdrop-blur:active {
backdrop-filter: blur(20px);
}
`);
});
});