Fixes options coercing in API.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sat, 29 Nov 2014 00:13:14 +0000 (00:13 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sat, 29 Nov 2014 00:13:14 +0000 (00:13 +0000)
* Apparently it was introduced when renaming options in 3.0.

lib/clean.js
test/module-test.js

index 4c6d9c6..a7693c0 100644 (file)
@@ -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,
index a83ac7a..f994e0a 100644 (file)
@@ -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);