the `function ()` with a space is more readable.
.option('-t, --timeout [seconds]', 'Per connection timeout when fetching remote @imports (defaults to 5 seconds)')
.option('-d, --debug', 'Shows debug information (minification time & compression efficiency)');
-commands.on('--help', function() {
+commands.on('--help', function () {
console.log(' Examples:\n');
console.log(' %> cleancss one.css');
console.log(' %> cleancss -o one-min.css one.css');
var stdin = process.openStdin();
stdin.setEncoding('utf-8');
var data = '';
- stdin.on('data', function(chunk) {
+ stdin.on('data', function (chunk) {
data += chunk;
});
- stdin.on('end', function() {
+ stdin.on('end', function () {
minify(data);
});
}
function outputFeedback(messages, isError) {
var prefix = isError ? '\x1B[31mERROR\x1B[39m:' : 'WARNING:';
- messages.forEach(function(message) {
+ messages.forEach(function (message) {
console.error('%s %s', prefix, message);
});
}
return fs.existsSync(filepath) && fs.statSync(filepath).isDirectory();
}
-CleanCSS.prototype.minify = function(data, callback) {
+CleanCSS.prototype.minify = function (data, callback) {
var context = {
stats: {},
errors: [],
run(urlsProcessor, 'escape');
run(freeTextProcessor, 'escape');
- run(function() {
+ run(function () {
return selectorsOptimizer.process(data, stringify, function (data) {
data = freeTextProcessor.restore(data);
data = urlsProcessor.restore(data);
}
var requestOptions = override(url.parse(importedUrl), context.inliner.request);
- get(requestOptions, function(res) {
+ get(requestOptions, function (res) {
if (res.statusCode < 200 || res.statusCode > 399) {
return handleError('error ' + res.statusCode);
} else if (res.statusCode > 299) {
var chunks = [];
var parsedUrl = url.parse(importedUrl);
- res.on('data', function(chunk) {
+ res.on('data', function (chunk) {
chunks.push(chunk.toString());
});
- res.on('end', function() {
+ res.on('end', function () {
var importedData = chunks.join('');
if (context.rebase)
importedData = rewriteUrls(importedData, { toBase: originalUrl }, context);
});
});
})
- .on('error', function(res) {
+ .on('error', function (res) {
handleError(res.message);
})
- .on('timeout', function() {
+ .on('timeout', function () {
handleError('timeout');
})
.setTimeout(context.inliner.timeout);
.replace(/(^|\s)0+([1-9])/g, '$1$2')
.replace(/(^|\D)\.0+(\D|$)/g, '$10$2')
.replace(/(^|\D)\.0+(\D|$)/g, '$10$2')
- .replace(/\.([1-9]*)0+(\D|$)/g, function(match, nonZeroPart, suffix) {
+ .replace(/\.([1-9]*)0+(\D|$)/g, function (match, nonZeroPart, suffix) {
return (nonZeroPart.length > 0 ? '.' : '') + nonZeroPart + suffix;
})
.replace(/(^|\D)0\.(\d)/g, '$1.$2');
return value;
return value
- .replace(precisionOptions.regexp, function(match, number) {
+ .replace(precisionOptions.regexp, function (match, number) {
return Math.round(parseFloat(number) * precisionOptions.multiplier) / precisionOptions.multiplier + 'px';
})
.replace(/(\d)\.($|\D)/g, '$1$2');
else
return prefix + '#' + color;
})
- .replace(/(rgb|rgba|hsl|hsla)\(([^\)]+)\)/g, function(match, colorFunction, colorDef) {
+ .replace(/(rgb|rgba|hsl|hsla)\(([^\)]+)\)/g, function (match, colorFunction, colorDef) {
var tokens = colorDef.split(',');
var applies = (colorFunction == 'hsl' && tokens.length == 3) ||
(colorFunction == 'hsla' && tokens.length == 4) ||
}
}
-SimpleOptimizer.prototype.optimize = function(tokens) {
+SimpleOptimizer.prototype.optimize = function (tokens) {
var self = this;
var hasCharset = false;
var options = this.options;
// Strip content tags by replacing them by the a special
// marker for further restoring. It's done via string scanning
// instead of regexps to speed up the process.
-FreeTextProcessor.prototype.escape = function(data) {
+FreeTextProcessor.prototype.escape = function (data) {
var self = this;
var breaksCount;
var lastBreakAt;
var metadata;
var saveWaypoints = this.saveWaypoints;
- return new QuoteScanner(data).each(function(match, store) {
+ return new QuoteScanner(data).each(function (match, store) {
if (saveWaypoints) {
breaksCount = match.split(lineBreak).length - 1;
lastBreakAt = match.lastIndexOf(lineBreak);
return text;
}
-FreeTextProcessor.prototype.restore = function(data) {
+FreeTextProcessor.prototype.restore = function (data) {
var tempData = [];
var cursor = 0;
onSuccess(chunks.join(''));
});
})
- .on('error', function(res) {
+ .on('error', function (res) {
if (errorHandled)
return;
onFailure(res.message);
errorHandled = true;
})
- .on('timeout', function() {
+ .on('timeout', function () {
if (errorHandled)
return;
var lineBreak = require('os').EOL;
-var batchContexts = function() {
+var batchContexts = function () {
var context = {};
var dir = path.join(__dirname, 'fixtures');
- fs.readdirSync(dir).forEach(function(filename) {
+ fs.readdirSync(dir).forEach(function (filename) {
if (filename.indexOf('.css') == -1 || /min.css$/.exec(filename) || !fs.statSync(path.join(dir, filename)).isFile())
return;
var testName = filename.split('.')[0];
context[testName] = {
- topic: function() {
+ topic: function () {
var plainPath = path.join(__dirname, 'fixtures', testName + '.css');
var minPath = path.join(__dirname, 'fixtures', testName + '-min.css');
};
},
minifying: {
- topic: function(data) {
+ topic: function (data) {
var self = this;
new CleanCSS({
keepBreaks: true,
root: data.root
- }).minify(data.plain, function(errors, minified) {
+ }).minify(data.plain, function (errors, minified) {
self.callback(errors, minified.styles, data);
});
},
- 'should output right content': function(errors, minified, data) {
+ 'should output right content': function (errors, minified, data) {
var minifiedTokens = minified.split(lineBreak);
var preminifiedTokens = data.preminified.split(lineBreak);
- minifiedTokens.forEach(function(line, i) {
+ minifiedTokens.forEach(function (line, i) {
assert.equal(line, preminifiedTokens[i]);
});
}
var isWindows = process.platform == 'win32';
var lineBreakRegExp = new RegExp(require('os').EOL, 'g');
-var binaryContext = function(options, context) {
+var binaryContext = function (options, context) {
if (isWindows)
return {};
- context.topic = function() {
+ context.topic = function () {
// We add __DIRECT__=1 to force binary into 'non-piped' mode
exec('__DIRECT__=1 ./bin/cleancss ' + options, this.callback);
};
return context;
};
-var pipedContext = function(css, options, context) {
+var pipedContext = function (css, options, context) {
if (isWindows)
return {};
- context.topic = function() {
+ context.topic = function () {
exec('echo "' + css + '" | ./bin/cleancss ' + options, this.callback);
};
return context;
};
-var unixOnlyContext = function(context) {
+var unixOnlyContext = function (context) {
return isWindows ? {} : context;
};
-var readFile = function(filename) {
+var readFile = function (filename) {
return fs.readFileSync(filename, { encoding: 'utf-8' }).replace(lineBreakRegExp, '');
};
-var deleteFile = function(filename) {
+var deleteFile = function (filename) {
if (isWindows)
exec('del /q /f ' + filename);
else
var CleanCSS = require('../index');
var lineBreak = require('os').EOL;
-var cssContext = function(groups, options) {
+var cssContext = function (groups, options) {
var context = {};
var clean = function (expected) {
'complex': 'a{width:expression((this.parentNode.innerWidth + this.parentNode.innerHeight) / 2 )}',
'with parentheses': "a{width:expression(this.parentNode.innerText == ')' ? '5px' : '10px' )}",
'open ended (broken)': "a{width:expression(this.parentNode.innerText == }",
- 'function call & advanced': 'a{zoom:expression(function(el){el.style.zoom="1"}(this))}'
+ 'function call & advanced': 'a{zoom:expression(function (el){el.style.zoom="1"}(this))}'
}),
'text content': cssContext({
'normal #1': 'a{content:"."}',
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}@media print{div{display:block}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media screen{a{color:red}}@media print{div{display:block}}');
}
},
'topic': function () {
return new CleanCSS().minify('@font-face{font-family:A}@font-face{font-family:B}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@font-face{font-family:A}@font-face{font-family:B}');
}
},
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}div{}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media screen{a{color:red}}');
}
}
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}@media screen{div{display:block}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media screen{a{color:red}div{display:block}}');
}
},
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}@media screen{div{display:block}}@media screen{body{width:100%}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media screen{a{color:red}div{display:block}body{width:100%}}');
}
},
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}body{width:100%}.one{height:100px}@media screen{div{display:block}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, 'body{width:100%}.one{height:100px}@media screen{a{color:red}div{display:block}}');
}
},
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}@media (min-width:1024px){body{width:100%}}@media screen{div{display:block}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media (min-width:1024px){body{width:100%}}@media screen{a{color:red}div{display:block}}');
}
},
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}.one{color:#00f}@media screen{div{display:block}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media screen{a{color:red}}.one{color:#00f}@media screen{div{display:block}}');
}
},
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}@media (min-width:1024px){.one{color:#00f}}@media screen{div{display:block}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media screen{a{color:red}}@media (min-width:1024px){.one{color:#00f}}@media screen{div{display:block}}');
}
},
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}@media (min-width:1024px){@media screen{.one{color:#00f}}}@media screen{div{display:block}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media screen{a{color:red}}@media (min-width:1024px){@media screen{.one{color:#00f}}}@media screen{div{display:block}}');
}
},
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}@media (min-width:1024px){p{width:100%}}@media screen{div{display:block}}@media (min-width:1024px){body{height:100%}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media screen{a{color:red}div{display:block}}@media (min-width:1024px){p{width:100%}body{height:100%}}');
}
},
'topic': function () {
return new CleanCSS().minify('@media screen{a{font-size:10px}}@media (min-width:1024px){.one{font:12px Helvetica}}@media screen{div{display:block}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media screen{a{font-size:10px}}@media (min-width:1024px){.one{font:12px Helvetica}}@media screen{div{display:block}}');
}
},
'topic': function () {
return new CleanCSS().minify('@media screen{a{font-size:10px}}@media (min-width:1024px){.one{font-weight:700}}@media screen{div{display:block}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media (min-width:1024px){.one{font-weight:700}}@media screen{a{font-size:10px}div{display:block}}');
}
},
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}@media (min-width:1024px){.one{color:red}}@media screen{div{display:block}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media (min-width:1024px){.one{color:red}}@media screen{a{color:red}div{display:block}}');
}
},
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}.one{color:#000}@media screen{a{color:red}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '.one{color:#000}@media screen{a{color:red}}');
}
},
'topic': function () {
return new CleanCSS().minify('@media print{a{color:#fff}}@media screen{a{color:red}}.one{color:#000}@media screen{a{color:red}}@media print{a{display:block}}@media print{a{color:#fff}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '.one{color:#000}@media screen{a{color:red}}@media print{a{display:block;color:#fff}}');
}
}
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}@media screen{a{display:block}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '@media screen{a{color:red;display:block}}');
}
}
'topic': function () {
return new CleanCSS().minify('@media screen{a{color:red}}/*! a comment */@media screen{a{display:block}}');
},
- 'get merged': function(minified) {
+ 'get merged': function (minified) {
assert.equal(minified.styles, '/*! a comment */@media screen{a{color:red;display:block}}');
}
}
'topic': function () {
return new CleanCSS({ mediaMerging: false }).minify('@media screen{a{color:red}}@media screen{a{display:block}}');
},
- 'keeps @media intact': function(minified) {
+ 'keeps @media intact': function (minified) {
assert.equal(minified.styles, '@media screen{a{color:red}}@media screen{a{display:block}}');
}
}
vows.describe('module tests').addBatch({
'imported as a function': {
- topic: function() {
+ topic: function () {
var css = new CleanCSS();
return css.minify.bind(css);
},
- 'should minify CSS correctly': function(minify) {
+ 'should minify CSS correctly': function (minify) {
assert.equal(minify('a{ color: #f00; }').styles, 'a{color:red}');
}
},
'extended via prototype': {
- topic: function() {
- CleanCSS.prototype.foo = function(data, callback) {
+ topic: function () {
+ CleanCSS.prototype.foo = function (data, callback) {
callback(null, this.minify(data));
};
new CleanCSS().foo('a{ color: #f00; }', this.callback);
},
- 'should minify CSS correctly': function(error, minified) {
+ 'should minify CSS correctly': function (error, minified) {
assert.equal(minified.styles, 'a{color:red}');
},
- teardown: function() {
+ teardown: function () {
delete CleanCSS.prototype.foo;
}
},
'with callback passed and no errors': {
- topic: function() {
+ topic: function () {
new CleanCSS().minify('a{color:#f00}', this.callback);
},
- 'should not set context': function() {
+ 'should not set context': function () {
assert.equal(this instanceof CleanCSS, false);
},
- 'should yield no error': function(errors, minified) {
+ 'should yield no error': function (errors, minified) {
/* jshint unused: false */
assert.isNull(errors);
},
- 'should yield minified data': function(errors, minified) {
+ 'should yield minified data': function (errors, minified) {
assert.equal(minified.styles, 'a{color:red}');
}
},
'with callback passed and one error': {
- topic: function() {
+ topic: function () {
new CleanCSS().minify('@import "missing.css";', this.callback);
},
- 'should yield no error and minify': function(errors, minified) {
+ 'should yield no error and minify': function (errors, minified) {
/* jshint unused: false */
assert.lengthOf(errors, 1);
}
'topic': function () {
return new CleanCSS();
},
- 'if both root and output used reasons given': function(minifier) {
+ 'if both root and output used reasons given': function (minifier) {
assert.doesNotThrow(function () {
minifier.minify('@import url(/some/fake/file);', function (errors) {
assert.isArray(errors);
},
'if both root and output used reasons given': function (minifier) {
minifier.minify('@import url(/some/fake/file);');
- minifier.minify('@import url(/some/fake/file);', function(errors) {
+ minifier.minify('@import url(/some/fake/file);', function (errors) {
assert.lengthOf(errors, 1);
assert.equal(errors[0], 'Broken @import declaration of "/some/fake/file"');
});
}
},
'buffer passed in': {
- 'topic': function() {
+ 'topic': function () {
return new CleanCSS().minify(new Buffer('@import url(test/fixtures/partials/one.css);'));
},
- 'should be processed correctly': function(minified) {
+ 'should be processed correctly': function (minified) {
assert.equal(minified.styles, '.one{color:red}');
}
},
.addBatch({
'with source map': {
topic: 'a{margin-top:10px;margin-bottom:4px;margin-left:5px;margin-right:5px}',
- 'into': function(topic) {
+ 'into': function (topic) {
assert.deepEqual(_optimize(topic), [
[
['margin', false, false, [[1, 2, undefined], [1, 18, undefined], [1, 36, undefined], [1, 52, undefined]]],
vows.describe('protocol imports').addBatch({
'of a missing file': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/missing.css')
.reply(404);
new CleanCSS().minify('@import url(http://127.0.0.1/missing.css);a{color:red}', this.callback);
},
- 'should raise error': function(errors, minified) {
+ 'should raise error': function (errors, minified) {
assert.lengthOf(errors, 1);
},
- 'should ignore @import': function(errors, minified) {
+ 'should ignore @import': function (errors, minified) {
assert.equal(minified.styles, '@import url(http://127.0.0.1/missing.css);a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of an existing file': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/present.css')
.reply(200, 'p{font-size:13px}');
new CleanCSS().minify('@import url(http://127.0.0.1/present.css);a{color:red}', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'p{font-size:13px}a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of an existing file with spaces in path': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://fonts.googleapis.com')
.get('/css?family=Oleo%20Script%20Swash%20Caps')
.reply(200, 'p{font-size:13px}');
new CleanCSS().minify('@import url(\'//fonts.googleapis.com/css?family=Oleo Script Swash Caps\');', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'p{font-size:13px}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of an existing file via HTTPS': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('https://127.0.0.1')
.get('/present.css')
.reply(200, 'p{font-size:13px}');
new CleanCSS().minify('@import url(https://127.0.0.1/present.css);a{color:red}', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'p{font-size:13px}a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of an existing file with media': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/present.css')
.reply(200, 'p{font-size:13px}');
new CleanCSS().minify('@import url(http://127.0.0.1/present.css) screen;a{color:red}', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, '@media screen{p{font-size:13px}}a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of an existing file with dependencies': {
- topic: function() {
+ topic: function () {
this.reqMocks1 = nock('http://127.0.0.1')
.get('/present.css')
.reply(200, '@import url(/vendor/reset.css);@import url(https://assets.127.0.0.1/base.css);p{font-size:13px}')
new CleanCSS().minify('@import url(http://127.0.0.1/present.css);a{color:red}', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'body{margin:0}div{padding:0}p{font-size:13px}a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks1.isDone());
assert.isTrue(this.reqMocks2.isDone());
nock.cleanAll();
}
},
'of an existing file with relative dependencies': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/nested/present.css')
.reply(200, '@import url(../vendor/reset.css);p{font-size:13px}')
new CleanCSS().minify('@import url(http://127.0.0.1/nested/present.css);a{color:red}', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'body{margin:0}p{font-size:13px}a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of an existing file missing relative dependency': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/nested/present.css')
.reply(200, '@import url(../missing.css);p{font-size:13px}')
new CleanCSS().minify('@import url(http://127.0.0.1/nested/present.css);a{color:red}', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.lengthOf(errors, 1);
assert.equal(errors[0], 'Broken @import declaration of "http://127.0.0.1/missing.css" - error 404');
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, '@import url(http://127.0.0.1/missing.css);p{font-size:13px}a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of an existing file with URLs to rebase': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/urls.css')
.reply(200, 'a{background:url(test.png)}');
new CleanCSS().minify('@import url(http://127.0.0.1/urls.css);', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'a{background:url(http://127.0.0.1/test.png)}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of an existing file with relative URLs to rebase': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/base.css')
.reply(200, '@import url(deeply/nested/urls.css);')
new CleanCSS().minify('@import url(http://127.0.0.1/base.css);', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'a{background:url(http://127.0.0.1/deeply/images/test.png)}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of an existing file with relative URLs and rebase turned off': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/base.css')
.reply(200, '@import url(deeply/nested/urls.css);')
new CleanCSS({ rebase: false }).minify('@import url(http://127.0.0.1/base.css);', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'a{background:url(../images/test.png)}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of an unreachable domain': {
- topic: function() {
+ topic: function () {
new CleanCSS().minify('@import url(http://0.0.0.0/custom.css);a{color:red}', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.lengthOf(errors, 1);
assert.include(errors[0], 'Broken @import declaration of "http://0.0.0.0/custom.css"');
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, '@import url(http://0.0.0.0/custom.css);a{color:red}');
}
},
'of a 30x response with absolute URL': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/moved.css')
.reply(301, '', { 'Location': 'http://127.0.0.1/present.css' })
new CleanCSS().minify('@import url(http://127.0.0.1/moved.css);a{color:red}', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'body{margin:0}a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of a 30x response with relative URL': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/moved.css')
.reply(301, '', { 'Location': '/present.css' })
new CleanCSS().minify('@import url(http://127.0.0.1/moved.css);a{color:red}', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'body{margin:0}a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of a cyclical reference response': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/one.css')
.reply(200, '@import url(/two.css);div{padding:0}')
new CleanCSS().minify('@import url(http://127.0.0.1/one.css);a{color:red}', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'body{margin:0}div{padding:0}a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of a resource without protocol': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/no-protocol.css')
.reply(200, 'div{padding:0}');
new CleanCSS().minify('@import url(//127.0.0.1/no-protocol.css);a{color:red}', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'div{padding:0}a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of a resource without protocol with rebase': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/no-protocol.css')
.reply(200, 'a{background:url(image.png)}');
new CleanCSS().minify('@import url(//127.0.0.1/no-protocol.css);', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'a{background:url(//127.0.0.1/image.png)}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of a resource without protocol with rebase to another domain': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.get('/no-protocol.css')
.reply(200, 'a{background:url(//127.0.0.2/image.png)}');
new CleanCSS().minify('@import url(http://127.0.0.1/no-protocol.css);', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'a{background:url(//127.0.0.2/image.png)}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of a resource available via POST only': {
- topic: function() {
+ topic: function () {
this.reqMocks = nock('http://127.0.0.1')
.post('/computed.css')
.reply(200, 'div{padding:0}');
}
}).minify('@import url(http://127.0.0.1/computed.css);a{color:red}', this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'div{padding:0}a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of a remote resource mixed with local ones': {
- topic: function() {
+ topic: function () {
var source = '@import url(http://127.0.0.1/remote.css);@import url(test/fixtures/partials/one.css);';
this.reqMocks = nock('http://127.0.0.1')
.get('/remote.css')
new CleanCSS().minify(source, this.callback);
},
- 'should not raise errors': function(errors, minified) {
+ 'should not raise errors': function (errors, minified) {
assert.isNull(errors);
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, 'div{padding:0}.one{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of a remote resource mixed with local ones but no callback': {
- topic: function() {
+ topic: function () {
var source = '@import url(test/fixtures/partials/one.css);@import url(http://127.0.0.1/remote.css);';
this.reqMocks = nock('http://127.0.0.1')
.get('/remote.css')
'should process @import': function (error, minified) {
assert.equal(minified.styles, '.one{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isFalse(this.reqMocks.isDone());
nock.cleanAll();
}
},
'of a remote file that imports relative stylesheets': {
- topic: function() {
+ topic: function () {
var source = '@import url(http://127.0.0.1/test/folder/remote.css);';
this.reqMocks = nock('http://127.0.0.1')
.get('/test/folder/remote.css')
'should process @import': function (error, minified) {
assert.equal(minified.styles, 'div{padding:0}a{color:red}');
},
- teardown: function() {
+ teardown: function () {
assert.isTrue(this.reqMocks.isDone());
nock.cleanAll();
}
}
}).addBatch({
'of a timed out response': {
- topic: function() {
+ topic: function () {
nock.enableNetConnect();
var self = this;
var timeout = 100;
- this.server = http.createServer(function(req, res) {
- setTimeout(function() {}, timeout * 2);
+ this.server = http.createServer(function (req, res) {
+ setTimeout(function () {}, timeout * 2);
});
- this.server.listen(port, function() {
+ this.server.listen(port, function () {
new CleanCSS({
inliner: {
timeout: timeout
});
enableDestroy(self.server);
},
- 'should raise errors': function(errors, minified) {
+ 'should raise errors': function (errors, minified) {
assert.lengthOf(errors, 1);
assert.equal(errors[0], 'Broken @import declaration of "http://localhost:' + port + '/timeout.css" - timeout');
},
- 'should process @import': function(errors, minified) {
+ 'should process @import': function (errors, minified) {
assert.equal(minified.styles, '@import url(http://localhost:' + port + '/timeout.css);a{color:red}');
},
- teardown: function() {
+ teardown: function () {
this.server.destroy();
nock.disableNetConnect();
}
tokens[0][2].map(function (property) {
return typeof property == 'string' ?
property :
- property.map(function(t) { return t[0]; });
+ property.map(function (t) { return t[0]; });
}) :
null;
'topic': function () {
return new CleanCSS({ sourceMap: true }).minify('/*! a */div[data-id=" abc "] { color:red; }');
},
- 'has 3 mappings': function(minified) {
+ 'has 3 mappings': function (minified) {
assert.lengthOf(minified.sourceMap._mappings._array, 3);
},
'has selector mapping': function (minified) {
'topic': function () {
return new CleanCSS({ sourceMap: true }).minify('@media screen {\n@font-face \n{ \nfont-family: test; } }');
},
- 'has 4 mappings': function(minified) {
+ 'has 4 mappings': function (minified) {
assert.lengthOf(minified.sourceMap._mappings._array, 4);
},
'has `@media` mapping': function (minified) {
'topic': function () {
return new CleanCSS({ sourceMap: true, keepBreaks: true }).minify('@media screen { a{color:red} p {color:blue} }div{color:pink}');
},
- 'has 10 mappings': function(minified) {
+ 'has 10 mappings': function (minified) {
assert.lengthOf(minified.sourceMap._mappings._array, 10);
},
'has `@media` mapping': function (minified) {
'topic': function () {
return new CleanCSS({ sourceMap: true }).minify('@-webkit-keyframes frames {\n 0% {\n border: 1px;\n }\n 100% {\n border: 3px;\n }\n}');
},
- 'has 7 mappings': function(minified) {
+ 'has 7 mappings': function (minified) {
assert.lengthOf(minified.sourceMap._mappings._array, 7);
},
'has `@keframes` mapping': function (minified) {
'topic': function () {
return new CleanCSS({ sourceMap: true }).minify('/* COMMENT 1 */\n/* COMMENT 2 */\ndiv{color:red}');
},
- 'has 3 mappings': function(minified) {
+ 'has 3 mappings': function (minified) {
assert.lengthOf(minified.sourceMap._mappings._array, 3);
},
'has `div`_ mapping': function (minified) {
'has mapping': function (errors, minified) {
assert.isDefined(minified.sourceMap);
},
- 'raises an error': function(errors, _) {
+ 'raises an error': function (errors, _) {
assert.lengthOf(errors, 1);
assert.equal(errors[0], 'Broken source map at "http://127.0.0.1/remote.css.map" - 404');
},
}
},
'timed out response for external source map': {
- topic: function() {
+ topic: function () {
nock.enableNetConnect();
var self = this;
var timeout = 100;
- this.server = http.createServer(function(req, res) {
+ this.server = http.createServer(function (req, res) {
switch (req.url) {
case '/remote.css':
res.writeHead(200);
res.end();
break;
case '/remote.css.map':
- setTimeout(function() {}, timeout * 2);
+ setTimeout(function () {}, timeout * 2);
}
});
- this.server.listen(port, '127.0.0.1', function() {
+ this.server.listen(port, '127.0.0.1', function () {
new CleanCSS({ sourceMap: true, inliner: { timeout: timeout } })
.minify('@import url(http://127.0.0.1:' + port + '/remote.css);', self.callback);
});
'has mapping': function (errors, minified) {
assert.isDefined(minified.sourceMap);
},
- 'raises an error': function(errors, _) {
+ 'raises an error': function (errors, _) {
assert.lengthOf(errors, 1);
assert.include(errors[0], 'Broken source map at "http://127.0.0.1:' + port + '/remote.css.map"');
},
'a{width:expression(this.parentNode.innerText == }'
],
'function call & advanced': [
- 'a{zoom:expression(function(el){el.style.zoom="1"}(this))}',
+ 'a{zoom:expression(function (el){el.style.zoom="1"}(this))}',
'a{zoom:__ESCAPED_EXPRESSION_CLEAN_CSS0__}',
- 'a{zoom:expression(function(el){el.style.zoom="1"}(this))}'
+ 'a{zoom:expression(function (el){el.style.zoom="1"}(this))}'
],
'with more properties': [
- 'a{color:red;zoom:expression(function(el){el.style.zoom="1"}(this));display:block}',
+ 'a{color:red;zoom:expression(function (el){el.style.zoom="1"}(this));display:block}',
'a{color:red;zoom:__ESCAPED_EXPRESSION_CLEAN_CSS0__;display:block}',
- 'a{color:red;zoom:expression(function(el){el.style.zoom="1"}(this));display:block}'
+ 'a{color:red;zoom:expression(function (el){el.style.zoom="1"}(this));display:block}'
]
})
)
'topic': function () {
return new Compatibility({}).toOptions();
},
- 'gets default options': function(options) {
+ 'gets default options': function (options) {
assert.isTrue(options.colors.opacity);
assert.isTrue(options.properties.colors);
assert.isFalse(options.properties.backgroundClipMerging);
'topic': function () {
return new Compatibility().toOptions();
},
- 'gets default options': function(options) {
+ 'gets default options': function (options) {
assert.deepEqual(options, new Compatibility({}).toOptions());
}
},
'topic': function () {
return new Compatibility({ units: { rem: false, vmax: false }, properties: { prefix: true } }).toOptions();
},
- 'gets merged options': function(options) {
+ 'gets merged options': function (options) {
assert.isTrue(options.colors.opacity);
assert.isFalse(options.properties.backgroundClipMerging);
assert.isFalse(options.properties.backgroundOriginMerging);
'topic': function () {
return new Compatibility('ie8').toOptions();
},
- 'gets template options': function(options) {
+ 'gets template options': function (options) {
assert.isFalse(options.colors.opacity);
assert.isFalse(options.properties.backgroundClipMerging);
assert.isFalse(options.properties.backgroundOriginMerging);
'topic': function () {
return new Compatibility('ie7').toOptions();
},
- 'gets template options': function(options) {
+ 'gets template options': function (options) {
assert.isFalse(options.colors.opacity);
assert.isFalse(options.properties.backgroundClipMerging);
assert.isFalse(options.properties.backgroundOriginMerging);
'topic': function () {
return new Compatibility('').toOptions();
},
- 'gets default options': function(options) {
+ 'gets default options': function (options) {
assert.deepEqual(options, new Compatibility({}).toOptions());
}
}
'topic': function () {
return new Compatibility('ie8,-properties.iePrefixHack,+colors.opacity').toOptions();
},
- 'gets calculated options': function(options) {
+ 'gets calculated options': function (options) {
assert.isTrue(options.colors.opacity);
assert.isFalse(options.properties.backgroundClipMerging);
assert.isFalse(options.properties.backgroundOriginMerging);
'topic': function () {
return new Compatibility('+properties.iePrefixHack').toOptions();
},
- 'gets calculated options': function(options) {
+ 'gets calculated options': function (options) {
assert.isTrue(options.colors.opacity);
assert.isTrue(options.properties.colors);
assert.isFalse(options.properties.backgroundClipMerging);
'topic': function () {
return new Compatibility('+properties.iePrefixHack,-units.rem').toOptions();
},
- 'gets calculated options': function(options) {
+ 'gets calculated options': function (options) {
assert.isTrue(options.colors.opacity);
assert.isTrue(options.properties.colors);
assert.isFalse(options.properties.backgroundClipMerging);