assert = require('assert'),
cleanCSS = require('../index');
+var lineBreak = process.platform == 'win32' ? /\r\n/g : /\n/g;
+
var batchContexts = function() {
var context = {};
fs.readdirSync(path.join(__dirname, 'data')).forEach(function(filename) {
context[testName] = {
topic: function() {
return {
- plain: fs.readFileSync(path.join(__dirname, 'data', testName + '.css')).toString('utf-8'),
- minimized: fs.readFileSync(path.join(__dirname, 'data', testName + '-min.css')).toString('utf-8').replace(/\n/g, '')
+ plain: fs.readFileSync(path.join(__dirname, 'data', testName + '.css'), 'utf-8').replace(lineBreak, ''),
+ minimized: fs.readFileSync(path.join(__dirname, 'data', testName + '-min.css'), 'utf-8').replace(lineBreak, '')
};
}
}
exec = require('child_process').exec,
fs = require('fs');
+var isWindows = process.platform == 'win32',
+ lineBreak = isWindows ? /\r\n/g : /\n/g;
+
var binaryContext = function(options, context) {
context.topic = function() {
// We add __DIRECT__=1 to switch binary into 'non-piped' mode
- exec("__DIRECT__=1 ./bin/cleancss " + options, this.callback);
+ if (isWindows)
+ exec("set __DIRECT__=1 & node .\\bin\\cleancss " + options, this.callback);
+ else
+ exec("__DIRECT__=1 ./bin/cleancss " + options, this.callback);
};
return context;
};
var pipedContext = function(css, options, context) {
+ if (isWindows)
+ return {};
+
context.topic = function() {
exec("echo \"" + css + "\" | ./bin/cleancss " + options, this.callback);
};
}
}),
'help': binaryContext('-h', {
- 'should output help': function(error, stdout) {
+ 'should output help': function(error, stdout, stderr) {
assert.equal(/usage:/.test(stdout), true);
}
}),
}),
'from source': binaryContext('./test/data/reset.css', {
'should minimize': function(error, stdout) {
- var minimized = fs.readFileSync('./test/data/reset-min.css', 'utf-8').replace(/\n/g, '');
+ var minimized = fs.readFileSync('./test/data/reset-min.css', 'utf-8').replace(lineBreak, '');
assert.equal(stdout, minimized);
}
}),
assert.equal(stdout, '');
},
'should minimize': function(stdout) {
- var minimized = fs.readFileSync('./test/data/reset-min.css', 'utf-8').replace(/\n/g, '');
- var target = fs.readFileSync('./reset-min.css', 'utf-8').replace(/\n/g, '');
+ var minimized = fs.readFileSync('./test/data/reset-min.css', 'utf-8').replace(lineBreak, '');
+ var target = fs.readFileSync('./reset-min.css', 'utf-8').replace(lineBreak, '');
assert.equal(minimized, target);
},
teardown: function() {