Skip to content

Commit fe1b30b

Browse files
committed
Remove prefixTree, update relevant tests
1 parent ca524ef commit fe1b30b

File tree

4 files changed

+64
-79
lines changed

4 files changed

+64
-79
lines changed

__tests__/prefixSelector.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import prefix from '../src/util/prefixSelector'
2+
3+
test('it prefixes classes with the provided prefix', () => {
4+
expect(prefix('tw-', '.foo')).toEqual('.tw-foo')
5+
})
6+
7+
test('it handles a function as the prefix', () => {
8+
const prefixFunc = selector => {
9+
return selector === '.foo' ? 'tw-' : ''
10+
}
11+
12+
expect(prefix(prefixFunc, '.foo')).toEqual('.tw-foo')
13+
expect(prefix(prefixFunc, '.bar')).toEqual('.bar')
14+
})
15+
16+
test('it properly prefixes selectors with non-standard characters', () => {
17+
expect(prefix('tw-', '.hello\\:world')).toEqual('.tw-hello\\:world')
18+
expect(prefix('tw-', '.foo\\/bar')).toEqual('.tw-foo\\/bar')
19+
expect(prefix('tw-', '.wew\\.lad')).toEqual('.tw-wew\\.lad')
20+
})
21+
22+
test('it prefixes all classes in a selector', () => {
23+
expect(prefix('tw-', '.btn-blue .w-1\\/4 > h1.text-xl + a .bar')).toEqual(
24+
'.tw-btn-blue .tw-w-1\\/4 > h1.tw-text-xl + a .tw-bar'
25+
)
26+
})

__tests__/prefixTree.test.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

__tests__/processPlugins.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,44 @@ test("component declarations respect the 'prefix' option by default", () => {
761761
`)
762762
})
763763

764+
test('all selectors in a rule are prefixed', () => {
765+
const { utilities, components } = processPlugins(
766+
[
767+
function({ addUtilities, addComponents }) {
768+
addUtilities({
769+
'.rotate-90, .rotate-1\\/4': {
770+
transform: 'rotate(90deg)',
771+
},
772+
})
773+
addComponents({
774+
'.btn-blue, .btn-red': {
775+
padding: '10px',
776+
},
777+
})
778+
},
779+
],
780+
makeConfig({
781+
options: {
782+
prefix: 'tw-',
783+
},
784+
})
785+
)
786+
787+
expect(css(utilities)).toMatchCss(`
788+
@variants {
789+
.tw-rotate-90, .tw-rotate-1\\/4 {
790+
transform: rotate(90deg)
791+
}
792+
}
793+
`)
794+
795+
expect(css(components)).toMatchCss(`
796+
.tw-btn-blue, .tw-btn-red {
797+
padding: 10px
798+
}
799+
`)
800+
})
801+
764802
test("component declarations can optionally ignore 'prefix' option", () => {
765803
const { components } = processPlugins(
766804
[

src/util/prefixTree.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)