Skip to content

Commit 0caaddb

Browse files
Add CSS fixtures to tests
1 parent 053ba2c commit 0caaddb

9 files changed

+124
-18
lines changed

test/fixtures/exclude-selectors.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
body {
2+
margin: 0;
3+
padding: 0;
4+
}
5+
6+
.a, .b {
7+
color: red;
8+
}
9+
10+
.a *:not(.b) {
11+
text-transform: uppercase;
12+
}
13+
14+
.c {
15+
font-size: 10px;
16+
}
17+
18+
.class-a {
19+
color: coral;
20+
}
21+
22+
.class-b {
23+
color: deepskyblue;
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
body {
2+
margin: 0;
3+
padding: 0;
4+
}
5+
6+
.hello .a, .hello .b {
7+
color: red;
8+
}
9+
10+
.a *:not(.b) {
11+
text-transform: uppercase;
12+
}
13+
14+
.hello .c {
15+
font-size: 10px;
16+
}
17+
18+
.class-a {
19+
color: coral;
20+
}
21+
22+
.class-b {
23+
color: deepskyblue;
24+
}

test/fixtures/group-selectors.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.a, .b {
2+
color: coral;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.hello .a, .hello .b {
2+
color: coral;
3+
}

test/fixtures/keyframes.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.a {
2+
color: coral;
3+
animation: glow 1s linear infinite alternate;
4+
}
5+
6+
.b {
7+
color: deepskyblue;
8+
}
9+
10+
@keyframes glow {
11+
from {
12+
color: coral;
13+
}
14+
to {
15+
color: red;
16+
}
17+
}

test/fixtures/keyframes.expected.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.hello .a {
2+
color: coral;
3+
animation: glow 1s linear infinite alternate;
4+
}
5+
6+
.hello .b {
7+
color: deepskyblue;
8+
}
9+
10+
@keyframes glow {
11+
from {
12+
color: coral;
13+
}
14+
to {
15+
color: red;
16+
}
17+
}

test/fixtures/single-selector.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.a {
2+
color: coral;
3+
}
4+
5+
.b {
6+
color: deepskyblue;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.hello .a {
2+
color: coral;
3+
}
4+
5+
.hello .b {
6+
color: deepskyblue;
7+
}

test/test.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
11

22
var postcss = require('postcss')
33
var assert = require('assert')
4+
var fs = require('fs')
45

56
var prefix = require('..')
67

78
it('should prefix a selector', function () {
89
var out = postcss().use(prefix({
910
prefix: '.hello '
10-
})).process('.a {}\n .b {}').css
11+
})).process(getFixtureContents('single-selector.css')).css
1112

12-
assert(~out.indexOf('.hello .a'))
13-
assert(~out.indexOf('.hello .b'))
13+
var expected = getFixtureContents('single-selector.expected.css')
14+
15+
assert.equal(out, expected)
1416
})
1517

1618
it('should prefix a group of selectors', function () {
1719
var out = postcss().use(prefix({
1820
prefix: '.hello '
19-
})).process('.a, .b {}').css
21+
})).process(getFixtureContents('group-selectors.css')).css
22+
23+
var expected = getFixtureContents('group-selectors.expected.css')
2024

21-
assert(~out.indexOf('.hello .a'))
22-
assert(~out.indexOf('.hello .b'))
25+
assert.equal(out, expected)
2326
})
2427

2528
it('should avoid prefixing excluded selectors', function () {
2629
var out = postcss().use(prefix({
2730
prefix: '.hello ',
2831
exclude: ['body', '.a *:not(.b)', /class-/]
29-
})).process('.a, .b {}\n body {}\n .a *:not(.b) {}\n .c {}\n .class-a{}\n .class-b{}').css
30-
31-
assert(~out.indexOf('.hello .a'))
32-
assert(~out.indexOf('.hello .b'))
33-
assert(~out.indexOf('.hello .c'))
34-
assert(!~out.indexOf('.hello body'))
35-
assert(!~out.indexOf('.hello .a *:not(.b)'))
36-
assert(!~out.indexOf('.hello .class-a'))
37-
assert(!~out.indexOf('.hello .class-b'))
32+
})).process(getFixtureContents('exclude-selectors.css')).css
33+
34+
var expected = getFixtureContents('exclude-selectors.expected.css')
35+
36+
assert.equal(out, expected)
3837
})
3938

4039
it('should skip @keyframes selectors', function () {
4140
var out = postcss().use(prefix({
4241
prefix: '.hello '
43-
})).process('@keyframes anim {from {} to {}}').css
42+
})).process(getFixtureContents('keyframes.css')).css
43+
44+
var expected = getFixtureContents('keyframes.expected.css')
4445

45-
assert(!~out.indexOf('.hello from'))
46-
assert(!~out.indexOf('.hello to'))
46+
assert.equal(out, expected)
4747
})
48+
49+
function getFixtureContents(name) {
50+
return fs.readFileSync('test/fixtures/' + name, 'utf8').trim()
51+
}

0 commit comments

Comments
 (0)