forked from postcss/postcss-dark-theme-class
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
131 lines (121 loc) · 3.2 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
let postcss = require('postcss')
let plugin = require('./')
function run(input, output, opts) {
let result = postcss([plugin(opts)]).process(input, { from: undefined })
expect(result.css).toEqual(output)
expect(result.warnings()).toHaveLength(0)
}
it('replaces selectors', () => {
run(
`@media (prefers-color-scheme:dark) {
html.is-a,
html,
:root,
a { }
}`,
`@media (prefers-color-scheme:dark) {
html:not(.is-light).is-a,
html:not(.is-light),
:root:not(.is-light),
html:not(.is-light) a { }
}
html.is-dark.is-a,
html.is-dark,
:root.is-dark,
html.is-dark a { }`
)
})
it('processes inner at-rules', () => {
run(
`@media (prefers-color-scheme: dark) {
@media (min-width: 500px) { a { } }
@media (min-width: 500px) { @media (print) { a { } } }
}`,
`@media (prefers-color-scheme: dark) {
@media (min-width: 500px) { html:not(.is-light) a { } }
@media (min-width: 500px) { @media (print) { html:not(.is-light) a { } } }
}
@media (min-width: 500px) { html.is-dark a { } }
@media (min-width: 500px) { @media (print) { html.is-dark a { } } }`
)
})
it('checks media params deeply', () => {
run(
`@media (x-dark: true) {
a { color: white }
}
@unknown (prefers-color-scheme: dark) {
a { color: white }
}`,
`@media (x-dark: true) {
a { color: white }
}
@unknown (prefers-color-scheme: dark) {
a { color: white }
}`
)
})
it('ignores whitespaces', () => {
run(
`@media ( prefers-color-scheme:dark ) {
a { color: white }
}`,
`@media ( prefers-color-scheme:dark ) {
html:not(.is-light) a { color: white }
}
html.is-dark a { color: white }`
)
})
it('reserve comments', () => {
run(
`@media (prefers-color-scheme:dark) {
/* some comments */
a { color: white }
@media (min-width: 500px) { /* another comments */ a { } }
}`,
`@media (prefers-color-scheme:dark) {
/* some comments */
html:not(.is-light) a { color: white }
@media (min-width: 500px) { /* another comments */ html:not(.is-light) a { } }
}
/* some comments */
html.is-dark a { color: white }
@media (min-width: 500px) { /* another comments */ html.is-dark a { } }`
)
})
it('supports combined queries', () => {
run(
`@media (min-width: 60px) and (prefers-color-scheme: dark) {
a { color: white }
}`,
`@media (min-width: 60px) and (prefers-color-scheme: dark) {
html:not(.is-light) a { color: white }
}@media (min-width: 60px) {
html.is-dark a { color: white }
}`
)
})
it('supports combined queries in the middle', () => {
run(
`@media (width > 0) and (prefers-color-scheme: dark) and (width > 0) {
a { color: white }
}`,
`@media (width > 0) and (prefers-color-scheme: dark) and (width > 0) {
html:not(.is-light) a { color: white }
}@media (width > 0) and (width > 0) {
html.is-dark a { color: white }
}`
)
})
it('allows to change class', () => {
run(
`@media (prefers-color-scheme: dark) {
a { color: white }
}`,
`@media (prefers-color-scheme: dark) {
html:not(.light-theme) a { color: white }
}
html.dark-theme a { color: white }`,
{ darkSelector: '.dark-theme', lightSelector: '.light-theme' }
)
})