Skip to content

Commit 78e8fdb

Browse files
committedApr 20, 2016
Merge pull request #622 from DanPurdy/feature/fix-cli-tests-windows
Fix issues with rules and cli tests
2 parents a287152 + 8c74614 commit 78e8fdb

10 files changed

+27
-47
lines changed
 

‎.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: node_js
22
node_js:
3-
- '0.10'
43
- '0.12'
5-
- '4.2'
4+
- '4'
5+
- '5'
66
- node
77
- iojs
88
before_script: npm link

‎appveyor.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Test against this version of Node.js
22
environment:
33
matrix:
4-
- nodejs_version: '0.10'
54
- nodejs_version: '0.12'
65
- nodejs_version: '4'
76
# Latest version of Node

‎lib/rules/brace-style.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ var isClosingBraceOnNewLine = function (node) {
8989
contentLength = content.length - 1,
9090
lastNode = content.get(contentLength);
9191

92-
if (lastNode.is('space') && helpers.hasEOL(lastNode.content)) {
92+
if (lastNode && lastNode.is('space') && helpers.hasEOL(lastNode.content)) {
9393
return true;
9494
}
9595
return false;

‎lib/rules/final-newline.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
if (typeof last.last('block') === 'object') {
2020
var lastBlock = last.last('block');
2121

22-
if (lastBlock.content.length > 0) {
22+
if (lastBlock && lastBlock.content.length > 0) {
2323
if (lastBlock.content[lastBlock.length - 1]) {
2424
last = lastBlock.content[lastBlock.length - 1];
2525
}

‎tests/cli.js

+21-42
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ var assert = require('assert'),
44
path = require('path'),
55
exec = require('child_process').exec;
66

7-
87
describe('cli', function () {
8+
99
it('should return help instructions', function (done) {
1010
var command = 'sass-lint -h';
1111

@@ -16,7 +16,7 @@ describe('cli', function () {
1616

1717
assert(stdout.indexOf('Usage') > 0);
1818

19-
return done(null);
19+
return done();
2020
});
2121
});
2222

@@ -30,12 +30,12 @@ describe('cli', function () {
3030

3131
should(stdout).match(/^[0-9]+.[0-9]+(.[0-9]+)?/);
3232

33-
return done(null);
33+
return done();
3434
});
3535
});
3636

3737
it('CLI format option should output JSON', function (done) {
38-
var command = 'sass-lint -c tests/yml/.stylish-output.yml tests/sass/cli.scss --verbose --format json';
38+
var command = 'sass-lint -c tests/yml/.stylish-output.yml tests/cli/cli.scss --verbose --format json';
3939

4040
exec(command, function (err, stdout) {
4141

@@ -55,7 +55,7 @@ describe('cli', function () {
5555
});
5656

5757
it('CLI output option should write to test file', function (done) {
58-
var command = 'sass-lint -c tests/yml/.stylish-output.yml tests/sass/cli.scss --verbose --format json --output tests/cli-output.json',
58+
var command = 'sass-lint -c tests/yml/.stylish-output.yml tests/cli/cli.scss --verbose --format json --output tests/cli-output.json',
5959
outputFile = path.resolve(process.cwd(), 'tests/cli-output.json');
6060

6161
exec(command, function (err) {
@@ -78,7 +78,7 @@ describe('cli', function () {
7878
});
7979

8080
it('CLI output option should write JSON to test file', function (done) {
81-
var command = 'sass-lint -c tests/yml/.stylish-output.yml tests/sass/cli.scss --verbose --format json --output tests/cli-output.json',
81+
var command = 'sass-lint -c tests/yml/.stylish-output.yml tests/cli/cli.scss --verbose --format json --output tests/cli-output.json',
8282
outputFile = path.resolve(process.cwd(), 'tests/cli-output.json');
8383

8484
exec(command, function (err) {
@@ -111,7 +111,7 @@ describe('cli', function () {
111111
});
112112

113113
it('CLI output option should write JSON to test file when upper case format is used', function (done) {
114-
var command = 'sass-lint -c tests/yml/.stylish-output.yml tests/sass/cli.scss --verbose --format JSON --output tests/cli-output.json',
114+
var command = 'sass-lint -c tests/yml/.stylish-output.yml tests/cli/cli.scss --verbose --format JSON --output tests/cli-output.json',
115115
outputFile = path.resolve(process.cwd(), 'tests/cli-output.json');
116116

117117
exec(command, function (err) {
@@ -146,7 +146,7 @@ describe('cli', function () {
146146
// Test custom config path
147147

148148
it('should return JSON from a custom config', function (done) {
149-
var command = 'sass-lint -c tests/yml/.color-keyword-errors.yml tests/sass/cli.scss --verbose';
149+
var command = 'sass-lint -c tests/yml/.color-keyword-errors.yml tests/cli/cli.scss --verbose';
150150

151151
exec(command, function (err, stdout) {
152152

@@ -168,7 +168,7 @@ describe('cli', function () {
168168
// Test 0 errors/warnings when rules set to 0 in config
169169

170170
it('output should return no errors/warnings', function (done) {
171-
var command = 'sass-lint -c tests/yml/.json-lint.yml tests/sass/cli.scss --verbose';
171+
var command = 'sass-lint -c tests/yml/.json-lint.yml tests/cli/cli.scss --verbose';
172172

173173
exec(command, function (err, stdout) {
174174

@@ -190,7 +190,7 @@ describe('cli', function () {
190190
// Test 1 warning when rules set to 0 in config
191191

192192
it('should return a warning', function (done) {
193-
var command = 'sass-lint -c tests/yml/.color-keyword-errors.yml tests/sass/cli.scss --verbose';
193+
var command = 'sass-lint -c tests/yml/.color-keyword-errors.yml tests/cli/cli.scss --verbose';
194194

195195
exec(command, function (err, stdout) {
196196

@@ -219,8 +219,8 @@ describe('cli', function () {
219219
});
220220

221221
it('should return a warning - stylish', function (done) {
222-
var command = 'sass-lint -c tests/yml/.stylish-errors.yml tests/sass/cli.scss --verbose',
223-
expectedOutputLength = 155;
222+
var command = 'sass-lint -c tests/yml/.stylish-errors.yml tests/cli/cli.scss --verbose',
223+
expectedOutputLength = 154;
224224

225225
exec(command, function (err, stdout) {
226226

@@ -236,59 +236,38 @@ describe('cli', function () {
236236
});
237237

238238
it('should not include ignored paths', function (done) {
239-
240-
var sassTestsPath = path.join(__dirname, '/sass/'),
241-
files = [];
242-
243-
files.push(sassTestsPath + fs.readdirSync(sassTestsPath));
244-
245-
var command = 'sass-lint -i \'**/*.s+(a|c)ss\'';
239+
var command = 'sass-lint -i **/*.scss -v -q --format json **/cli/*.scss';
246240

247241
exec(command, function (err, stdout) {
248242

249243
if (err) {
250244
return done(err);
251245
}
252246

253-
files.forEach(function (file) {
254-
assert(stdout.indexOf(file) === -1);
255-
});
247+
assert(stdout.indexOf('.scss') === -1);
256248

257249
return done();
258250
});
259251
});
260252

261253
it('should not include multiple ignored paths', function (done) {
262-
263-
var sassTestsPath = path.join(__dirname, '/sass/'),
264-
files = [];
265-
266-
files.push(sassTestsPath + fs.readdirSync(sassTestsPath));
267-
268-
var command = 'sass-lint -i \'**/*.scss, **/*.sass \'';
254+
var command = 'sass-lint -i \'**/*.scss, **/*.sass\' -q -v --format json';
269255

270256
exec(command, function (err, stdout) {
271257

272258
if (err) {
273259
return done(err);
274260
}
275261

276-
files.forEach(function (file) {
277-
assert(stdout.indexOf(file) === -1);
278-
});
262+
assert(stdout.indexOf('.scss') === -1);
263+
assert(stdout.indexOf('.sass') === -1);
279264

280265
return done();
281266
});
282267
});
283268

284269
it('should override filename convention if a valid --syntax is provided', function (done) {
285-
286-
var sassTestsPath = path.join(__dirname, '/sass/'),
287-
files = [];
288-
289-
files.push(sassTestsPath + fs.readdirSync(sassTestsPath));
290-
291-
var command = 'sass-lint --syntax scss tests/sass/cli.txt --verbose';
270+
var command = 'sass-lint --syntax scss tests/cli/cli.txt --verbose --format json';
292271

293272
exec(command, function (err, stdout) {
294273

@@ -309,7 +288,7 @@ describe('cli', function () {
309288
});
310289

311290
it('should exit with exit code 1 when quiet', function (done) {
312-
var command = 'sass-lint -c tests/yml/.error-output.yml tests/sass/cli-error.scss --verbose --no-exit';
291+
var command = 'sass-lint -c tests/yml/.error-output.yml tests/cli/cli-error.scss --verbose --no-exit';
313292

314293
exec(command, function (err) {
315294
if (err.code === 1) {
@@ -321,7 +300,7 @@ describe('cli', function () {
321300
});
322301

323302
it('should exit with exit code 1 when more warnings than --max-warnings', function (done) {
324-
var command = 'sass-lint -c tests/yml/.color-keyword-errors.yml tests/sass/cli.scss --max-warnings 0';
303+
var command = 'sass-lint -c tests/yml/.color-keyword-errors.yml tests/cli/cli.scss --max-warnings 0';
325304

326305
exec(command, function (err) {
327306
if (err && err.code === 1) {
@@ -333,7 +312,7 @@ describe('cli', function () {
333312
});
334313

335314
it('should not exit with an error if no config is specified', function (done) {
336-
var command = 'sass-lint tests/sass/cli-clean.scss --verbose --no-exit';
315+
var command = 'sass-lint tests/cli/cli-clean.scss --verbose --no-exit';
337316

338317
exec(command, function (err) {
339318
if (!err) {
File renamed without changes.

‎tests/cli/cli-error.sass

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#cli
2+
color: red
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)
Please sign in to comment.