From: Jakub Pawlowicz Date: Sat, 29 Nov 2014 00:13:14 +0000 (+0000) Subject: Fixes options coercing in API. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=dea7c0b6a0f6917777e7be77a649d62065a99288;p=clean-css.git Fixes options coercing in API. * Apparently it was introduced when renaming options in 3.0. --- diff --git a/lib/clean.js b/lib/clean.js index 4c6d9c6d..a7693c05 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -20,16 +20,16 @@ var CleanCSS = module.exports = function CleanCSS(options) { options = options || {}; this.options = { - advanced: options.advanced === undefined ? true : false, - aggressiveMerging: undefined === options.aggressiveMerging ? true : false, + advanced: undefined === options.advanced ? true : !!options.advanced, + aggressiveMerging: undefined === options.aggressiveMerging ? true : !!options.aggressiveMerging, benchmark: options.benchmark, compatibility: new Compatibility(options.compatibility).toOptions(), debug: options.debug, inliner: options.inliner, keepBreaks: options.keepBreaks || false, keepSpecialComments: 'keepSpecialComments' in options ? options.keepSpecialComments : '*', - processImport: undefined === options.processImport ? true : false, - rebase: undefined === options.rebase ? true : false, + processImport: undefined === options.processImport ? true : !!options.processImport, + rebase: undefined === options.rebase ? true : !!options.rebase, relativeTo: options.relativeTo, root: options.root, roundingPrecision: options.roundingPrecision, diff --git a/test/module-test.js b/test/module-test.js index a83ac7a0..f994e0af 100644 --- a/test/module-test.js +++ b/test/module-test.js @@ -1,5 +1,6 @@ var vows = require('vows'); var assert = require('assert'); +var path = require('path'); var CleanCSS = require('../index'); vows.describe('module tests').addBatch({ @@ -235,5 +236,31 @@ vows.describe('module tests').addBatch({ 'should be processed correctly': function(minified) { assert.equal('.one{color:red}', minified); } + }, + 'options': { + 'advanced': { + 'topic': new CleanCSS({ advanced: true }).minify('a{color:red}a{color:#fff}'), + 'gets right output': function (minified) { + assert.equal('a{color:#fff}', minified); + } + }, + 'aggressive merging': { + 'topic': new CleanCSS({ aggressiveMerging: true }).minify('a{display:block;color:red;display:inline-block}'), + 'gets right output': function (minified) { + assert.equal('a{color:red;display:inline-block}', minified); + } + }, + 'process import': { + 'topic': new CleanCSS({ processImport: true }).minify('@import url(/test/data/partials/one.css);'), + 'gets right output': function (minified) { + assert.equal('.one{color:red}', minified); + } + }, + 'rebase': { + 'topic': new CleanCSS({ rebase: true, relativeTo: path.join(process.cwd(), 'test', 'data'), root: process.cwd() }).minify('div{background:url(./dummy.png)}'), + 'gets right output': function (minified) { + assert.include(minified, 'url(/test/data/dummy.png)'); + } + } } }).export(module);