Skip to content

Commit

Permalink
Merge pull request #622 from DanPurdy/feature/fix-cli-tests-windows
Browse files Browse the repository at this point in the history
Fix issues with rules and cli tests
  • Loading branch information
bgriffith committed Apr 20, 2016
2 parents a287152 + 8c74614 commit 78e8fdb
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: node_js
node_js:
- '0.10'
- '0.12'
- '4.2'
- '4'
- '5'
- node
- iojs
before_script: npm link
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Test against this version of Node.js
environment:
matrix:
- nodejs_version: '0.10'
- nodejs_version: '0.12'
- nodejs_version: '4'
# Latest version of Node
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/brace-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var isClosingBraceOnNewLine = function (node) {
contentLength = content.length - 1,
lastNode = content.get(contentLength);

if (lastNode.is('space') && helpers.hasEOL(lastNode.content)) {
if (lastNode && lastNode.is('space') && helpers.hasEOL(lastNode.content)) {
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/final-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
if (typeof last.last('block') === 'object') {
var lastBlock = last.last('block');

if (lastBlock.content.length > 0) {
if (lastBlock && lastBlock.content.length > 0) {
if (lastBlock.content[lastBlock.length - 1]) {
last = lastBlock.content[lastBlock.length - 1];
}
Expand Down
63 changes: 21 additions & 42 deletions tests/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ var assert = require('assert'),
path = require('path'),
exec = require('child_process').exec;


describe('cli', function () {

it('should return help instructions', function (done) {
var command = 'sass-lint -h';

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

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

return done(null);
return done();
});
});

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

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

return done(null);
return done();
});
});

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

exec(command, function (err, stdout) {

Expand All @@ -55,7 +55,7 @@ describe('cli', function () {
});

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

exec(command, function (err) {
Expand All @@ -78,7 +78,7 @@ describe('cli', function () {
});

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

exec(command, function (err) {
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('cli', function () {
});

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

exec(command, function (err) {
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('cli', function () {
// Test custom config path

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

exec(command, function (err, stdout) {

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

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

exec(command, function (err, stdout) {

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

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

exec(command, function (err, stdout) {

Expand Down Expand Up @@ -219,8 +219,8 @@ describe('cli', function () {
});

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

exec(command, function (err, stdout) {

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

it('should not include ignored paths', function (done) {

var sassTestsPath = path.join(__dirname, '/sass/'),
files = [];

files.push(sassTestsPath + fs.readdirSync(sassTestsPath));

var command = 'sass-lint -i \'**/*.s+(a|c)ss\'';
var command = 'sass-lint -i **/*.scss -v -q --format json **/cli/*.scss';

exec(command, function (err, stdout) {

if (err) {
return done(err);
}

files.forEach(function (file) {
assert(stdout.indexOf(file) === -1);
});
assert(stdout.indexOf('.scss') === -1);

return done();
});
});

it('should not include multiple ignored paths', function (done) {

var sassTestsPath = path.join(__dirname, '/sass/'),
files = [];

files.push(sassTestsPath + fs.readdirSync(sassTestsPath));

var command = 'sass-lint -i \'**/*.scss, **/*.sass \'';
var command = 'sass-lint -i \'**/*.scss, **/*.sass\' -q -v --format json';

exec(command, function (err, stdout) {

if (err) {
return done(err);
}

files.forEach(function (file) {
assert(stdout.indexOf(file) === -1);
});
assert(stdout.indexOf('.scss') === -1);
assert(stdout.indexOf('.sass') === -1);

return done();
});
});

it('should override filename convention if a valid --syntax is provided', function (done) {

var sassTestsPath = path.join(__dirname, '/sass/'),
files = [];

files.push(sassTestsPath + fs.readdirSync(sassTestsPath));

var command = 'sass-lint --syntax scss tests/sass/cli.txt --verbose';
var command = 'sass-lint --syntax scss tests/cli/cli.txt --verbose --format json';

exec(command, function (err, stdout) {

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

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

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

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

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

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

exec(command, function (err) {
if (!err) {
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/cli/cli-error.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#cli
color: red
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 78e8fdb

Please sign in to comment.