Skip to content

Commit

Permalink
mergeOptions will always use defaultOptions as base.
Browse files Browse the repository at this point in the history
Fixed test setup.
  • Loading branch information
Christian Stuff committed Apr 20, 2016
1 parent b47aca6 commit de14321
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
3 changes: 2 additions & 1 deletion jsontosass.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var JsonToSass = function () {
this.convert = function (json, options) {
var parsedJSON;

this.mergeOptions(this.defaultOptions);
this.mergeOptions(options);

parsedJSON = JSON.parse(json);
Expand Down Expand Up @@ -181,7 +182,7 @@ var JsonToSass = function () {
}
}

this.options = extend(this.options, options);
this.options = extend({}, this.defaultOptions, options);
};

this.shouldPrettify = function () {
Expand Down
64 changes: 35 additions & 29 deletions test/jsontosass.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var assert = require('chai').assert;
var fs = require('fs');
var glob = require('glob');
var jsontosass;
var jsontosass = require('../jsontosass.js');

function removeFiles () {
glob('test/*.s[ac]ss', function (er, files) {
Expand All @@ -12,13 +12,6 @@ function removeFiles () {
}

describe('jsontosass', function () {
beforeEach(function () {
jsontosass = require('../jsontosass.js');
jsontosass.mergeOptions(jsontosass.defaultOptions);
jsontosass.mergeOptions({
prettify: false
});
});
after(function () {
// delete generated test sass files
removeFiles();
Expand Down Expand Up @@ -48,6 +41,11 @@ describe('jsontosass', function () {
});
});
describe('convertObject()', function () {
beforeEach(function () {
jsontosass.mergeOptions({
prettify: false
});
});
it('is present', function () {
assert.isFunction(jsontosass.convertObject);
});
Expand Down Expand Up @@ -82,18 +80,24 @@ describe('jsontosass', function () {
it('is present', function () {
assert.isFunction(jsontosass.convertFile);
});
it('basic file conversion', function () {
var sass;
jsontosass.convertFile('test/basic.json', 'test/basic.scss', function () {
sass = fs.readFileSync('test/basic.scss');
assert.equal(sass, '$key:value;');
it('basic file conversion', function (done) {
var testFile = 'test/basic.scss';
jsontosass.convertFile('test/basic.json', testFile, { prettify: false }, function () {
fs.readFile(testFile, 'utf8', function (err, sass) {
if (err) throw err;
assert.equal(sass, '$key:value;');
done();
});
});
});
it('extended file conversion', function () {
var sass;
jsontosass.convertFile('test/extended.json', 'test/extended.scss', function () {
sass = fs.readFileSync('test/extended.scss');
assert.equal(sass, "$key:(inner-key:(1,2,3),some-object:(color-black:#000,font-family:'Helvetica, sans-serif'));");
it('extended file conversion', function (done) {
var testFile = 'test/extended.scss';
jsontosass.convertFile('test/extended.json', testFile, { prettify: false }, function () {
fs.readFile(testFile, 'utf8', function (err, sass) {
if (err) throw err;
assert.equal(sass, "$key:(inner-key:(1,2,3),some-object:(color-black:#000,font-family:'Helvetica, sans-serif'));");
done();
});
});
});
});
Expand All @@ -106,14 +110,14 @@ describe('jsontosass', function () {
});
it('basic file conversion', function () {
var sass;
jsontosass.convertFileSync('test/basic.json', 'test/basic.scss');
sass = fs.readFileSync('test/basic.scss');
jsontosass.convertFileSync('test/basic.json', 'test/basic.scss', { prettify: false });
sass = fs.readFileSync('test/basic.scss', 'utf8');
assert.equal(sass, '$key:value;');
});
it('extended file conversion', function () {
var sass;
jsontosass.convertFileSync('test/extended.json', 'test/extended.scss');
sass = fs.readFileSync('test/extended.scss');
jsontosass.convertFileSync('test/extended.json', 'test/extended.scss', { prettify: false });
sass = fs.readFileSync('test/extended.scss', 'utf8');
assert.equal(sass, "$key:(inner-key:(1,2,3),some-object:(color-black:#000,font-family:'Helvetica, sans-serif'));");
});
});
Expand Down Expand Up @@ -145,20 +149,22 @@ describe('jsontosass', function () {
}), '$key: (\n key2: value\n);');
});
it('respect indent with tabs', function () {
assert.equal(jsontosass.convert('{"key":{"key2":"value"}}', {
var options = {
indent: 'tabs',
prettify: true
}), '$key: (\n\tkey2: value\n);');
assert.equal(jsontosass.convert('{"key":{"key2":{"key3":"value"}}}'), '$key: (\n\tkey2: (\n\t\tkey3: value\n\t)\n);');
};
assert.equal(jsontosass.convert('{"key":{"key2":"value"}}', options), '$key: (\n\tkey2: value\n);');
assert.equal(jsontosass.convert('{"key":{"key2":{"key3":"value"}}}', options), '$key: (\n\tkey2: (\n\t\tkey3: value\n\t)\n);');
});
it('generate dashed variables instead of maps', function () {
assert.equal(jsontosass.convert('{"key":{"key2":"value"}}', {
var options = {
indent: 'tabs',
prettify: true,
useMaps: false
}), '$key-key2: value;');
assert.equal(jsontosass.convert('{"key":{"key2":{"key3":"value"}}}'), '$key-key2-key3: value;');
assert.equal(jsontosass.convert('{"key":{"key2":{"key3":[1,2,3]}}}'), '$key-key2-key3: (1,2,3);');
};
assert.equal(jsontosass.convert('{"key":{"key2":"value"}}', options), '$key-key2: value;');
assert.equal(jsontosass.convert('{"key":{"key2":{"key3":"value"}}}', options), '$key-key2-key3: value;');
assert.equal(jsontosass.convert('{"key":{"key2":{"key3":[1,2,3]}}}', options), '$key-key2-key3: (1,2,3);');
});
});
describe('options', function () {
Expand Down

0 comments on commit de14321

Please sign in to comment.