From b54fce9ef6aee45d6d9b349575a8c9f657370874 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Mon, 19 Dec 2016 10:49:00 +0100 Subject: [PATCH] Fixes #704 - adds batch CLI tests. Why: * To compare output generated by CLI and API (should be the same!). --- test/batch-test.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/batch-test.js b/test/batch-test.js index f651ac6d..3bb6d933 100644 --- a/test/batch-test.js +++ b/test/batch-test.js @@ -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]); + }); + } } }; }); -- 2.34.1