Skip to content

Commit 1ac7112

Browse files
committed
Add tests for SCSS #4
1 parent e3ca17c commit 1ac7112

8 files changed

+64
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
22
npm-debug.log
33
test/**/*.actual.css
4+
test/**/*.actual.scss
45
dev/

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Sorting at-rules, also by at-rule name and parameter.
1212
* Sorting variables.
1313
* Grouping content.
14-
* Currently support CSS, [PreCSS] and most likely any other syntax added by other PostCSS plugins.
14+
* Support CSS, SCSS (if [postcss-scss] parser is used), [PreCSS] and most likely any other syntax added by other PostCSS plugins.
1515

1616
## Installation
1717

@@ -288,3 +288,4 @@ This plugin is heavily inspired by [CSSComb]. Some code logic, tests and documen
288288
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
289289
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
290290
[PreCSS]: https://github.com/jonathantneal/precss
291+
[postcss-scss]: https://github.com/postcss/postcss-scss

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
},
2222
"devDependencies": {
2323
"ava": "^0.7.0",
24-
"eslint": "^1.10.2"
24+
"eslint": "^1.10.2",
25+
"postcss-scss": "^0.1.3"
2526
},
2627
"scripts": {
2728
"test": "ava && eslint index.js test/test.js",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
div p em {
2+
border-bottom:1px solid red; // trololo
3+
// upline comment 1
4+
font-style:italic;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
div p em {
2+
// upline comment 1
3+
font-style:italic;
4+
border-bottom:1px solid red; // trololo
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
div p em {
2+
border-bottom: 1px solid red; // trololo 1
3+
// upline comment 1
4+
// upline comment 2
5+
font-style: italic;
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
div p em {
2+
// upline comment 1
3+
// upline comment 2
4+
font-style: italic;
5+
border-bottom: 1px solid red; // trololo 1
6+
}

test/test.js

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,31 @@ import fs from 'fs';
44
import path from 'path';
55
import plugin from '../';
66

7-
function run(t, input, opts = { }) {
7+
function run(t, input, opts = { }, syntax) {
88
var dir = './fixtures/';
9+
var inputName = input;
10+
var inputExt = 'css';
11+
var inputSplitted = input.split('.');
912

10-
var inputPath = path.resolve(dir + input + '.css');
11-
var expectPath = path.resolve(dir + input + '.expected.css');
12-
var actualPath = path.resolve(dir + input + '.actual.css');
13+
if (inputSplitted.length > 1) {
14+
inputName = inputSplitted[0];
15+
inputExt = inputSplitted[1];
16+
}
17+
18+
var inputPath = path.resolve(dir + inputName + '.' + inputExt);
19+
var expectPath = path.resolve(dir + inputName + '.expected.' + inputExt);
20+
var actualPath = path.resolve(dir + inputName + '.actual.' + inputExt);
1321

1422
var inputCSS = fs.readFileSync(inputPath, 'utf8');
1523
var expectCSS = fs.readFileSync(expectPath, 'utf8');
1624

17-
return postcss([ plugin(opts) ]).process(inputCSS)
25+
if (syntax && syntax === 'scss') {
26+
syntax = { syntax: require('postcss-scss') };
27+
} else {
28+
syntax = {};
29+
}
30+
31+
return postcss([ plugin(opts) ]).process(inputCSS, syntax)
1832
.then( result => {
1933
var actualCSS = result.css;
2034

@@ -42,6 +56,24 @@ test('Should work correctly with one comment in case of 1 group', t => {
4256
] });
4357
});
4458

59+
test('Should work correctly with comments in case of 1 group', t => {
60+
return run(t, 'single-group-comments', { 'sort-order': [
61+
['border-bottom', 'font-style']
62+
] });
63+
});
64+
65+
test('Should work correctly with one comment in case of 1 group. SCSS syntax', t => {
66+
return run(t, 'single-group-comment-scss.scss', { 'sort-order': [
67+
['border-bottom', 'font-style']
68+
] }, 'scss');
69+
});
70+
71+
test('Should work correctly with comments in case of 1 group. SCSS syntax', t => {
72+
return run(t, 'single-group-comments-scss.scss', { 'sort-order': [
73+
['border-bottom', 'font-style']
74+
] }, 'scss');
75+
});
76+
4577
test('Should place the leftovers in the end', t => {
4678
return run(t, 'leftovers-1', { 'sort-order': [
4779
[ 'font' ],
@@ -148,9 +180,3 @@ test('Should sort at-rules by name', t => {
148180
test.skip('Should use default config if config is empty', t => {
149181
return run(t, 'at-rules-by-name', { });
150182
});
151-
152-
test('Should work correctly with comments in case of 1 group', t => {
153-
return run(t, 'single-group-comments', { 'sort-order': [
154-
['border-bottom', 'font-style']
155-
] });
156-
});

0 commit comments

Comments
 (0)