Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyganch committed Jul 11, 2016
1 parent bc9ca2c commit 75e0e9e
Show file tree
Hide file tree
Showing 23 changed files with 279 additions and 121 deletions.
12 changes: 9 additions & 3 deletions src/options/sort-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ module.exports = {
extendedNode.spacesBeforeDelimiter =
this._getNodesByIndex(block, spacesBeforeDelimiter);

i += spacesBeforeDelimiter.length + 1;
node = block.get(i);
i += spacesBeforeDelimiter.length;

// Spaces after delimiter.
// If there is `;` right after the declaration, save it with the
// declaration and mark it for removing from parent node:
if (node && node.is('declarationDelimiter')) {
if (block.get(i + 1) && block.get(i + 1).is('declarationDelimiter')) {
i += 1;
node = block.get(i);
nodesToDelete.push(i);
extendedNode.delim = node;

Expand Down Expand Up @@ -259,6 +260,11 @@ module.exports = {
let spacesBeforeDelimiter = currentNode.spacesBeforeDelimiter || [];
let spacesAfterDelimiter = currentNode.spacesAfterDelimiter || [];

if (node.syntax === 'sass' && spacesBeforeNode.length) {
let space = spacesBeforeNode[0];
space.content = space.content.replace(/\n/, '');
}

spacesBeforeNode.reverse().map(this._removeEmptyLines);
spacesBeforeDelimiter.reverse().map(this._removeEmptyLines);
spacesAfterDelimiter.reverse().map(this._removeEmptyLines);
Expand Down
47 changes: 23 additions & 24 deletions test/core/configure/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,43 @@ let Comb = process.env.TEST_COV ?
let assert = require('assert');

describe('CSScomb#configure', function() {
it.skip('Passing no config to constructor should not configure anything', function() {
it('Passing no config to constructor should not configure anything', function() {
let comb = new Comb();
assert.equal(undefined, comb._handlers);
});

it.skip('Passing valid config name to constructor should configure using correct config', function() {
it('Passing valid config name to constructor should configure using correct config', function() {
let comb = new Comb('zen');
let input = 'a { color: tomato; top: 0; }';
let expected = 'a {top: 0; color: tomato; }';
let output = comb.processString(input);

assert.equal(expected, output);
return comb.processString(input).then(function(output) {
assert.equal(expected, output);
});
});

it.skip('Passing config object to constructor should configure using that object', function() {
comb = new Comb({ 'always-semicolon': true });
input = 'a { color: tomato }';
expected = 'a { color: tomato; }';
return comb.processString(input)
.then(function(actual) {
assert.equal(actual, expected);
});
it('Passing config object to constructor should configure using that object', function() {
let comb = new Comb({ 'always-semicolon': true });
let input = 'a { color: tomato }';
let expected = 'a { color: tomato; }';
return comb.processString(input).then(function(actual) {
assert.equal(actual, expected);
});
});

it.skip('new Comb() should be chainable', function() {
input = 'a { color: tomato; top: 0; }';
expected = 'a {top: 0; color: tomato; }';
output = new Comb('zen').processString(input);

assert.equal(expected, output);
it('new Comb() should be chainable', function() {
let input = 'a { color: tomato; top: 0; }';
let expected = 'a {top: 0; color: tomato; }';
return (new Comb('zen')).processString(input).then(output => {
assert.equal(expected, output);
});
});

it.skip('configure() should be chainable', function() {
input = 'a { color: tomato }';
expected = 'a { color: tomato; }';
return new Comb().configure({ 'always-semicolon': true })
it('configure() should be chainable', function() {
let input = 'a { color: tomato }';
let expected = 'a { color: tomato; }';
return (new Comb()).configure({ 'always-semicolon': true })
.processString(input)
.then(function(actual) {
.then(actual => {
assert.equal(actual, expected);
});
});
Expand Down
54 changes: 54 additions & 0 deletions test/core/core_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
let assert = require('assert');
let fs = require('fs');
let path = require('path');

let Comb = require('../../lib/csscomb');

class CoreTest {
constructor(context, config) {
this.file = context.test.file;
this.syntax = context.test.parent.title;

this.Comb = Comb;
this.comb = new Comb();
if (config) this.comb.configure(config);
}

useConfig(name) {
let config = Comb.getConfig(name);
this.comb.configure(config);
}

getErrors(filename) {
let input = this.readFile(filename);
return this.comb.lintString(input, {syntax: this.syntax});
}

shouldBeEqual(inputFile, expectedFile) {
let input = this.readFile(inputFile);
let expected = expectedFile ? this.readFile(expectedFile) : input;

return this.comb.processString(input, {syntax: this.syntax})
.then(string => assert.equal(string, expected));
}

/**
* Detect options in a file and compare result with expected.
* File names should be relative to test suite's folder.
* @param {Array} options List of options that should be detected
* @param {String} input Name of template file
* @param {Object} expected Expected config with detected options
*/
shouldDetect(options, input, expected) {
let detectedConfig = Comb.detectInString(input, options);
assert.deepEqual(detectedConfig, expected);
}

readFile(filename) {
let dirname = path.dirname(this.file);
let filePath = path.join(dirname, filename);
return fs.readFileSync(filePath, 'utf8');
}
}

module.exports = CoreTest;
30 changes: 21 additions & 9 deletions test/core/get-config/test.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,63 @@
var assert = require('assert');
let Test = require('../core_test');

describe.skip('csscomb methods', function() {
describe('csscomb methods', function() {
it('getConfig()', function() {
let test = new Test(this);
var config = require('../../../config/csscomb.json');

assert.equal(this.Comb.getConfig(), config);
assert.equal(test.Comb.getConfig(), config);
});

it('getConfig(number)', function() {
let test = new Test(this);

assert.throws(function() {
this.Comb.getConfig(16);
test.Comb.getConfig(16);
});
});

it('getConfig(boolean)', function() {
let test = new Test(this);

assert.throws(function() {
this.Comb.getConfig(true);
test.Comb.getConfig(true);
});
});

it('getConfig(empty string)', function() {
let test = new Test(this);
var config = require('../../../config/csscomb.json');

assert.equal(this.Comb.getConfig(''), config);
assert.equal(test.Comb.getConfig(''), config);
});

it('getConfig(invalid string)', function() {
let test = new Test(this);

assert.throws(function() {
this.Comb.getConfig('nani');
test.Comb.getConfig('nani');
});
});

it('getConfig(csscomb)', function() {
let test = new Test(this);
var config = require('../../../config/csscomb.json');

assert.equal(this.Comb.getConfig('csscomb'), config);
assert.equal(test.Comb.getConfig('csscomb'), config);
});

it('getConfig(zen)', function() {
let test = new Test(this);
var config = require('../../../config/zen.json');

assert.equal(this.Comb.getConfig('zen'), config);
assert.equal(test.Comb.getConfig('zen'), config);
});

it('getConfig(yandex)', function() {
let test = new Test(this);
var config = require('../../../config/yandex.json');

assert.equal(this.Comb.getConfig('yandex'), config);
assert.equal(test.Comb.getConfig('yandex'), config);
});
});
51 changes: 38 additions & 13 deletions test/core/less/test.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,66 @@
describe.skip('LESS', function() {
beforeEach(function() {
this.comb.configure({});
});
let Test = require('../core_test');

describe('less', function() {
it('Should parse nested rules', function() {
this.shouldBeEqual('nested-rule.less');
let test = new Test(this);
test.comb.configure({});

return test.shouldBeEqual('nested-rule.less');
});

it('Should parse operations', function() {
this.shouldBeEqual('operation.less');
let test = new Test(this);
test.comb.configure({});

return test.shouldBeEqual('operation.less');
});

it('Should parse parent selector &', function() {
this.shouldBeEqual('parent-selector.less');
let test = new Test(this);
test.comb.configure({});

return test.shouldBeEqual('parent-selector.less');
});

it('Should parse variables', function() {
this.shouldBeEqual('variable.less');
let test = new Test(this);
test.comb.configure({});

return test.shouldBeEqual('variable.less');
});

it('Should parse interpolated variables inside selectors', function() {
this.shouldBeEqual('interpolated-variable-1.less');
let test = new Test(this);
test.comb.configure({});

return test.shouldBeEqual('interpolated-variable-1.less');
});

it('Should parse interpolated variables inside values', function() {
this.shouldBeEqual('interpolated-variable-2.less');
let test = new Test(this);
test.comb.configure({});

return test.shouldBeEqual('interpolated-variable-2.less');
});

it('Should parse @import', function() {
this.shouldBeEqual('import.less');
let test = new Test(this);
test.comb.configure({});

return test.shouldBeEqual('import.less');
});

it('Should parse included mixins', function() {
this.shouldBeEqual('mixin.less');
let test = new Test(this);
test.comb.configure({});

return test.shouldBeEqual('mixin.less');
});

it('Should parse nested @media', function() {
this.shouldBeEqual('nested-media.less');
let test = new Test(this);
test.comb.configure({});

return test.shouldBeEqual('nested-media.less');
});
});
Loading

0 comments on commit 75e0e9e

Please sign in to comment.