Fixes #704 - adds batch CLI tests.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 19 Dec 2016 09:49:00 +0000 (10:49 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 19 Dec 2016 09:53:41 +0000 (10:53 +0100)
Why:

* To compare output generated by CLI and API (should be the same!).

test/batch-test.js

index f651ac6..3bb6d93 100644 (file)
@@ -1,3 +1,4 @@
+var exec = require('child_process').exec;
 var vows = require('vows');
 var path = require('path');
 var fs = require('fs');
@@ -24,7 +25,7 @@ var batchContexts = function () {
 
         return {
           plain: '@import "' + plainPath + '";',
-          preminified: fs.readFileSync(minPath, 'utf8')
+          preminified: fs.readFileSync(minPath, 'utf8').trim()
         };
       },
       'minifying': {
@@ -65,6 +66,25 @@ var batchContexts = function () {
             assert.equal(line, preminifiedTokens[i]);
           });
         }
+      },
+      'minifying via CLI': {
+        'topic': function (data) {
+          var isIE7Mode = filename.indexOf('ie7') > 0;
+
+          exec(
+            '__DIRECT__=1 ./bin/cleancss -b ' + (isIE7Mode ? '-c ie7 ' : '') + path.join(dir, filename),
+            { maxBuffer: 500 * 1024 },
+            this.callback.bind(null, data)
+          );
+        },
+        'outputs right content': function (data, error, stdout) {
+          var optimizedLines = stdout.split(lineBreak);
+          var preoptimizedLines = data.preminified.split(lineBreak);
+
+          optimizedLines.forEach(function (line, i) {
+            assert.equal(line, preoptimizedLines[i]);
+          });
+        }
       }
     };
   });