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

Commit 985a1b4

Browse files
committed
Add tests for legacy modifySelectors API
1 parent 87def19 commit 985a1b4

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

tests/05-modify-selectors.test.css

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.markdown > p {
2+
margin-top: 12px;
3+
}
4+
.font-bold {
5+
font-weight: 700;
6+
}
7+
.foo .foo\:markdown > p {
8+
margin-top: 12px;
9+
}
10+
.foo .foo\:font-bold {
11+
font-weight: 700;
12+
}
13+
.foo .foo\:visited\:markdown:visited > p {
14+
margin-top: 12px;
15+
}
16+
.foo .foo\:hover\:font-bold:hover {
17+
font-weight: 700;
18+
}
19+
@media (min-width: 640px) {
20+
.foo .sm\:foo\:font-bold {
21+
font-weight: 700;
22+
}
23+
}
24+
@media (min-width: 768px) {
25+
.foo .md\:foo\:focus\:font-bold:focus {
26+
font-weight: 700;
27+
}
28+
}
29+
@media (min-width: 1024px) {
30+
.foo .lg\:foo\:disabled\:markdown:disabled > p {
31+
margin-top: 12px;
32+
}
33+
}

tests/05-modify-selectors.test.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="font-bold"></div>
2+
<div class="foo:font-bold"></div>
3+
<div class="foo:hover:font-bold"></div>
4+
<div class="sm:foo:font-bold"></div>
5+
<div class="md:foo:focus:font-bold"></div>
6+
<div class="markdown">
7+
<p>Lorem ipsum dolor sit amet...</p>
8+
</div>
9+
<div class="foo:markdown">
10+
<p>Lorem ipsum dolor sit amet...</p>
11+
</div>
12+
<div class="foo:visited:markdown">
13+
<p>Lorem ipsum dolor sit amet...</p>
14+
</div>
15+
<div class="lg:foo:disabled:markdown">
16+
<p>Lorem ipsum dolor sit amet...</p>
17+
</div>

tests/05-modify-selectors.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const postcss = require('postcss')
2+
const tailwind = require('../src/index.js')
3+
const fs = require('fs')
4+
const path = require('path')
5+
const selectorParser = require('postcss-selector-parser')
6+
7+
function run(input, config = {}) {
8+
return postcss([tailwind(config)]).process(input, { from: path.resolve(__filename) })
9+
}
10+
11+
test('modify selectors', () => {
12+
let config = {
13+
darkMode: 'class',
14+
purge: [path.resolve(__dirname, './05-modify-selectors.test.html')],
15+
corePlugins: { preflight: false },
16+
theme: {},
17+
plugins: [
18+
function ({ addVariant, e }) {
19+
addVariant('foo', ({ modifySelectors, separator }) => {
20+
modifySelectors(({ selector }) => {
21+
return selectorParser((selectors) => {
22+
selectors.walkClasses((classNode) => {
23+
classNode.value = `foo${separator}${classNode.value}`
24+
classNode.parent.insertBefore(classNode, selectorParser().astSync(`.foo `))
25+
})
26+
}).processSync(selector)
27+
})
28+
})
29+
},
30+
],
31+
}
32+
33+
let css = `
34+
@tailwind components;
35+
@tailwind utilities;
36+
37+
@layer components {
38+
.markdown > p {
39+
margin-top: 12px;
40+
}
41+
}
42+
`
43+
44+
return run(css, config).then((result) => {
45+
let expectedPath = path.resolve(__dirname, './05-modify-selectors.test.css')
46+
let expected = fs.readFileSync(expectedPath, 'utf8')
47+
48+
expect(result.css).toMatchCss(expected)
49+
})
50+
})

0 commit comments

Comments
 (0)