-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
test.js
153 lines (138 loc) · 3.87 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
147
148
149
150
151
152
153
const assert = require('assert')
const path = require('path')
const fs = require('fs')
const stripIndent = require('strip-indent')
const plugin = require('./')
const cleanup = str => stripIndent(str).trim()
describe('styled-jsx-plugin-sass', () => {
it('applies plugins', () => {
assert.equal(
plugin('p { img { display: block} color: color(red a(90%)) }', {}).trim(),
cleanup(`
p {
color: color(red a(90%)); }
p img {
display: block; }
`)
)
})
it("does not add space after variable placeholder", () => {
assert.equal(
plugin('p { img { color: %%styled-jsx-placeholder-0%%px; } }', {}).trim(),
cleanup(`
p img {
color: %%styled-jsx-placeholder-0%%px; }
`)
)
})
it("works with placeholders in css functions", () => {
assert.equal(
plugin('div { grid-template-columns: repeat(%%styled-jsx-placeholder-0%%, calc(%%styled-jsx-placeholder-1%%% - %%styled-jsx-placeholder-2%%px)); }', {}).trim(),
cleanup(`
div {
grid-template-columns: repeat(%%styled-jsx-placeholder-0%%, calc(%%styled-jsx-placeholder-1%%% - %%styled-jsx-placeholder-2%%px)); }
`)
)
})
it('works with placeholders', () => {
assert.equal(
plugin(`
p {
img { display: block } color: %%styled-jsx-placeholder-0%%; border-bottom: 1px solid %%styled-jsx-placeholder-1%%;
em { color: %%styled-jsx-placeholder-2%% !important; }
}
%%styled-jsx-placeholder-1%%`,
{}
).trim(),
cleanup(`
p {
color: %%styled-jsx-placeholder-0%%;
border-bottom: 1px solid %%styled-jsx-placeholder-1%%; }
p img {
display: block; }
p em {
color: %%styled-jsx-placeholder-2%% !important; }
%%styled-jsx-placeholder-1%%
`)
)
})
it('works with media queries placeholders', () => {
assert.equal(
plugin(`
p {
display: block;
@media %%styled-jsx-placeholder-0%% { color: red; }
@media (min-width: %%styled-jsx-placeholder-0%%px) { color: blue; }
@media (min-width: %%styled-jsx-placeholder-0%%) { color: yellow; }
}`,
{}
).trim(),
cleanup(`
p {
display: block; }
@media %%styled-jsx-placeholder-0%% {
p {
color: red; } }
@media (min-width: %%styled-jsx-placeholder-0%%px) {
p {
color: blue; } }
@media (min-width: %%styled-jsx-placeholder-0%%) {
p {
color: yellow; } }
`)
)
})
it('works with selectors placeholders', () => {
assert.equal(
plugin('p { display: block; %%styled-jsx-placeholder-0%% { color: red; } }', {}).trim(),
cleanup(`
p {
display: block; }
p %%styled-jsx-placeholder-0%% {
color: red; }
`)
)
})
it('works with @import', () => {
assert.equal(
plugin('@import "fixtures/fixture"; p { color: red }', {}).trim(),
cleanup(`
div {
color: red; }
p {
color: red; }
`)
)
})
it('works with relative @import', () => {
const filename = 'fixtures/entry.scss'
const file = fs.readFileSync(path.join(__dirname, filename))
assert.equal(
plugin(file.toString(), {
sassOptions: {
includePaths: [path.join(__dirname, 'fixtures')]
},
babel: { filename }
}).trim(),
cleanup(`
* {
font-family: "Comic Sans MS" !important; }
p {
color: red; }
`)
)
});
it('applies sassOptions', () => {
assert.equal(
plugin('div { padding: (1 / 3) * 1em }', {
sassOptions: {
precision: 1
}
}).trim(),
cleanup(`
div {
padding: 0.3em; }
`)
)
})
})