Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit 697b244

Browse files
committed
Combine tests
1 parent 921cee9 commit 697b244

File tree

5 files changed

+50
-508
lines changed

5 files changed

+50
-508
lines changed

src/index.test.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ div {
340340
.hover\:font-bold:hover {
341341
font-weight: 700;
342342
}
343+
.hover\:custom-util:hover {
344+
background: #abcdef;
345+
}
343346
.focus\:font-normal:focus {
344347
font-weight: 400;
345348
}
@@ -363,6 +366,9 @@ div {
363366
.group:hover .group-hover\:opacity-100 {
364367
opacity: 1;
365368
}
369+
.group:hover .group-hover\:custom-util {
370+
background: #abcdef;
371+
}
366372
.group:active .group-active\:opacity-10 {
367373
opacity: 0.1;
368374
}
@@ -373,6 +379,9 @@ div {
373379
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
374380
transition-duration: 150ms;
375381
}
382+
.motion-safe\:custom-util {
383+
background: #abcdef;
384+
}
376385
}
377386
@media (prefers-reduced-motion: reduce) {
378387
.motion-reduce\:transition {
@@ -382,6 +391,15 @@ div {
382391
transition-duration: 150ms;
383392
}
384393
}
394+
.dark .dark\:custom-util {
395+
background: #abcdef;
396+
}
397+
.foo\:custom-util {
398+
background: #abcdef !important;
399+
}
400+
.foo\:hover\:custom-util:hover {
401+
background: #abcdef !important;
402+
}
385403
@media (min-width: 640px) {
386404
.sm\:container {
387405
width: 100%;
@@ -433,6 +451,9 @@ div {
433451
.sm\:text-center {
434452
text-align: center;
435453
}
454+
.sm\:custom-util {
455+
background: #abcdef;
456+
}
436457
@media (prefers-reduced-motion: no-preference) {
437458
.group:active .sm\:motion-safe\:group-active\:focus\:opacity-10:focus {
438459
opacity: 0.1;
@@ -490,6 +511,11 @@ div {
490511
transition-duration: 150ms;
491512
}
492513
}
514+
@media (prefers-reduced-motion: no-preference) {
515+
.dark .md\:dark\:motion-safe\:foo\:active\:custom-util:active {
516+
background: #abcdef !important;
517+
}
518+
}
493519
}
494520
@media (min-width: 640px) {
495521
@media (min-width: 768px) {

src/index.test.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
></div>
1515
<div class="grid-cols-[200px,repeat(auto-fill,minmax(15%,100px)),300px]"></div>
1616
<div class="mt-6"></div>
17+
<div class="custom-util"></div>
18+
<div class="hover:custom-util"></div>
19+
<div class="group-hover:custom-util"></div>
20+
<div class="foo:custom-util"></div>
21+
<div class="foo:hover:custom-util"></div>
22+
<div class="sm:custom-util"></div>
23+
<div class="dark:custom-util"></div>
24+
<div class="motion-safe:custom-util"></div>
25+
<div class="md:dark:motion-safe:foo:active:custom-util"></div>
1726
<div class="aspect-w-1 aspect-h-2"></div>
1827
<div class="aspect-w-3 aspect-h-4"></div>
1928
<div class="filter-none filter-grayscale"></div>

src/index.test.js

Lines changed: 14 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ test('it works', () => {
2525
},
2626
plugins: [
2727
require('@tailwindcss/aspect-ratio'),
28+
function ({ addVariant }) {
29+
addVariant(
30+
'foo',
31+
({ container }) => {
32+
container.walkRules((rule) => {
33+
rule.selector = `.foo\\:${rule.selector.slice(1)}`
34+
rule.walkDecls((decl) => {
35+
decl.important = true
36+
})
37+
})
38+
},
39+
{ before: 'sm' }
40+
)
41+
},
2842
function ({ addUtilities, addBase, theme }) {
2943
addBase({
3044
h1: {
@@ -144,83 +158,6 @@ test('it works', () => {
144158
})
145159
})
146160

147-
test('using postcss for everything wip', () => {
148-
let config = {
149-
darkMode: 'class',
150-
purge: [path.resolve(__dirname, './index.test.adding-a-custom-variant.html')],
151-
corePlugins: ['opacity'],
152-
theme: {},
153-
plugins: [
154-
function ({ addVariant }) {
155-
addVariant(
156-
'foo',
157-
({ container }) => {
158-
container.walkRules((rule) => {
159-
rule.selector = `.foo\\:${rule.selector.slice(1)}`
160-
rule.walkDecls((decl) => {
161-
decl.important = true
162-
})
163-
})
164-
},
165-
{ before: 'sm' }
166-
)
167-
},
168-
],
169-
}
170-
171-
let css = `
172-
@tailwind utilities;
173-
@layer utilities {
174-
.custom-util {
175-
background: #abcdef;
176-
}
177-
}
178-
`
179-
180-
return run(css, config).then((result) => {
181-
expect(result.css).toMatchCss(`
182-
.opacity-50 {
183-
opacity: 0.5;
184-
}
185-
.custom-util {
186-
background: #abcdef;
187-
}
188-
.hover\\:custom-util:hover {
189-
background: #abcdef;
190-
}
191-
.group:hover .group-hover\\:custom-util {
192-
background: #abcdef;
193-
}
194-
@media (prefers-reduced-motion: no-preference) {
195-
.motion-safe\\:custom-util {
196-
background: #abcdef;
197-
}
198-
}
199-
.dark .dark\\:custom-util {
200-
background: #abcdef;
201-
}
202-
.foo\\:custom-util {
203-
background: #abcdef !important;
204-
}
205-
.foo\\:hover\\:custom-util:hover {
206-
background: #abcdef !important;
207-
}
208-
@media (min-width: 640px) {
209-
.sm\\:custom-util {
210-
background: #abcdef;
211-
}
212-
}
213-
@media (min-width: 768px) {
214-
@media (prefers-reduced-motion: no-preference) {
215-
.dark .md\\:dark\\:motion-safe\\:foo\\:active\\:custom-util:active {
216-
background: #abcdef !important;
217-
}
218-
}
219-
}
220-
`)
221-
})
222-
})
223-
224161
function format(input) {
225162
return prettier.format(input, {
226163
parser: 'css',

src/pluginUtils.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const selectorParser = require('postcss-selector-parser')
22
const postcss = require('postcss')
3+
const { toRgba } = require('tailwindcss/lib/util/withAlphaVariable')
34

45
function updateAllClasses(selectors, updateClass) {
56
let parser = selectorParser((selectors) => {
@@ -46,31 +47,6 @@ function ruleIsEmpty([selector, rules]) {
4647
return Array.isArray(rules) && rules.length === 0
4748
}
4849

49-
function transformRule(rule, transform) {
50-
let [selector, rules] = rule
51-
52-
let transformed = transform(rule)
53-
54-
if (transformed === null) {
55-
return null
56-
}
57-
58-
let [transformedSelector, transformedRules] = transformed
59-
60-
let result = [
61-
transformedSelector,
62-
Array.isArray(transformedRules)
63-
? transformedRules.map((rule) => transformRule(rule, transform)).filter(Boolean)
64-
: transformedRules,
65-
]
66-
67-
if (ruleIsEmpty(result)) {
68-
return null
69-
}
70-
71-
return result
72-
}
73-
7450
function transformAllSelectors(transformSelector, wrap = null) {
7551
return ({ container }) => {
7652
container.walkRules((rule) => {
@@ -144,12 +120,9 @@ function asUnit(modifier, units, lookup = {}) {
144120
})
145121
}
146122

147-
const { toRgba } = require('tailwindcss/lib/util/withAlphaVariable')
148-
149123
module.exports = {
150124
updateAllClasses,
151125
updateLastClasses,
152-
transformRule,
153126
transformAllSelectors,
154127
transformAllClasses,
155128
transformLastClasses,

0 commit comments

Comments
 (0)